|
6 | 6 | "crypto/sha256"
|
7 | 7 | "encoding/hex"
|
8 | 8 | "fmt"
|
| 9 | + "io" |
9 | 10 | "net"
|
10 | 11 | "strconv"
|
11 | 12 | "time"
|
@@ -1295,6 +1296,31 @@ func (b *BurnLeaf) UniverseLeafNode() (*mssmt.LeafNode, error) {
|
1295 | 1296 | return mssmt.NewLeafNode(rawProofBytes, b.BurnProof.Asset.Amount), nil
|
1296 | 1297 | }
|
1297 | 1298 |
|
| 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 | + |
1298 | 1324 | // AuthenticatedBurnLeaf is a type that represents a burn leaf within the
|
1299 | 1325 | // Universe tree. This includes the MS-SMT inclusion proofs.
|
1300 | 1326 | type AuthenticatedBurnLeaf struct {
|
@@ -1360,3 +1386,9 @@ type BurnTree interface {
|
1360 | 1386 | // ListBurns attempts to list all burn leaves for the given asset.
|
1361 | 1387 | ListBurns(context.Context, asset.Specifier) ListBurnsResp
|
1362 | 1388 | }
|
| 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