Skip to content

Commit

Permalink
add transaction and event commitments
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Feb 20, 2024
1 parent d0d4ce0 commit 9b6a014
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 43 deletions.
34 changes: 18 additions & 16 deletions adapters/sn2core/sn2core.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,24 @@ func AdaptBlock(response *starknet.Block, sig *starknet.Signature) (*core.Block,

return &core.Block{
Header: &core.Header{
Hash: response.Hash,
ParentHash: response.ParentHash,
Number: response.Number,
GlobalStateRoot: response.StateRoot,
Timestamp: response.Timestamp,
ProtocolVersion: response.Version,
SequencerAddress: response.SequencerAddress,
TransactionCount: uint64(len(response.Transactions)),
EventCount: eventCount,
EventsBloom: core.EventsBloom(receipts),
GasPrice: response.GasPriceETH(),
GasPriceSTRK: response.GasPriceSTRK,
L1DAMode: l1DAMode,
L1DataGasPrice: L1DataGasPrice,
L1GasPrice: L1GasPrice,
Signatures: sigs,
Hash: response.Hash,
ParentHash: response.ParentHash,

Check warning on line 69 in adapters/sn2core/sn2core.go

View check run for this annotation

Codecov / codecov/patch

adapters/sn2core/sn2core.go#L60-L69

Added lines #L60 - L69 were not covered by tests
Number: response.Number,
GlobalStateRoot: response.StateRoot,
TransactionCommitment: response.TransactionCommitment,
EventCommitment: response.EventCommitment,
Timestamp: response.Timestamp,
ProtocolVersion: response.Version,
SequencerAddress: response.SequencerAddress,
TransactionCount: uint64(len(response.Transactions)),
EventCount: eventCount,
EventsBloom: core.EventsBloom(receipts),
GasPrice: response.GasPriceETH(),
GasPriceSTRK: response.GasPriceSTRK,
L1DAMode: l1DAMode,
L1DataGasPrice: L1DataGasPrice,
L1GasPrice: L1GasPrice,
Signatures: sigs,
},
Transactions: txns,
Receipts: receipts,
Expand Down
34 changes: 20 additions & 14 deletions adapters/sn2core/sn2core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ import (

func TestAdaptBlock(t *testing.T) {
tests := []struct {
number uint64
protocolVersion string
network utils.Network
sig *starknet.Signature
gasPriceWEI *felt.Felt
gasPriceSTRK *felt.Felt
l1GasPriceWEI *felt.Felt
l1GasPriceFRI *felt.Felt
l1DAGasPriceWEI *felt.Felt
l1DAGasPriceFRI *felt.Felt
number uint64
protocolVersion string
network utils.Network
sig *starknet.Signature
gasPriceWEI *felt.Felt
gasPriceSTRK *felt.Felt
l1GasPriceWEI *felt.Felt
l1GasPriceFRI *felt.Felt
l1DAGasPriceWEI *felt.Felt
l1DAGasPriceFRI *felt.Felt
transactionCommitment *felt.Felt
eventCommitment *felt.Felt
}{
{
number: 147,
Expand Down Expand Up @@ -71,10 +73,12 @@ func TestAdaptBlock(t *testing.T) {
utils.HexToFelt(t, "0x343e605de3957e664746ba8ef82f2b0f9d53cda3d75dcb078290b8edd010165"),
},
},
l1GasPriceWEI: utils.HexToFelt(t, "0x3b9aca08"),
l1GasPriceFRI: utils.HexToFelt(t, "0x2540be400"),
l1DAGasPriceWEI: utils.HexToFelt(t, "0x5265a14ef"),
l1DAGasPriceFRI: utils.HexToFelt(t, "0x3c0c00c87"),
l1GasPriceWEI: utils.HexToFelt(t, "0x3b9aca08"),
l1GasPriceFRI: utils.HexToFelt(t, "0x2540be400"),
l1DAGasPriceWEI: utils.HexToFelt(t, "0x5265a14ef"),
l1DAGasPriceFRI: utils.HexToFelt(t, "0x3c0c00c87"),
transactionCommitment: utils.HexToFelt(t, "0x13367121d0b7e34a9b10c8a5a1c269811cd9afc3ce680c88888f1a22d2f017a"),
eventCommitment: utils.HexToFelt(t, "0x1090dd2ab2aa22bd5fc5a59d3b1394d54461bb2a80156c4b2c2622d2c474ca2"),
},
}

Expand All @@ -99,6 +103,8 @@ func TestAdaptBlock(t *testing.T) {
assert.True(t, block.ParentHash.Equal(response.ParentHash))
assert.Equal(t, response.Number, block.Number)
assert.True(t, block.GlobalStateRoot.Equal(response.StateRoot))
assert.Equal(t, test.eventCommitment, block.EventCommitment)
assert.Equal(t, test.transactionCommitment, block.TransactionCommitment)
assert.Equal(t, response.Timestamp, block.Timestamp)
assert.Equal(t, len(response.Transactions), len(block.Transactions))
assert.Equal(t, uint64(len(response.Transactions)), block.TransactionCount)
Expand Down
5 changes: 5 additions & 0 deletions core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ type Header struct {
Number uint64
// The state commitment after this block
GlobalStateRoot *felt.Felt

TransactionCommitment *felt.Felt

EventCommitment *felt.Felt

// The Starknet address of the sequencer who created this block
SequencerAddress *felt.Felt
// The amount Transactions and Receipts stored in this block
Expand Down
28 changes: 15 additions & 13 deletions starknet/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import (

// Block object returned by the feeder in JSON format for "get_block" endpoint
type Block struct {
Hash *felt.Felt `json:"block_hash"`
ParentHash *felt.Felt `json:"parent_block_hash"`
Number uint64 `json:"block_number"`
StateRoot *felt.Felt `json:"state_root"`
Status string `json:"status"`
Transactions []*Transaction `json:"transactions"`
Timestamp uint64 `json:"timestamp"`
Version string `json:"starknet_version"`
Receipts []*TransactionReceipt `json:"transaction_receipts"`
SequencerAddress *felt.Felt `json:"sequencer_address"`
GasPriceSTRK *felt.Felt `json:"strk_l1_gas_price"`
L1DAMode L1DAMode `json:"l1_da_mode"`
L1DataGasPrice *GasPrice `json:"l1_data_gas_price"`
Hash *felt.Felt `json:"block_hash"`
ParentHash *felt.Felt `json:"parent_block_hash"`
Number uint64 `json:"block_number"`
StateRoot *felt.Felt `json:"state_root"`
TransactionCommitment *felt.Felt `json:"transaction_commitment"`
EventCommitment *felt.Felt `json:"event_commitment"`
Status string `json:"status"`
Transactions []*Transaction `json:"transactions"`
Timestamp uint64 `json:"timestamp"`
Version string `json:"starknet_version"`
Receipts []*TransactionReceipt `json:"transaction_receipts"`
SequencerAddress *felt.Felt `json:"sequencer_address"`
GasPriceSTRK *felt.Felt `json:"strk_l1_gas_price"`
L1DAMode L1DAMode `json:"l1_da_mode"`
L1DataGasPrice *GasPrice `json:"l1_data_gas_price"`

// TODO this field replaces `eth_l1_gas_price` and `strk_l1_gas_price` in v0.13.1
L1GasPrice *GasPrice `json:"l1_gas_price"`
Expand Down

0 comments on commit 9b6a014

Please sign in to comment.