Skip to content

Commit 60b2c2b

Browse files
Merge pull request #6 from dipdup-net/GO-14-node-rpc
Node RPC: add rollup API
2 parents 00248ec + 2d65136 commit 60b2c2b

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

node/context_api.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ type ContextAPI interface {
3636
DelegateVotingPower(ctx context.Context, blockID, pkh string) (int, error)
3737
ActiveDelegatesWithRolls(ctx context.Context, blockID string) ([]string, error)
3838
LiquidityBakingCPMMAddress(ctx context.Context, blockID string) (string, error)
39+
TxRollupState(ctx context.Context, txRollupID string) (TxRollupState, error)
40+
TxRollupCommitment(ctx context.Context, blockID, txRollupID, blockLevel string) (*RollupCommitmentForBlock, error)
41+
TxRollupInbox(ctx context.Context, blockID, txRollupID, blockLevel string) (*TxRollupInbox, error)
42+
TxRollupPendingBondedCommitments(ctx context.Context, blockID, txRollupID, pkh string) (uint64, error)
3943
}
4044

4145
// Context -
@@ -319,3 +323,47 @@ func (api *Context) LiquidityBakingCPMMAddress(ctx context.Context, blockID stri
319323
err = req.doWithJSONResponse(ctx, api.client, &result)
320324
return result, err
321325
}
326+
327+
// TxRollupState -
328+
func (api *Context) TxRollupState(ctx context.Context, blockID, txRollupID string) (TxRollupState, error) {
329+
req, err := newGetRequest(api.baseURL, fmt.Sprintf("chains/%s/blocks/%s/context/tx_rollup/%s/state", api.chainID, blockID, txRollupID), nil)
330+
if err != nil {
331+
return TxRollupState{}, err
332+
}
333+
var state TxRollupState
334+
err = req.doWithJSONResponse(ctx, api.client, &state)
335+
return state, err
336+
}
337+
338+
// TxRollupCommitment -
339+
func (api *Context) TxRollupCommitment(ctx context.Context, blockID, txRollupID, blockLevel string) (*RollupCommitmentForBlock, error) {
340+
req, err := newGetRequest(api.baseURL, fmt.Sprintf("chains/%s/blocks/%s/context/tx_rollup/%s/commitment/%s", api.chainID, blockID, txRollupID, blockLevel), nil)
341+
if err != nil {
342+
return nil, err
343+
}
344+
result := new(RollupCommitmentForBlock)
345+
err = req.doWithJSONResponse(ctx, api.client, result)
346+
return result, err
347+
}
348+
349+
// TxRollupInbox -
350+
func (api *Context) TxRollupInbox(ctx context.Context, blockID, txRollupID, blockLevel string) (*TxRollupInbox, error) {
351+
req, err := newGetRequest(api.baseURL, fmt.Sprintf("chains/%s/blocks/%s/context/tx_rollup/%s/inbox/%s", api.chainID, blockID, txRollupID, blockLevel), nil)
352+
if err != nil {
353+
return nil, err
354+
}
355+
inbox := new(TxRollupInbox)
356+
err = req.doWithJSONResponse(ctx, api.client, inbox)
357+
return inbox, err
358+
}
359+
360+
// TxRollupPendingBondedCommitments -
361+
func (api *Context) TxRollupPendingBondedCommitments(ctx context.Context, blockID, txRollupID, pkh string) (uint64, error) {
362+
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)
363+
if err != nil {
364+
return 0, err
365+
}
366+
var response uint64
367+
err = req.doWithJSONResponse(ctx, api.client, &response)
368+
return response, err
369+
}

node/context_data.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,62 @@ const (
112112
InactiveDelegateType DelegateType = "inactive"
113113
AllDelegateType DelegateType = "all"
114114
)
115+
116+
// TxRollupState -
117+
type TxRollupState struct {
118+
LastRemovedCommitmentHashes *LastRemovedCommitmentHashes `json:"last_removed_commitment_hashes,omitempty"`
119+
FinalizedCommitments RollupStateCommitment `json:"finalized_commitments"`
120+
UnfinalizedCommitments RollupStateCommitment `json:"unfinalized_commitments"`
121+
UncommittedInboxes RollupStateCommitment `json:"uncommitted_inboxes"`
122+
CommitmentNewestHash *string `json:"commitment_newest_hash,omitempty"`
123+
TezosHeadLevel *uint64 `json:"tezos_head_level,omitempty"`
124+
BurnPerByte stdJSON.Number `json:"burn_per_byte,omitempty"`
125+
AllocatedStorage stdJSON.Number `json:"allocated_storage"`
126+
OccupiedStorage stdJSON.Number `json:"occupied_storage"`
127+
InboxEma uint64 `json:"inbox_ema"`
128+
CommitmentsWatermark *uint64 `json:"commitments_watermark,omitempty"`
129+
}
130+
131+
// LastRemovedCommitmentHashes -
132+
type LastRemovedCommitmentHashes struct {
133+
LastMessageHash string `json:"last_message_hash"`
134+
CommitmentHash string `json:"commitment_hash"`
135+
}
136+
137+
// RollupStateCommitment -
138+
type RollupStateCommitment struct {
139+
Next *uint64 `json:"next,omitempty"`
140+
Newest *uint64 `json:"newest,omitempty"`
141+
Oldest *uint64 `json:"oldest,omitempty"`
142+
}
143+
144+
// RollupCommitmentForBlock -
145+
type RollupCommitmentForBlock struct {
146+
Commitment RollupCommitment `json:"commitment"`
147+
CommitmentHash string `json:"commitment_hash"`
148+
Committer string `json:"committer"`
149+
SubmittedAt uint64 `json:"submitted_at"`
150+
FinalizedAt uint64 `json:"finalized_at"`
151+
}
152+
153+
// RollupCommitment -
154+
type RollupCommitment struct {
155+
Level uint64 `json:"level"`
156+
Messages RollupCommitmentMessages `json:"messages"`
157+
Predecessor *string `json:"predecessor,omitempty"`
158+
InboxMerkleRoot string `json:"inbox_merkle_root"`
159+
}
160+
161+
// RollupCommitmentMessages -
162+
type RollupCommitmentMessages struct {
163+
Count uint64 `json:"count"`
164+
Root string `json:"root"`
165+
LastMessageResultHash string `json:"last_message_result_hash"`
166+
}
167+
168+
// TxRollupInbox -
169+
type TxRollupInbox struct {
170+
InboxLength uint64 `json:"inbox_length"`
171+
CumulatedSize uint64 `json:"cumulated_size"`
172+
MerkleRoot string `json:"merkle_root"`
173+
}

0 commit comments

Comments
 (0)