Skip to content

Commit

Permalink
Merge pull request #264 from coburn24/rpcv03
Browse files Browse the repository at this point in the history
Update StateUpdateOutput & Add PendingStateUpdate
  • Loading branch information
rianhughes committed Aug 18, 2023
2 parents 87254fb + 987ead0 commit e409e6e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 40 deletions.
44 changes: 24 additions & 20 deletions rpc/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,17 +569,19 @@ func TestStateUpdate(t *testing.T) {
ExpectedStateUpdateOutput: StateUpdateOutput{
BlockHash: utils.TestHexToFelt(t, "0x4f1cee281edb6cb31b9ba5a8530694b5527cf05c5ac6502decf3acb1d0cec4"),
NewRoot: utils.TestHexToFelt(t, "0x70677cda9269d47da3ff63bc87cf1c87d0ce167b05da295dc7fc68242b250b"),
OldRoot: utils.TestHexToFelt(t, "0x19aa982a75263d4c4de4cc4c5d75c3dec32e00b95bef7bbb4d17762a0b138af"),
StateDiff: StateDiff{
StorageDiffs: []ContractStorageDiffItem{{
Address: utils.TestHexToFelt(t, "0xe5cc6f2b6d34979184b88334eb64173fe4300cab46ecd3229633fcc45c83d4"),
StorageEntries: []StorageEntry{
{
Key: utils.TestHexToFelt(t, "0x1813aac5f5e7799684c6dc33e51f44d3627fd748c800724a184ed5be09b713e"),
Value: utils.TestHexToFelt(t, "0x630b4197"),
PendingStateUpdate: PendingStateUpdate{
OldRoot: utils.TestHexToFelt(t, "0x19aa982a75263d4c4de4cc4c5d75c3dec32e00b95bef7bbb4d17762a0b138af"),
StateDiff: StateDiff{
StorageDiffs: []ContractStorageDiffItem{{
Address: utils.TestHexToFelt(t, "0xe5cc6f2b6d34979184b88334eb64173fe4300cab46ecd3229633fcc45c83d4"),
StorageEntries: []StorageEntry{
{
Key: utils.TestHexToFelt(t, "0x1813aac5f5e7799684c6dc33e51f44d3627fd748c800724a184ed5be09b713e"),
Value: utils.TestHexToFelt(t, "0x630b4197"),
},
},
},
}},
}},
},
},
},
},
Expand All @@ -590,17 +592,19 @@ func TestStateUpdate(t *testing.T) {
ExpectedStateUpdateOutput: StateUpdateOutput{
BlockHash: utils.TestHexToFelt(t, "0x03b6d94b246815960f38b7dffc53cda192e7d1dcfff61e1bc042fb57e95f8349"),
NewRoot: utils.TestHexToFelt(t, "0x70677cda9269d47da3ff63bc87cf1c87d0ce167b05da295dc7fc68242b250b"),
OldRoot: utils.TestHexToFelt(t, "0x19aa982a75263d4c4de4cc4c5d75c3dec32e00b95bef7bbb4d17762a0b138af"),
StateDiff: StateDiff{
StorageDiffs: []ContractStorageDiffItem{{
Address: utils.TestHexToFelt(t, "0xe5cc6f2b6d34979184b88334eb64173fe4300cab46ecd3229633fcc45c83d4"),
StorageEntries: []StorageEntry{
{
Key: utils.TestHexToFelt(t, "0x1813aac5f5e7799684c6dc33e51f44d3627fd748c800724a184ed5be09b713e"),
Value: utils.TestHexToFelt(t, "0x630b4197"),
PendingStateUpdate: PendingStateUpdate{
OldRoot: utils.TestHexToFelt(t, "0x19aa982a75263d4c4de4cc4c5d75c3dec32e00b95bef7bbb4d17762a0b138af"),
StateDiff: StateDiff{
StorageDiffs: []ContractStorageDiffItem{{
Address: utils.TestHexToFelt(t, "0xe5cc6f2b6d34979184b88334eb64173fe4300cab46ecd3229633fcc45c83d4"),
StorageEntries: []StorageEntry{
{
Key: utils.TestHexToFelt(t, "0x1813aac5f5e7799684c6dc33e51f44d3627fd748c800724a184ed5be09b713e"),
Value: utils.TestHexToFelt(t, "0x630b4197"),
},
},
},
}},
}},
},
},
},
},
Expand Down
37 changes: 23 additions & 14 deletions rpc/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,23 @@ func mock_starknet_getEvents(result interface{}, method string, args ...interfac
return err
}
events := &EventsOutput{
Events: []EmittedEvent{
{BlockHash: deadbeefFelt,

Events: []EventChunk{{
Events: []EmittedEvent{{
Event: Event{
FromAddress: query.Address,
Keys: []*felt.Felt{},
Data: []*felt.Felt{},
},

BlockHash: deadbeefFelt,
BlockNumber: 1,
TransactionHash: deadbeefFelt,
},
},
}},
ContinuationToken: "deadbeef",
}},
}

outputContent, _ := json.Marshal(events)
json.Unmarshal(outputContent, r)
return nil
Expand Down Expand Up @@ -530,17 +537,19 @@ func mock_starknet_getStateUpdate(result interface{}, method string, args ...int
output := StateUpdateOutput{
BlockHash: stateFeltArr[0],
NewRoot: stateFeltArr[1],
OldRoot: stateFeltArr[2],
StateDiff: StateDiff{
StorageDiffs: []ContractStorageDiffItem{{
Address: stateFeltArr[3],
StorageEntries: []StorageEntry{
{
Key: stateFeltArr[4],
Value: stateFeltArr[5],
PendingStateUpdate: PendingStateUpdate{
OldRoot: stateFeltArr[2],
StateDiff: StateDiff{
StorageDiffs: []ContractStorageDiffItem{{
Address: stateFeltArr[3],
StorageEntries: []StorageEntry{
{
Key: stateFeltArr[4],
Value: stateFeltArr[5],
},
},
},
}},
}},
},
},
}
outputContent, _ := json.Marshal(output)
Expand Down
34 changes: 30 additions & 4 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ type ContractStorageDiffItem struct {
StorageEntries []StorageEntry `json:"storage_entries"`
}

// DeclaredClassesItem is an object with class_hash and compiled_class_hash
type DeclaredClassesItem struct {
//The hash of the declared class
ClassHash *felt.Felt `json:"class_hash"`
//The Cairo assembly hash corresponding to the declared class
CompiledClassHash *felt.Felt `json:"compiled_class_hash"`
}

// DeployedContractItem A new contract deployed as part of the new state
type DeployedContractItem struct {
// ContractAddress is the address of the contract
Expand All @@ -38,6 +46,14 @@ type DeployedContractItem struct {
ClassHash *felt.Felt `json:"class_hash"`
}

// contracts whose class was replaced
type ReplacedClassesItem struct {
//The address of the contract whose class was replaced
ContractClass *felt.Felt `json:"contract_address"`
//The new class hash
ClassHash *felt.Felt `json:"class_hash"`
}

// ContractNonce is a the updated nonce per contract address
type ContractNonce struct {
// ContractAddress is the address of the contract
Expand All @@ -49,12 +65,16 @@ type ContractNonce struct {
// StateDiff is the change in state applied in this block, given as a
// mapping of addresses to the new values and/or new contracts.
type StateDiff struct {
// StorageDiffs list storage changes
// list storage changes
StorageDiffs []ContractStorageDiffItem `json:"storage_diffs"`
// Contracts list new contracts added as part of the new state
DeclaredContractHashes []*felt.Felt `json:"declared_contract_hashes"`
// Nonces provides the updated nonces per contract addresses
// a list of Deprecated declared classes
DeprecatedDeclaredClasses []*felt.Felt `json:"deprecated_declared_classes"`
// list of DeclaredClassesItems objects
DeclaredClasses []DeclaredClassesItem `json:"declared_classes"`
// list of new contract deployed as part of the state update
DeployedContracts []DeployedContractItem `json:"deployed_contracts"`
// list of contracts whose class was replaced
ReplacedClasses []ReplacedClassesItem `json:"replaced_classes"`
// Nonces provides the updated nonces per contract addresses
Nonces []ContractNonce `json:"nonces"`
}
Expand All @@ -65,6 +85,12 @@ type StateUpdateOutput struct {
BlockHash *felt.Felt `json:"block_hash"`
// NewRoot is the new global state root.
NewRoot *felt.Felt `json:"new_root"`
// Pending
PendingStateUpdate
}

// PENDING_STATE_UPDATE in spec
type PendingStateUpdate struct {
// OldRoot is the previous global state root.
OldRoot *felt.Felt `json:"old_root"`
// AcceptedTime is when the block was accepted on L1.
Expand Down
8 changes: 6 additions & 2 deletions rpc/types_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ type Event struct {
Data []*felt.Felt `json:"data"`
}

type EventChunk struct {
Events []EmittedEvent `json:"events"`
ContinuationToken string `json:"continuation_token"`
}

// EmittedEvent an event emitted as a result of transaction execution
type EmittedEvent struct {
Event
Expand Down Expand Up @@ -36,6 +41,5 @@ type EventsInput struct {
}

type EventsOutput struct {
Events []EmittedEvent `json:"events"`
ContinuationToken *string `json:"continuation_token,omitempty"`
Events []EventChunk `json:"events"`
}

0 comments on commit e409e6e

Please sign in to comment.