Skip to content

Commit 787fed1

Browse files
committed
universerpc: extend FetchSupplyLeavesResponse with block header map
Extend the FetchSupplyLeavesResponse RPC message with a new field: a map from block height to SupplyLeafBlockHeader. The SupplyLeafBlockHeader message includes the block header timestamp (in seconds since the Unix epoch) and the 32-byte block header hash. This map covers all block heights referenced in the supply leaves.
1 parent 9537ee5 commit 787fed1

File tree

4 files changed

+517
-352
lines changed

4 files changed

+517
-352
lines changed

rpcserver.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4339,6 +4339,25 @@ func marshalSupplyLeaves(
43394339
return rpcIssuanceLeaves, rpcBurnLeaves, rpcIgnoreLeaves, nil
43404340
}
43414341

4342+
// marshalSupplyLeafBlockHeaders converts a map of block heights to block
4343+
// headers into a map of block heights to RPC SupplyLeafBlockHeader objects.
4344+
//
4345+
// nolint: lll
4346+
func marshalSupplyLeafBlockHeaders(
4347+
heightHeaderMap map[uint32]wire.BlockHeader) map[uint32]*unirpc.SupplyLeafBlockHeader {
4348+
4349+
rpcHeightHeader := make(map[uint32]*unirpc.SupplyLeafBlockHeader)
4350+
4351+
for height, header := range heightHeaderMap {
4352+
rpcHeightHeader[height] = &unirpc.SupplyLeafBlockHeader{
4353+
Timestamp: header.Timestamp.Unix(),
4354+
Hash: fn.ByteSlice(header.BlockHash()),
4355+
}
4356+
}
4357+
4358+
return rpcHeightHeader
4359+
}
4360+
43424361
// FetchSupplyLeaves fetches the supply leaves for a specific asset group
43434362
// within a specified block height range. The leaves include issuance, burn,
43444363
// and ignore leaves, which represent the supply changes for the asset group.
@@ -4433,13 +4452,25 @@ func (r *rpcServer) FetchSupplyLeaves(ctx context.Context,
44334452
}
44344453
}
44354454

4455+
// Extract block headers for all block heights that have supply leaves.
4456+
// And then marshal them into the RPC format.
4457+
heightHeaderMap, err := supplycommit.ExtractSupplyLeavesBlockHeaders(
4458+
ctx, r.cfg.ChainBridge, resp,
4459+
)
4460+
if err != nil {
4461+
return nil, fmt.Errorf("failed to extract block headers for "+
4462+
"supply leaves: %w", err)
4463+
}
4464+
rpcHeightHeaderMap := marshalSupplyLeafBlockHeaders(heightHeaderMap)
4465+
44364466
return &unirpc.FetchSupplyLeavesResponse{
44374467
IssuanceLeaves: issuanceLeaves,
44384468
BurnLeaves: burnLeaves,
44394469
IgnoreLeaves: ignoreLeaves,
44404470
IssuanceLeafInclusionProofs: issuanceInclusionProofs,
44414471
BurnLeafInclusionProofs: burnInclusionProofs,
44424472
IgnoreLeafInclusionProofs: ignoreInclusionProofs,
4473+
BlockHeaders: rpcHeightHeaderMap,
44434474
}, nil
44444475
}
44454476

0 commit comments

Comments
 (0)