Skip to content

Commit bebf17f

Browse files
ffranrdarioAnongba
authored andcommitted
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 2ff3cdf commit bebf17f

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
@@ -4350,6 +4350,25 @@ func marshalSupplyLeaves(
43504350
return rpcIssuanceLeaves, rpcBurnLeaves, rpcIgnoreLeaves, nil
43514351
}
43524352

4353+
// marshalSupplyLeafBlockHeaders converts a map of block heights to block
4354+
// headers into a map of block heights to RPC SupplyLeafBlockHeader objects.
4355+
//
4356+
// nolint: lll
4357+
func marshalSupplyLeafBlockHeaders(
4358+
heightHeaderMap map[uint32]wire.BlockHeader) map[uint32]*unirpc.SupplyLeafBlockHeader {
4359+
4360+
rpcHeightHeader := make(map[uint32]*unirpc.SupplyLeafBlockHeader)
4361+
4362+
for height, header := range heightHeaderMap {
4363+
rpcHeightHeader[height] = &unirpc.SupplyLeafBlockHeader{
4364+
Timestamp: header.Timestamp.Unix(),
4365+
Hash: fn.ByteSlice(header.BlockHash()),
4366+
}
4367+
}
4368+
4369+
return rpcHeightHeader
4370+
}
4371+
43534372
// FetchSupplyLeaves fetches the supply leaves for a specific asset group
43544373
// within a specified block height range. The leaves include issuance, burn,
43554374
// and ignore leaves, which represent the supply changes for the asset group.
@@ -4444,13 +4463,25 @@ func (r *rpcServer) FetchSupplyLeaves(ctx context.Context,
44444463
}
44454464
}
44464465

4466+
// Extract block headers for all block heights that have supply leaves.
4467+
// And then marshal them into the RPC format.
4468+
heightHeaderMap, err := supplycommit.ExtractSupplyLeavesBlockHeaders(
4469+
ctx, r.cfg.ChainBridge, resp,
4470+
)
4471+
if err != nil {
4472+
return nil, fmt.Errorf("failed to extract block headers for "+
4473+
"supply leaves: %w", err)
4474+
}
4475+
rpcHeightHeaderMap := marshalSupplyLeafBlockHeaders(heightHeaderMap)
4476+
44474477
return &unirpc.FetchSupplyLeavesResponse{
44484478
IssuanceLeaves: issuanceLeaves,
44494479
BurnLeaves: burnLeaves,
44504480
IgnoreLeaves: ignoreLeaves,
44514481
IssuanceLeafInclusionProofs: issuanceInclusionProofs,
44524482
BurnLeafInclusionProofs: burnInclusionProofs,
44534483
IgnoreLeafInclusionProofs: ignoreInclusionProofs,
4484+
BlockHeaders: rpcHeightHeaderMap,
44544485
}, nil
44554486
}
44564487

0 commit comments

Comments
 (0)