Continue Pigeon::Parser. ::Message.ingest() will be required though. Everything is stubbed out, just need to get tests to pass.

This commit is contained in:
Netscape Navigator 2020-03-24 08:12:35 -05:00
parent db33acdf36
commit 8d2a721d84
3 changed files with 29 additions and 9 deletions

View File

@ -4,6 +4,7 @@ module Pigeon
class Message
attr_reader :author, :kind, :body, :signature, :depth, :prev
# Author a new message.
def self.publish(draft, author: LocalIdentity.current)
msg = self.new(author: LocalIdentity.current,
kind: draft.kind,
@ -15,6 +16,17 @@ module Pigeon
msg
end
# Store a message that someone (not the LocalIdentity)
# has authored.
def self.ingest(author:, body:, depth:, kind:, prev:, signature:)
message = new(author: author,
kind: kind,
body: body,
signature: signature)
message.verify!
message.save
end
def render
template.render.chomp
end
@ -24,11 +36,17 @@ module Pigeon
"#{MESSAGE_SIGIL}#{sha256}#{BLOB_FOOTER}"
end
def verify!
verify_depth
verify_prev
verify_signature
end
private
def template
@template ||= MessageSerializer.new(self)
end
def verify_depth; raise "WIP"; end
def verify_prev; raise "WIP"; end
def verify_signature; raise "WIP"; end
def initialize(author:, kind:, body:, signature: nil)
raise MISSING_BODY if body.empty?
@ -44,6 +62,10 @@ module Pigeon
store.save_message(self)
end
def template
@template ||= MessageSerializer.new(self)
end
def calculate_signature
@author.sign(template.render_without_signature)
end

View File

@ -30,12 +30,9 @@ module Pigeon
private
def finish_this_message!
# Step 1: Create a message
# Step 2: Verify message
# Step 3: Push current scratchpad onto `results` array
# Step 4: Reset @scratchpad to empty hash.
@scratchpad.freeze
@results.push(Message.ingest(**@scratchpad))
@scratchpad = {}
raise "See steps above."
end
def set(key, value, hash = @scratchpad)

View File

@ -12,9 +12,10 @@ module Pigeon
end
def get_message_by_depth(author, depth)
raise "Expected string, got #{author.class}" unless author.is_a?(String) # Delete later
store.transaction do
# Map<[author(str), depth(int)], Signature>
store[DEPTH_INDEX_NS][[author.public_key, depth]]
store[DEPTH_INDEX_NS][[author, depth]]
end
end