From 2d65136987c92963a83138036afb13e003d9aeef Mon Sep 17 00:00:00 2001 From: Artem Date: Mon, 6 Jun 2022 16:31:10 +0300 Subject: [PATCH] Node RPC: add rollup API --- node/context_api.go | 48 +++++++++++++++++++++++++++++++++++ node/context_data.go | 59 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/node/context_api.go b/node/context_api.go index cae96b8..87a480f 100644 --- a/node/context_api.go +++ b/node/context_api.go @@ -36,6 +36,10 @@ type ContextAPI interface { DelegateVotingPower(ctx context.Context, blockID, pkh string) (int, error) ActiveDelegatesWithRolls(ctx context.Context, blockID string) ([]string, error) LiquidityBakingCPMMAddress(ctx context.Context, blockID string) (string, error) + TxRollupState(ctx context.Context, txRollupID string) (TxRollupState, error) + TxRollupCommitment(ctx context.Context, blockID, txRollupID, blockLevel string) (*RollupCommitmentForBlock, error) + TxRollupInbox(ctx context.Context, blockID, txRollupID, blockLevel string) (*TxRollupInbox, error) + TxRollupPendingBondedCommitments(ctx context.Context, blockID, txRollupID, pkh string) (uint64, error) } // Context - @@ -319,3 +323,47 @@ func (api *Context) LiquidityBakingCPMMAddress(ctx context.Context, blockID stri err = req.doWithJSONResponse(ctx, api.client, &result) return result, err } + +// TxRollupState - +func (api *Context) TxRollupState(ctx context.Context, blockID, txRollupID string) (TxRollupState, error) { + req, err := newGetRequest(api.baseURL, fmt.Sprintf("chains/%s/blocks/%s/context/tx_rollup/%s/state", api.chainID, blockID, txRollupID), nil) + if err != nil { + return TxRollupState{}, err + } + var state TxRollupState + err = req.doWithJSONResponse(ctx, api.client, &state) + return state, err +} + +// TxRollupCommitment - +func (api *Context) TxRollupCommitment(ctx context.Context, blockID, txRollupID, blockLevel string) (*RollupCommitmentForBlock, error) { + req, err := newGetRequest(api.baseURL, fmt.Sprintf("chains/%s/blocks/%s/context/tx_rollup/%s/commitment/%s", api.chainID, blockID, txRollupID, blockLevel), nil) + if err != nil { + return nil, err + } + result := new(RollupCommitmentForBlock) + err = req.doWithJSONResponse(ctx, api.client, result) + return result, err +} + +// TxRollupInbox - +func (api *Context) TxRollupInbox(ctx context.Context, blockID, txRollupID, blockLevel string) (*TxRollupInbox, error) { + req, err := newGetRequest(api.baseURL, fmt.Sprintf("chains/%s/blocks/%s/context/tx_rollup/%s/inbox/%s", api.chainID, blockID, txRollupID, blockLevel), nil) + if err != nil { + return nil, err + } + inbox := new(TxRollupInbox) + err = req.doWithJSONResponse(ctx, api.client, inbox) + return inbox, err +} + +// TxRollupPendingBondedCommitments - +func (api *Context) TxRollupPendingBondedCommitments(ctx context.Context, blockID, txRollupID, pkh string) (uint64, error) { + req, err := newGetRequest(api.baseURL, fmt.Sprintf("chains/%s/blocks/%s/context/tx_rollup/%s/pending_bonded_commitments/%s", api.chainID, blockID, txRollupID, pkh), nil) + if err != nil { + return 0, err + } + var response uint64 + err = req.doWithJSONResponse(ctx, api.client, &response) + return response, err +} diff --git a/node/context_data.go b/node/context_data.go index 93bc8d0..2f647b1 100644 --- a/node/context_data.go +++ b/node/context_data.go @@ -112,3 +112,62 @@ const ( InactiveDelegateType DelegateType = "inactive" AllDelegateType DelegateType = "all" ) + +// TxRollupState - +type TxRollupState struct { + LastRemovedCommitmentHashes *LastRemovedCommitmentHashes `json:"last_removed_commitment_hashes,omitempty"` + FinalizedCommitments RollupStateCommitment `json:"finalized_commitments"` + UnfinalizedCommitments RollupStateCommitment `json:"unfinalized_commitments"` + UncommittedInboxes RollupStateCommitment `json:"uncommitted_inboxes"` + CommitmentNewestHash *string `json:"commitment_newest_hash,omitempty"` + TezosHeadLevel *uint64 `json:"tezos_head_level,omitempty"` + BurnPerByte stdJSON.Number `json:"burn_per_byte,omitempty"` + AllocatedStorage stdJSON.Number `json:"allocated_storage"` + OccupiedStorage stdJSON.Number `json:"occupied_storage"` + InboxEma uint64 `json:"inbox_ema"` + CommitmentsWatermark *uint64 `json:"commitments_watermark,omitempty"` +} + +// LastRemovedCommitmentHashes - +type LastRemovedCommitmentHashes struct { + LastMessageHash string `json:"last_message_hash"` + CommitmentHash string `json:"commitment_hash"` +} + +// RollupStateCommitment - +type RollupStateCommitment struct { + Next *uint64 `json:"next,omitempty"` + Newest *uint64 `json:"newest,omitempty"` + Oldest *uint64 `json:"oldest,omitempty"` +} + +// RollupCommitmentForBlock - +type RollupCommitmentForBlock struct { + Commitment RollupCommitment `json:"commitment"` + CommitmentHash string `json:"commitment_hash"` + Committer string `json:"committer"` + SubmittedAt uint64 `json:"submitted_at"` + FinalizedAt uint64 `json:"finalized_at"` +} + +// RollupCommitment - +type RollupCommitment struct { + Level uint64 `json:"level"` + Messages RollupCommitmentMessages `json:"messages"` + Predecessor *string `json:"predecessor,omitempty"` + InboxMerkleRoot string `json:"inbox_merkle_root"` +} + +// RollupCommitmentMessages - +type RollupCommitmentMessages struct { + Count uint64 `json:"count"` + Root string `json:"root"` + LastMessageResultHash string `json:"last_message_result_hash"` +} + +// TxRollupInbox - +type TxRollupInbox struct { + InboxLength uint64 `json:"inbox_length"` + CumulatedSize uint64 `json:"cumulated_size"` + MerkleRoot string `json:"merkle_root"` +}