@@ -10,6 +10,7 @@ import (
10
10
"github.com/ethereum/go-ethereum/common"
11
11
"github.com/ethereum/go-ethereum/common/hexutil"
12
12
ethtypes "github.com/ethereum/go-ethereum/core/types"
13
+ "github.com/harmony-one/harmony/block"
13
14
"github.com/harmony-one/harmony/core/types"
14
15
"github.com/harmony-one/harmony/crypto/bls"
15
16
internal_common "github.com/harmony-one/harmony/internal/common"
@@ -46,6 +47,34 @@ type BlockWithTxHash struct {
46
47
Signers []string `json:"signers,omitempty"`
47
48
}
48
49
50
+ // BlockHeader represents a block header that will serialize to the RPC representation of a block header
51
+ type BlockHeader struct {
52
+ ParentHash common.Hash `json:"parentHash"`
53
+ Miner string `json:"miner"`
54
+ StateRoot common.Hash `json:"stateRoot"`
55
+ TransactionsRoot common.Hash `json:"transactionsRoot"`
56
+ ReceiptsRoot common.Hash `json:"receiptsRoot"`
57
+ OutgoingReceiptsRoot common.Hash `json:"outgoingReceiptsRoot"`
58
+ IncomingReceiptsRoot common.Hash `json:"incomingReceiptsRoot"`
59
+ LogsBloom ethtypes.Bloom `json:"logsBloom"`
60
+ Number * big.Int `json:"number"`
61
+ GasLimit uint64 `json:"gasLimit"`
62
+ GasUsed uint64 `json:"gasUsed"`
63
+ Timestamp * big.Int `json:"timestamp"`
64
+ ExtraData hexutil.Bytes `json:"extraData"`
65
+ MixHash common.Hash `json:"mixHash"`
66
+ ViewID * big.Int `json:"viewID"`
67
+ Epoch * big.Int `json:"epoch"`
68
+ ShardID uint32 `json:"shardID"`
69
+ LastCommitSignature hexutil.Bytes `json:"lastCommitSignature"`
70
+ LastCommitBitmap hexutil.Bytes `json:"lastCommitBitmap"`
71
+ Vrf hexutil.Bytes `json:"vrf"`
72
+ Vdf hexutil.Bytes `json:"vdf"`
73
+ ShardState hexutil.Bytes `json:"shardState"`
74
+ CrossLink hexutil.Bytes `json:"crossLink"`
75
+ Slashes hexutil.Bytes `json:"slashes"`
76
+ }
77
+
49
78
// BlockWithFullTx represents a block that will serialize to the RPC representation of a block
50
79
// having FULL transactions in the Transaction & Staking transaction fields.
51
80
type BlockWithFullTx struct {
@@ -679,6 +708,42 @@ func blockWithFullTxFromBlock(b *types.Block) (*BlockWithFullTx, error) {
679
708
return blk , nil
680
709
}
681
710
711
+ func NewBlockHeader (
712
+ head * block.Header ,
713
+ ) (* BlockHeader , error ) {
714
+ lastSig := head .LastCommitSignature ()
715
+ blk := & BlockHeader {
716
+ ParentHash : head .ParentHash (),
717
+ Miner : head .Coinbase ().Hex (),
718
+ StateRoot : head .Root (),
719
+ TransactionsRoot : head .TxHash (),
720
+ ReceiptsRoot : head .ReceiptHash (),
721
+ OutgoingReceiptsRoot : head .OutgoingReceiptHash (),
722
+ IncomingReceiptsRoot : head .IncomingReceiptHash (),
723
+ LogsBloom : head .Bloom (),
724
+
725
+ Number : head .Number (),
726
+ GasLimit : head .GasLimit (),
727
+ GasUsed : head .GasUsed (),
728
+ Timestamp : head .Time (),
729
+ ExtraData : hexutil .Bytes (head .Extra ()),
730
+ MixHash : head .MixDigest (),
731
+
732
+ ViewID : head .ViewID (),
733
+ Epoch : head .Epoch (),
734
+ ShardID : head .ShardID (),
735
+
736
+ LastCommitSignature : hexutil .Bytes (lastSig [:]),
737
+ LastCommitBitmap : head .LastCommitBitmap (),
738
+ Vrf : head .Vrf (),
739
+ Vdf : head .Vdf (),
740
+ ShardState : head .ShardState (),
741
+ CrossLink : head .CrossLinks (),
742
+ Slashes : head .Slashes (),
743
+ }
744
+ return blk , nil
745
+ }
746
+
682
747
// NewTransactionFromHash returns a transaction that will serialize to the RPC representation.
683
748
func NewTransactionFromHash (b * types.Block , hash common.Hash ) (* Transaction , error ) {
684
749
for idx , tx := range b .Transactions () {
0 commit comments