Skip to content

Commit

Permalink
CBOR encode Addr Pairs for keys (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek authored Jan 6, 2022
1 parent d314098 commit 057cdfb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 5 deletions.
62 changes: 62 additions & 0 deletions abi/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions abi/key.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package abi

import (
"bytes"
"encoding/binary"
"errors"

Expand All @@ -22,18 +23,20 @@ func (k AddrKey) Key() string {

// Adapts an address tuple as a mapping key.
type AddrPairKey struct {
first address.Address
second address.Address
First address.Address
Second address.Address
}

func (k *AddrPairKey) Key() string {
return string(address.Address(k.first).Bytes()) + string(address.Address(k.second).Bytes())
buf := new(bytes.Buffer)
_ = k.MarshalCBOR(buf)
return buf.String()
}

func NewAddrPairKey(first address.Address, second address.Address) *AddrPairKey{
return &AddrPairKey{
first: first,
second: second,
First: first,
Second: second,
}
}

Expand Down
1 change: 1 addition & 0 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func main() {
if err := gen.WriteTupleEncodersToFile("./abi/cbor_gen.go", "abi",
abi.PieceInfo{},
abi.SectorID{},
abi.AddrPairKey{},
); err != nil {
panic(err)
}
Expand Down

0 comments on commit 057cdfb

Please sign in to comment.