Skip to content

Commit 6f9a19b

Browse files
committed
universe: add Encode+Decode methods for BurnLeaf
1 parent 4bb4d5a commit 6f9a19b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

universe/interface.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/sha256"
77
"encoding/hex"
88
"fmt"
9+
"io"
910
"net"
1011
"strconv"
1112
"time"
@@ -1295,6 +1296,31 @@ func (b *BurnLeaf) UniverseLeafNode() (*mssmt.LeafNode, error) {
12951296
return mssmt.NewLeafNode(rawProofBytes, b.BurnProof.Asset.Amount), nil
12961297
}
12971298

1299+
// Encode encodes the burn leaf into the target writer.
1300+
func (b *BurnLeaf) Encode(w io.Writer) error {
1301+
return b.BurnProof.Encode(w)
1302+
}
1303+
1304+
// Decode decodes the burn leaf from the target reader.
1305+
func (b *BurnLeaf) Decode(r io.Reader) error {
1306+
burnProof := new(proof.Proof)
1307+
if err := burnProof.Decode(r); err != nil {
1308+
return fmt.Errorf("unable to decode burn proof: %w", err)
1309+
}
1310+
1311+
b.BurnProof = burnProof
1312+
1313+
b.UniverseKey = AssetLeafKey{
1314+
BaseLeafKey: BaseLeafKey{
1315+
OutPoint: b.BurnProof.OutPoint(),
1316+
ScriptKey: &b.BurnProof.Asset.ScriptKey,
1317+
},
1318+
AssetID: b.BurnProof.Asset.ID(),
1319+
}
1320+
1321+
return nil
1322+
}
1323+
12981324
// AuthenticatedBurnLeaf is a type that represents a burn leaf within the
12991325
// Universe tree. This includes the MS-SMT inclusion proofs.
13001326
type AuthenticatedBurnLeaf struct {
@@ -1360,3 +1386,9 @@ type BurnTree interface {
13601386
// ListBurns attempts to list all burn leaves for the given asset.
13611387
ListBurns(context.Context, asset.Specifier) ListBurnsResp
13621388
}
1389+
1390+
// UniverseLeaf is an interface that allows a caller to query for the leaf node
1391+
// of a given Universe tree.
1392+
type UniverseLeaf interface {
1393+
UniverseLeafNode() (*mssmt.LeafNode, error)
1394+
}

0 commit comments

Comments
 (0)