This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
smart_rollup.go
185 lines (162 loc) · 5.45 KB
/
smart_rollup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Copyright (c) 2023 Blockwatch Data Inc.
// Author: alex@blockwatch.cc
package rpc
import (
"encoding/json"
"fmt"
"blockwatch.cc/tzgo/micheline"
"blockwatch.cc/tzgo/tezos"
)
// Ensure SmartRollup types implement the TypedOperation interface.
var (
_ TypedOperation = (*SmartRollupOriginate)(nil)
_ TypedOperation = (*SmartRollupAddMessages)(nil)
_ TypedOperation = (*SmartRollupCement)(nil)
_ TypedOperation = (*SmartRollupPublish)(nil)
_ TypedOperation = (*SmartRollupRefute)(nil)
_ TypedOperation = (*SmartRollupTimeout)(nil)
_ TypedOperation = (*SmartRollupExecuteOutboxMessage)(nil)
_ TypedOperation = (*SmartRollupRecoverBond)(nil)
)
type SmartRollupResult struct {
Address *tezos.Address `json:"address,omitempty"` // v016, smart_rollup_originate
Size *tezos.Z `json:"size,omitempty"` // v016, smart_rollup_originate
InboxLevel int64 `json:"inbox_level,omitempty"` // v016, smart_rollup_cement
StakedHash *tezos.SmartRollupCommitHash `json:"staked_hash,omitempty"` // v016, smart_rollup_publish
PublishedAtLevel int64 `json:"published_at_level,omitempty"` // v016, smart_rollup_publish
GameStatus *GameStatus `json:"game_status,omitempty"` // v016, smart_rollup_refute, smart_rollup_timeout
}
type SmartRollupOriginate struct {
Manager
PvmKind tezos.PvmKind `json:"pvm_kind"`
Kernel tezos.HexBytes `json:"kernel"`
OriginationProof tezos.HexBytes `json:"origination_proof"`
ParametersTy micheline.Prim `json:"parameters_ty"`
}
type SmartRollupAddMessages struct {
Manager
Messages []tezos.HexBytes `json:"message"`
}
type SmartRollupCement struct {
Manager
Rollup tezos.Address `json:"rollup"`
Commitment tezos.SmartRollupCommitHash `json:"commitment"`
}
type SmartRollupCommitment struct {
CompressedState tezos.SmartRollupStateHash `json:"compressed_state"`
InboxLevel int64 `json:"inbox_level"`
Predecessor tezos.SmartRollupCommitHash `json:"predecessor"`
NumberOfTicks tezos.Z `json:"number_of_ticks"`
}
type SmartRollupPublish struct {
Manager
Rollup tezos.Address `json:"rollup"`
Commitment SmartRollupCommitment `json:"commitment"`
}
type SmartRollupRefute struct {
Manager
Rollup tezos.Address `json:"rollup"`
Opponent tezos.Address `json:"opponent"`
Refutation SmartRollupRefutation `json:"refutation"`
}
type SmartRollupRefutation struct {
Kind string `json:"refutation_kind"`
PlayerHash *tezos.SmartRollupCommitHash `json:"player_commitment_hash,omitempty"`
OpponentHash *tezos.SmartRollupCommitHash `json:"opponent_commitment_hash,omitempty"`
Choice *tezos.Z `json:"choice,omitempty"`
Step *SmartRollupRefuteStep `json:"step,omitempty"`
}
// Step can either be
//
// - []SmartRollupTick
// - SmartRollupInputProof
// - smth else?
//
// There is no indication in the outer parts of the refutation struct that
// suggests how to decode this.
type SmartRollupRefuteStep struct {
Ticks []SmartRollupTick
Proof *SmartRollupProof
}
type SmartRollupProof struct {
PvmStep tezos.HexBytes `json:"pvm_step,omitempty"`
InputProof *SmartRollupInputProof `json:"input_proof,omitempty"`
}
func (s *SmartRollupRefuteStep) UnmarshalJSON(buf []byte) error {
if len(buf) == 0 {
return nil
}
switch buf[0] {
case '[':
s.Ticks = make([]SmartRollupTick, 0)
return json.Unmarshal(buf, &s.Ticks)
case '{':
s.Proof = &SmartRollupProof{}
return json.Unmarshal(buf, s.Proof)
default:
return fmt.Errorf("Invalid refute step data %q", string(buf))
}
}
func (s SmartRollupRefuteStep) MarshalJSON() ([]byte, error) {
if s.Ticks != nil {
return json.Marshal(s.Ticks)
}
if s.Proof != nil {
return json.Marshal(s.Proof)
}
return nil, nil
}
type SmartRollupTick struct {
State tezos.SmartRollupStateHash `json:"state"`
Tick tezos.Z `json:"tick"`
}
type SmartRollupInputProof struct {
Kind string `json:"input_proof_kind"`
Level int64 `json:"level"`
Counter tezos.Z `json:"message_counter"`
Proof tezos.HexBytes `json:"serialized_proof"`
}
type SmartRollupTimeout struct {
Manager
Rollup tezos.Address `json:"rollup"`
Stakers struct {
Alice tezos.Address `json:"alice"`
Bob tezos.Address `json:"bob"`
} `json:"stakers"`
}
type SmartRollupExecuteOutboxMessage struct {
Manager
Rollup tezos.Address `json:"rollup"`
CementedCommitment tezos.SmartRollupCommitHash `json:"cemented_commitment"`
OutputProof tezos.HexBytes `json:"output_proof"`
}
type SmartRollupRecoverBond struct {
Manager
Rollup tezos.Address `json:"rollup"`
Staker tezos.Address `json:"staker"`
}
type GameStatus struct {
Status string `json:"status,omitempty"`
Kind string `json:"kind,omitempty"`
Reason string `json:"reason,omitempty"`
Player *tezos.Address `json:"player,omitempty"`
}
func (s *GameStatus) UnmarshalJSON(buf []byte) error {
if len(buf) == 0 {
return nil
}
switch buf[0] {
case '"':
s.Status = string(buf[1 : len(buf)-1])
case '{':
type alias *GameStatus
type wrapper struct {
S alias `json:"result"`
}
a := wrapper{alias(s)}
_ = json.Unmarshal(buf, &a)
default:
return fmt.Errorf("Invalid game status data %q", string(buf))
}
return nil
}