|
2 | 2 |
|
3 | 3 | You can use the chain specific SDKs to inspect the state of your MCMS and timelock contracts.
|
4 | 4 |
|
5 |
| -### Example: MCMS Inspection |
| 5 | +- [EVM](#evm) |
| 6 | + - [MCMS Inspection](#example-evm-mcms-inspection) |
| 7 | + - [Timelock Inspection](#example-evm-timelock-inspection) |
| 8 | +- [Solana](#solana) |
| 9 | + - [MCMS Inspection](#example-solana-mcms-inspection) |
| 10 | + - [Timelock Inspection](#example-solana-timelock-inspection) |
| 11 | + |
| 12 | +## EVM |
| 13 | + |
| 14 | +### Example: EVM MCMS Inspection |
| 15 | + |
| 16 | +```go |
| 17 | +package main |
| 18 | + |
| 19 | +import ( |
| 20 | + "log" |
| 21 | + |
| 22 | + "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" |
| 23 | + |
| 24 | + "github.com/smartcontractkit/mcms/sdk/evm" |
| 25 | +) |
| 26 | + |
| 27 | +func main() { |
| 28 | + // Inspecting MCMS contract on EVM |
| 29 | + backend := backends.SimulatedBackend{} |
| 30 | + inspector := evm.NewInspector(backend) |
| 31 | + contractAddress := "0x123" // replace with your address |
| 32 | + |
| 33 | + // Get the op count |
| 34 | + opcount, err := inspector.GetOpCount(contractAddress) |
| 35 | + if err != nil { |
| 36 | + log.Fatalf("failed to get op count: %v", err) |
| 37 | + } |
| 38 | + log.Printf("Op count: %d", opcount) |
| 39 | + |
| 40 | + // Get the config |
| 41 | + config, err := inspector.GetConfig(contractAddress) |
| 42 | + if err != nil { |
| 43 | + log.Fatalf("failed to get config: %v", err) |
| 44 | + } |
| 45 | + log.Printf("Config: %+v", config) |
| 46 | + |
| 47 | + // Get the root |
| 48 | + root, validUntil, err := inspector.GetRoot(contractAddress) |
| 49 | + if err != nil { |
| 50 | + log.Fatalf("failed to get root: %v", err) |
| 51 | + } |
| 52 | + log.Printf("Root: %s, Valid until: %d", root.Hex(), validUntil) |
| 53 | + |
| 54 | + // Get the proposers |
| 55 | + metadata, err := inspector.GetRootMetadata(contractAddress) |
| 56 | + if err != nil { |
| 57 | + log.Fatalf("failed to get root metadata: %v", err) |
| 58 | + } |
| 59 | + log.Printf("Metadata: %+v", metadata) |
| 60 | + |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +### Example: EVM Timelock Inspection |
| 65 | + |
| 66 | +```go |
| 67 | +package main |
| 68 | + |
| 69 | +import ( |
| 70 | + "fmt" |
| 71 | + "log" |
| 72 | + |
| 73 | + "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" |
| 74 | + |
| 75 | + "github.com/smartcontractkit/mcms/sdk/evm" |
| 76 | +) |
| 77 | + |
| 78 | +func main() { |
| 79 | + // Inspecting Timelock contract on EVM |
| 80 | + backend := backends.SimulatedBackend{} |
| 81 | + inspector := evm.NewTimelockInspector(backend) |
| 82 | + contractAddress := "0x123" // replace with your address |
| 83 | + |
| 84 | + // Get the proposers |
| 85 | + proposers, err := inspector.GetProposers(contractAddress) |
| 86 | + if err != nil { |
| 87 | + log.Fatalf("failed to get op count: %v", err) |
| 88 | + } |
| 89 | + log.Printf("proposers: %d", proposers) |
| 90 | + |
| 91 | + // Get the bypassers |
| 92 | + bypassers, err := inspector.GetBypassers(contractAddress) |
| 93 | + if err != nil { |
| 94 | + log.Fatalf("failed to get bypassers: %v", err) |
| 95 | + } |
| 96 | + log.Printf("bypassers: %+v", bypassers) |
| 97 | + |
| 98 | + // Get the executors |
| 99 | + executors, err := inspector.GetExecutors(contractAddress) |
| 100 | + if err != nil { |
| 101 | + log.Fatalf("failed to get executors: %v", err) |
| 102 | + } |
| 103 | + log.Printf("executors: %s", executors) |
| 104 | + |
| 105 | + // Get the cancellers |
| 106 | + cancellers, err := inspector.GetCancellers(contractAddress) |
| 107 | + if err != nil { |
| 108 | + log.Fatalf("failed to get root metadata: %v", err) |
| 109 | + } |
| 110 | + log.Printf("Metadata: %+v", cancellers) |
| 111 | + |
| 112 | + // Get operation statuses, opID is a [32]byte representing the operation ID |
| 113 | + opID := [32]byte{} // replace with your operation ID |
| 114 | + isOp, err := inspector.IsOperation(contractAddress, opID) |
| 115 | + if err != nil { |
| 116 | + log.Fatalf("failed to get operation status: %v", err) |
| 117 | + } |
| 118 | + log.Printf("IsOperation: %t", isOp) |
| 119 | + |
| 120 | + isReady, err := inspector.IsOperationReady(contractAddress, opID) |
| 121 | + if err != nil { |
| 122 | + log.Fatalf("failed to get operation status: %v", err) |
| 123 | + } |
| 124 | + fmt.Printf("IsOperationReady: %t", isReady) |
| 125 | + |
| 126 | + isPending, err := inspector.IsOperationPending(contractAddress, opID) |
| 127 | + if err != nil { |
| 128 | + log.Fatalf("failed to get operation status: %v", err) |
| 129 | + } |
| 130 | + fmt.Printf("IsOperationPending: %t", isPending) |
| 131 | + |
| 132 | + isDone, err := inspector.IsOperationDone(contractAddress, opID) |
| 133 | + if err != nil { |
| 134 | + log.Fatalf("failed to get operation status: %v", err) |
| 135 | + } |
| 136 | + fmt.Printf("IsOperationDone: %t", isDone) |
| 137 | + |
| 138 | +} |
| 139 | + |
| 140 | +``` |
| 141 | + |
| 142 | +## Solana |
| 143 | + |
| 144 | +### Example: Solana MCMS Inspection |
6 | 145 |
|
7 | 146 | ```go
|
8 | 147 | package main
|
9 | 148 |
|
10 | 149 | import (
|
11 |
| - "log" |
| 150 | + "context" |
| 151 | + "log" |
12 | 152 |
|
13 |
| - "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" |
| 153 | + "github.com/gagliardetto/solana-go" |
| 154 | + "github.com/gagliardetto/solana-go/rpc" |
14 | 155 |
|
15 |
| - "github.com/smartcontractkit/mcms/sdk/evm" |
| 156 | + mcmsSolana "github.com/smartcontractkit/mcms/sdk/solana" |
16 | 157 | )
|
17 | 158 |
|
18 | 159 | func main() {
|
19 |
| - // Inspecting MCMS contract on EVM |
20 |
| - backend := backends.SimulatedBackend{} |
21 |
| - inspector := evm.NewInspector(backend) |
22 |
| - contractAddress := "0x123" // replace with your address |
23 |
| - |
24 |
| - // Get the op count |
25 |
| - opcount, err := inspector.GetOpCount(contractAddress) |
26 |
| - if err != nil { |
27 |
| - log.Fatalf("failed to get op count: %v", err) |
28 |
| - } |
29 |
| - log.Printf("Op count: %d", opcount) |
30 |
| - |
31 |
| - // Get the config |
32 |
| - config, err := inspector.GetConfig(contractAddress) |
33 |
| - if err != nil { |
34 |
| - log.Fatalf("failed to get config: %v", err) |
35 |
| - } |
36 |
| - log.Printf("Config: %+v", config) |
37 |
| - |
38 |
| - // Get the root |
39 |
| - root, validUntil, err := inspector.GetRoot(contractAddress) |
40 |
| - if err != nil { |
41 |
| - log.Fatalf("failed to get root: %v", err) |
42 |
| - } |
43 |
| - log.Printf("Root: %s, Valid until: %d", root.Hex(), validUntil) |
44 |
| - |
45 |
| - // Get the proposers |
46 |
| - metadata, err := inspector.GetRootMetadata(contractAddress) |
47 |
| - if err != nil { |
48 |
| - log.Fatalf("failed to get root metadata: %v", err) |
49 |
| - } |
50 |
| - log.Printf("Metadata: %+v", metadata) |
| 160 | + testMCMProgramID := solana.MustPublicKeyFromBase58("6UmMZr5MEqiKWD5jqTJd1WCR5kT8oZuFYBLJFi1o6GQX") |
| 161 | + testMCMSeed := [32]byte{'t', 'e', 's', 't', '-', 'm', 'c', 'm'} |
| 162 | + contractID := mcmsSolana.ContractAddress(testMCMProgramID, testMCMSeed) |
| 163 | + |
| 164 | + // Inspecting MCMS contract on Solana |
| 165 | + ctx := context.Background() |
| 166 | + backend := rpc.New("https://api.devnet.solana.com") |
| 167 | + inspector := mcmsSolana.NewInspector(backend) |
| 168 | + |
| 169 | + // Get the op count |
| 170 | + opcount, err := inspector.GetOpCount(ctx, contractID) |
| 171 | + if err != nil { |
| 172 | + log.Fatalf("failed to get op count: %v", err) |
| 173 | + } |
| 174 | + log.Printf("Op count: %d", opcount) |
| 175 | + |
| 176 | + // Get the config |
| 177 | + config, err := inspector.GetConfig(ctx, contractID) |
| 178 | + if err != nil { |
| 179 | + log.Fatalf("failed to get config: %v", err) |
| 180 | + } |
| 181 | + log.Printf("Config: %+v", config) |
| 182 | + |
| 183 | + // Get the root |
| 184 | + root, validUntil, err := inspector.GetRoot(ctx, contractID) |
| 185 | + if err != nil { |
| 186 | + log.Fatalf("failed to get root: %v", err) |
| 187 | + } |
| 188 | + log.Printf("Root: %s, Valid until: %d", root.Hex(), validUntil) |
| 189 | + |
| 190 | + // Get the proposers |
| 191 | + metadata, err := inspector.GetRootMetadata(ctx, contractID) |
| 192 | + if err != nil { |
| 193 | + log.Fatalf("failed to get root metadata: %v", err) |
| 194 | + } |
| 195 | + log.Printf("Metadata: %+v", metadata) |
51 | 196 |
|
52 | 197 | }
|
53 | 198 | ```
|
54 | 199 |
|
55 |
| -### Example: Timelock Inspection |
| 200 | +### Example: Solana Timelock Inspection |
56 | 201 |
|
57 | 202 | ```go
|
58 | 203 | package main
|
59 | 204 |
|
60 | 205 | import (
|
61 |
| - "fmt" |
62 |
| - "log" |
| 206 | + "context" |
| 207 | + "fmt" |
| 208 | + "log" |
63 | 209 |
|
64 |
| - "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" |
| 210 | + "github.com/gagliardetto/solana-go" |
| 211 | + "github.com/gagliardetto/solana-go/rpc" |
65 | 212 |
|
66 |
| - "github.com/smartcontractkit/mcms/sdk/evm" |
| 213 | + mcmsSolana "github.com/smartcontractkit/mcms/sdk/solana" |
67 | 214 | )
|
68 | 215 |
|
69 | 216 | func main() {
|
70 |
| - // Inspecting Timelock contract on EVM |
71 |
| - backend := backends.SimulatedBackend{} |
72 |
| - inspector := evm.NewTimelockInspector(backend) |
73 |
| - contractAddress := "0x123" // replace with your address |
74 |
| - |
75 |
| - // Get the proposers |
76 |
| - proposers, err := inspector.GetProposers(contractAddress) |
77 |
| - if err != nil { |
78 |
| - log.Fatalf("failed to get op count: %v", err) |
79 |
| - } |
80 |
| - log.Printf("proposers: %d", proposers) |
81 |
| - |
82 |
| - // Get the bypassers |
83 |
| - bypassers, err := inspector.GetBypassers(contractAddress) |
84 |
| - if err != nil { |
85 |
| - log.Fatalf("failed to get bypassers: %v", err) |
86 |
| - } |
87 |
| - log.Printf("bypassers: %+v", bypassers) |
88 |
| - |
89 |
| - // Get the executors |
90 |
| - executors, err := inspector.GetExecutors(contractAddress) |
91 |
| - if err != nil { |
92 |
| - log.Fatalf("failed to get executors: %v", err) |
93 |
| - } |
94 |
| - log.Printf("executors: %s", executors) |
95 |
| - |
96 |
| - // Get the cancellers |
97 |
| - cancellers, err := inspector.GetCancellers(contractAddress) |
98 |
| - if err != nil { |
99 |
| - log.Fatalf("failed to get root metadata: %v", err) |
100 |
| - } |
101 |
| - log.Printf("Metadata: %+v", cancellers) |
102 |
| - |
103 |
| - // Get operation statuses, opID is a [32]byte representing the operation ID |
104 |
| - opID := [32]byte{} // replace with your operation ID |
105 |
| - isOp, err := inspector.IsOperation(contractAddress, opID) |
106 |
| - if err != nil { |
107 |
| - log.Fatalf("failed to get operation status: %v", err) |
108 |
| - } |
109 |
| - log.Printf("IsOperation: %t", isOp) |
110 |
| - |
111 |
| - isReady, err := inspector.IsOperationReady(contractAddress, opID) |
112 |
| - if err != nil { |
113 |
| - log.Fatalf("failed to get operation status: %v", err) |
114 |
| - } |
115 |
| - fmt.Printf("IsOperationReady: %t", isReady) |
116 |
| - |
117 |
| - isPending, err := inspector.IsOperationPending(contractAddress, opID) |
118 |
| - if err != nil { |
119 |
| - log.Fatalf("failed to get operation status: %v", err) |
120 |
| - } |
121 |
| - fmt.Printf("IsOperationPending: %t", isPending) |
122 |
| - |
123 |
| - isDone, err := inspector.IsOperationDone(contractAddress, opID) |
124 |
| - if err != nil { |
125 |
| - log.Fatalf("failed to get operation status: %v", err) |
126 |
| - } |
127 |
| - fmt.Printf("IsOperationDone: %t", isDone) |
| 217 | + testMCMProgramID := solana.MustPublicKeyFromBase58("6UmMZr5MEqiKWD5jqTJd1WCR5kT8oZuFYBLJFi1o6GQX") |
| 218 | + testMCMSeed := [32]byte{'t', 'e', 's', 't', '-', 'm', 'c', 'm'} |
| 219 | + contractID := mcmsSolana.ContractAddress(testMCMProgramID, testMCMSeed) |
| 220 | + ctx := context.Background() |
| 221 | + backend := rpc.New("https://api.devnet.solana.com") |
| 222 | + inspector := mcmsSolana.NewTimelockInspector(backend) |
| 223 | + // Step 1: Initialize the ProposalBuilder |
| 224 | + // Get the proposers |
| 225 | + proposers, err := inspector.GetProposers(ctx, contractID) |
| 226 | + if err != nil { |
| 227 | + log.Fatalf("failed to get op count: %v", err) |
| 228 | + } |
| 229 | + log.Printf("proposers: %d", proposers) |
| 230 | + |
| 231 | + // Get the bypassers |
| 232 | + bypassers, err := inspector.GetBypassers(ctx, contractID) |
| 233 | + if err != nil { |
| 234 | + log.Fatalf("failed to get bypassers: %v", err) |
| 235 | + } |
| 236 | + log.Printf("bypassers: %+v", bypassers) |
| 237 | + |
| 238 | + // Get the executors |
| 239 | + executors, err := inspector.GetExecutors(ctx, contractID) |
| 240 | + if err != nil { |
| 241 | + log.Fatalf("failed to get executors: %v", err) |
| 242 | + } |
| 243 | + log.Printf("executors: %s", executors) |
| 244 | + |
| 245 | + // Get the cancellers |
| 246 | + cancellers, err := inspector.GetCancellers(ctx, contractID) |
| 247 | + if err != nil { |
| 248 | + log.Fatalf("failed to get root metadata: %v", err) |
| 249 | + } |
| 250 | + log.Printf("Metadata: %+v", cancellers) |
| 251 | + |
| 252 | + // Get operation statuses, opID is a [32]byte representing the operation ID |
| 253 | + opID := [32]byte{} // replace with your operation ID |
| 254 | + isOp, err := inspector.IsOperation(ctx, contractID, opID) |
| 255 | + if err != nil { |
| 256 | + log.Fatalf("failed to get operation status: %v", err) |
| 257 | + } |
| 258 | + log.Printf("IsOperation: %t", isOp) |
| 259 | + |
| 260 | + isReady, err := inspector.IsOperationReady(ctx, contractID, opID) |
| 261 | + if err != nil { |
| 262 | + log.Fatalf("failed to get operation status: %v", err) |
| 263 | + } |
| 264 | + fmt.Printf("IsOperationReady: %t", isReady) |
| 265 | + |
| 266 | + isPending, err := inspector.IsOperationPending(ctx, contractID, opID) |
| 267 | + if err != nil { |
| 268 | + log.Fatalf("failed to get operation status: %v", err) |
| 269 | + } |
| 270 | + fmt.Printf("IsOperationPending: %t", isPending) |
| 271 | + |
| 272 | + isDone, err := inspector.IsOperationDone(ctx, contractID, opID) |
| 273 | + if err != nil { |
| 274 | + log.Fatalf("failed to get operation status: %v", err) |
| 275 | + } |
| 276 | + fmt.Printf("IsOperationDone: %t", isDone) |
128 | 277 |
|
129 | 278 | }
|
130 | 279 |
|
131 |
| -``` |
| 280 | + |
| 281 | +``` |
0 commit comments