Skip to content

Commit

Permalink
go mod and new code to chain
Browse files Browse the repository at this point in the history
  • Loading branch information
techlab-lainio committed Jun 12, 2021
1 parent 081d67a commit 9354e22
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ type Block struct {
}

type Chain struct {
blocks []Block // first is leaf and last is the root block, always
blocks []Block
}

type PubKey = []byte
type Key = []byte
type Signature = []byte

func NewRoot(rootPubKey PubKey) Block {
return Block{HashToPrev: nil, InviteePubKey: rootPubKey, InvitersSignature: nil}
func NewChain(rootPubKey PubKey) Chain {
chain = Chain{blocks: make(Chain, 1, 12)}
chain.blocks[0] = Block{
HashToPrev: nil,
InviteePubKey: rootPubKey,
InvitersSignature: nil,
}
}

func (c Chain) AddBlock(invitersKey Key, inviteesPubKey PubKey, position int) {
func (c *Chain) AddBlock(invitersKey Key, inviteesPubKey PubKey, position int) {
assert.D.True(invitersKey.PubKey == c.LeafPubKey())

newBlock := Block{
Expand All @@ -30,11 +35,13 @@ func (c Chain) AddBlock(invitersKey Key, inviteesPubKey PubKey, position int) {
Position: position,
}
h := newBlock.Hash()
newBloc.InvitersSignature = invitersKey.Sign(h)
newBlock.InvitersSignature = invitersKey.Sign(h)

c.blocks = append(c.blocks, newBlock)
}

func (c Chain) LeafPubKey() PubKey {
assert.D.True(len(c.blocks) > 0)

return c.blocks[0].InviteePubKey
return c.blocks[len(c.blocks)-1].InviteePubKey
}

0 comments on commit 9354e22

Please sign in to comment.