github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/cli/smartcontract/testdata/rpcbindings/notifications/rpcbindings.out (about) 1 // Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT. 2 3 // Package structs contains RPC wrappers for Notifications contract. 4 package structs 5 6 import ( 7 "errors" 8 "fmt" 9 "github.com/nspcc-dev/neo-go/pkg/core/transaction" 10 "github.com/nspcc-dev/neo-go/pkg/neorpc/result" 11 "github.com/nspcc-dev/neo-go/pkg/util" 12 "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" 13 "unicode/utf8" 14 ) 15 16 // Hash contains contract hash. 17 var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x0} 18 19 // ComplicatedNameEvent represents "! complicated name %$#" event emitted by the contract. 20 type ComplicatedNameEvent struct { 21 ComplicatedParam string 22 } 23 24 // SomeMapEvent represents "SomeMap" event emitted by the contract. 25 type SomeMapEvent struct { 26 M map[any]any 27 } 28 29 // SomeStructEvent represents "SomeStruct" event emitted by the contract. 30 type SomeStructEvent struct { 31 S []any 32 } 33 34 // SomeArrayEvent represents "SomeArray" event emitted by the contract. 35 type SomeArrayEvent struct { 36 A []any 37 } 38 39 // SomeUnexportedFieldEvent represents "SomeUnexportedField" event emitted by the contract. 40 type SomeUnexportedFieldEvent struct { 41 S []any 42 } 43 44 // Actor is used by Contract to call state-changing methods. 45 type Actor interface { 46 MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) 47 MakeRun(script []byte) (*transaction.Transaction, error) 48 MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) 49 MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) 50 SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) 51 SendRun(script []byte) (util.Uint256, uint32, error) 52 } 53 54 // Contract implements all contract methods. 55 type Contract struct { 56 actor Actor 57 hash util.Uint160 58 } 59 60 // New creates an instance of Contract using Hash and the given Actor. 61 func New(actor Actor) *Contract { 62 var hash = Hash 63 return &Contract{actor, hash} 64 } 65 66 // Array creates a transaction invoking `array` method of the contract. 67 // This transaction is signed and immediately sent to the network. 68 // The values returned are its hash, ValidUntilBlock value and error if any. 69 func (c *Contract) Array() (util.Uint256, uint32, error) { 70 return c.actor.SendCall(c.hash, "array") 71 } 72 73 // ArrayTransaction creates a transaction invoking `array` method of the contract. 74 // This transaction is signed, but not sent to the network, instead it's 75 // returned to the caller. 76 func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) { 77 return c.actor.MakeCall(c.hash, "array") 78 } 79 80 // ArrayUnsigned creates a transaction invoking `array` method of the contract. 81 // This transaction is not signed, it's simply returned to the caller. 82 // Any fields of it that do not affect fees can be changed (ValidUntilBlock, 83 // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. 84 func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) { 85 return c.actor.MakeUnsignedCall(c.hash, "array", nil) 86 } 87 88 // CrazyMap creates a transaction invoking `crazyMap` method of the contract. 89 // This transaction is signed and immediately sent to the network. 90 // The values returned are its hash, ValidUntilBlock value and error if any. 91 func (c *Contract) CrazyMap() (util.Uint256, uint32, error) { 92 return c.actor.SendCall(c.hash, "crazyMap") 93 } 94 95 // CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract. 96 // This transaction is signed, but not sent to the network, instead it's 97 // returned to the caller. 98 func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) { 99 return c.actor.MakeCall(c.hash, "crazyMap") 100 } 101 102 // CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract. 103 // This transaction is not signed, it's simply returned to the caller. 104 // Any fields of it that do not affect fees can be changed (ValidUntilBlock, 105 // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. 106 func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) { 107 return c.actor.MakeUnsignedCall(c.hash, "crazyMap", nil) 108 } 109 110 // Main creates a transaction invoking `main` method of the contract. 111 // This transaction is signed and immediately sent to the network. 112 // The values returned are its hash, ValidUntilBlock value and error if any. 113 func (c *Contract) Main() (util.Uint256, uint32, error) { 114 return c.actor.SendCall(c.hash, "main") 115 } 116 117 // MainTransaction creates a transaction invoking `main` method of the contract. 118 // This transaction is signed, but not sent to the network, instead it's 119 // returned to the caller. 120 func (c *Contract) MainTransaction() (*transaction.Transaction, error) { 121 return c.actor.MakeCall(c.hash, "main") 122 } 123 124 // MainUnsigned creates a transaction invoking `main` method of the contract. 125 // This transaction is not signed, it's simply returned to the caller. 126 // Any fields of it that do not affect fees can be changed (ValidUntilBlock, 127 // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. 128 func (c *Contract) MainUnsigned() (*transaction.Transaction, error) { 129 return c.actor.MakeUnsignedCall(c.hash, "main", nil) 130 } 131 132 // Struct creates a transaction invoking `struct` method of the contract. 133 // This transaction is signed and immediately sent to the network. 134 // The values returned are its hash, ValidUntilBlock value and error if any. 135 func (c *Contract) Struct() (util.Uint256, uint32, error) { 136 return c.actor.SendCall(c.hash, "struct") 137 } 138 139 // StructTransaction creates a transaction invoking `struct` method of the contract. 140 // This transaction is signed, but not sent to the network, instead it's 141 // returned to the caller. 142 func (c *Contract) StructTransaction() (*transaction.Transaction, error) { 143 return c.actor.MakeCall(c.hash, "struct") 144 } 145 146 // StructUnsigned creates a transaction invoking `struct` method of the contract. 147 // This transaction is not signed, it's simply returned to the caller. 148 // Any fields of it that do not affect fees can be changed (ValidUntilBlock, 149 // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. 150 func (c *Contract) StructUnsigned() (*transaction.Transaction, error) { 151 return c.actor.MakeUnsignedCall(c.hash, "struct", nil) 152 } 153 154 // UnexportedField creates a transaction invoking `unexportedField` method of the contract. 155 // This transaction is signed and immediately sent to the network. 156 // The values returned are its hash, ValidUntilBlock value and error if any. 157 func (c *Contract) UnexportedField() (util.Uint256, uint32, error) { 158 return c.actor.SendCall(c.hash, "unexportedField") 159 } 160 161 // UnexportedFieldTransaction creates a transaction invoking `unexportedField` method of the contract. 162 // This transaction is signed, but not sent to the network, instead it's 163 // returned to the caller. 164 func (c *Contract) UnexportedFieldTransaction() (*transaction.Transaction, error) { 165 return c.actor.MakeCall(c.hash, "unexportedField") 166 } 167 168 // UnexportedFieldUnsigned creates a transaction invoking `unexportedField` method of the contract. 169 // This transaction is not signed, it's simply returned to the caller. 170 // Any fields of it that do not affect fees can be changed (ValidUntilBlock, 171 // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. 172 func (c *Contract) UnexportedFieldUnsigned() (*transaction.Transaction, error) { 173 return c.actor.MakeUnsignedCall(c.hash, "unexportedField", nil) 174 } 175 176 // ComplicatedNameEventsFromApplicationLog retrieves a set of all emitted events 177 // with "! complicated name %$#" name from the provided [result.ApplicationLog]. 178 func ComplicatedNameEventsFromApplicationLog(log *result.ApplicationLog) ([]*ComplicatedNameEvent, error) { 179 if log == nil { 180 return nil, errors.New("nil application log") 181 } 182 183 var res []*ComplicatedNameEvent 184 for i, ex := range log.Executions { 185 for j, e := range ex.Events { 186 if e.Name != "! complicated name %$#" { 187 continue 188 } 189 event := new(ComplicatedNameEvent) 190 err := event.FromStackItem(e.Item) 191 if err != nil { 192 return nil, fmt.Errorf("failed to deserialize ComplicatedNameEvent from stackitem (execution #%d, event #%d): %w", i, j, err) 193 } 194 res = append(res, event) 195 } 196 } 197 198 return res, nil 199 } 200 201 // FromStackItem converts provided [stackitem.Array] to ComplicatedNameEvent or 202 // returns an error if it's not possible to do to so. 203 func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error { 204 if item == nil { 205 return errors.New("nil item") 206 } 207 arr, ok := item.Value().([]stackitem.Item) 208 if !ok { 209 return errors.New("not an array") 210 } 211 if len(arr) != 1 { 212 return errors.New("wrong number of structure elements") 213 } 214 215 var ( 216 index = -1 217 err error 218 ) 219 index++ 220 e.ComplicatedParam, err = func(item stackitem.Item) (string, error) { 221 b, err := item.TryBytes() 222 if err != nil { 223 return "", err 224 } 225 if !utf8.Valid(b) { 226 return "", errors.New("not a UTF-8 string") 227 } 228 return string(b), nil 229 }(arr[index]) 230 if err != nil { 231 return fmt.Errorf("field ComplicatedParam: %w", err) 232 } 233 234 return nil 235 } 236 237 // SomeMapEventsFromApplicationLog retrieves a set of all emitted events 238 // with "SomeMap" name from the provided [result.ApplicationLog]. 239 func SomeMapEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeMapEvent, error) { 240 if log == nil { 241 return nil, errors.New("nil application log") 242 } 243 244 var res []*SomeMapEvent 245 for i, ex := range log.Executions { 246 for j, e := range ex.Events { 247 if e.Name != "SomeMap" { 248 continue 249 } 250 event := new(SomeMapEvent) 251 err := event.FromStackItem(e.Item) 252 if err != nil { 253 return nil, fmt.Errorf("failed to deserialize SomeMapEvent from stackitem (execution #%d, event #%d): %w", i, j, err) 254 } 255 res = append(res, event) 256 } 257 } 258 259 return res, nil 260 } 261 262 // FromStackItem converts provided [stackitem.Array] to SomeMapEvent or 263 // returns an error if it's not possible to do to so. 264 func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error { 265 if item == nil { 266 return errors.New("nil item") 267 } 268 arr, ok := item.Value().([]stackitem.Item) 269 if !ok { 270 return errors.New("not an array") 271 } 272 if len(arr) != 1 { 273 return errors.New("wrong number of structure elements") 274 } 275 276 var ( 277 index = -1 278 err error 279 ) 280 index++ 281 e.M, err = func(item stackitem.Item) (map[any]any, error) { 282 m, ok := item.Value().([]stackitem.MapElement) 283 if !ok { 284 return nil, fmt.Errorf("%s is not a map", item.Type().String()) 285 } 286 res := make(map[any]any) 287 for i := range m { 288 k, err := m[i].Key.Value(), error(nil) 289 if err != nil { 290 return nil, fmt.Errorf("key %d: %w", i, err) 291 } 292 v, err := m[i].Value.Value(), error(nil) 293 if err != nil { 294 return nil, fmt.Errorf("value %d: %w", i, err) 295 } 296 res[k] = v 297 } 298 return res, nil 299 }(arr[index]) 300 if err != nil { 301 return fmt.Errorf("field M: %w", err) 302 } 303 304 return nil 305 } 306 307 // SomeStructEventsFromApplicationLog retrieves a set of all emitted events 308 // with "SomeStruct" name from the provided [result.ApplicationLog]. 309 func SomeStructEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeStructEvent, error) { 310 if log == nil { 311 return nil, errors.New("nil application log") 312 } 313 314 var res []*SomeStructEvent 315 for i, ex := range log.Executions { 316 for j, e := range ex.Events { 317 if e.Name != "SomeStruct" { 318 continue 319 } 320 event := new(SomeStructEvent) 321 err := event.FromStackItem(e.Item) 322 if err != nil { 323 return nil, fmt.Errorf("failed to deserialize SomeStructEvent from stackitem (execution #%d, event #%d): %w", i, j, err) 324 } 325 res = append(res, event) 326 } 327 } 328 329 return res, nil 330 } 331 332 // FromStackItem converts provided [stackitem.Array] to SomeStructEvent or 333 // returns an error if it's not possible to do to so. 334 func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error { 335 if item == nil { 336 return errors.New("nil item") 337 } 338 arr, ok := item.Value().([]stackitem.Item) 339 if !ok { 340 return errors.New("not an array") 341 } 342 if len(arr) != 1 { 343 return errors.New("wrong number of structure elements") 344 } 345 346 var ( 347 index = -1 348 err error 349 ) 350 index++ 351 e.S, err = func(item stackitem.Item) ([]any, error) { 352 arr, ok := item.Value().([]stackitem.Item) 353 if !ok { 354 return nil, errors.New("not an array") 355 } 356 res := make([]any, len(arr)) 357 for i := range res { 358 res[i], err = arr[i].Value(), error(nil) 359 if err != nil { 360 return nil, fmt.Errorf("item %d: %w", i, err) 361 } 362 } 363 return res, nil 364 }(arr[index]) 365 if err != nil { 366 return fmt.Errorf("field S: %w", err) 367 } 368 369 return nil 370 } 371 372 // SomeArrayEventsFromApplicationLog retrieves a set of all emitted events 373 // with "SomeArray" name from the provided [result.ApplicationLog]. 374 func SomeArrayEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeArrayEvent, error) { 375 if log == nil { 376 return nil, errors.New("nil application log") 377 } 378 379 var res []*SomeArrayEvent 380 for i, ex := range log.Executions { 381 for j, e := range ex.Events { 382 if e.Name != "SomeArray" { 383 continue 384 } 385 event := new(SomeArrayEvent) 386 err := event.FromStackItem(e.Item) 387 if err != nil { 388 return nil, fmt.Errorf("failed to deserialize SomeArrayEvent from stackitem (execution #%d, event #%d): %w", i, j, err) 389 } 390 res = append(res, event) 391 } 392 } 393 394 return res, nil 395 } 396 397 // FromStackItem converts provided [stackitem.Array] to SomeArrayEvent or 398 // returns an error if it's not possible to do to so. 399 func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error { 400 if item == nil { 401 return errors.New("nil item") 402 } 403 arr, ok := item.Value().([]stackitem.Item) 404 if !ok { 405 return errors.New("not an array") 406 } 407 if len(arr) != 1 { 408 return errors.New("wrong number of structure elements") 409 } 410 411 var ( 412 index = -1 413 err error 414 ) 415 index++ 416 e.A, err = func(item stackitem.Item) ([]any, error) { 417 arr, ok := item.Value().([]stackitem.Item) 418 if !ok { 419 return nil, errors.New("not an array") 420 } 421 res := make([]any, len(arr)) 422 for i := range res { 423 res[i], err = arr[i].Value(), error(nil) 424 if err != nil { 425 return nil, fmt.Errorf("item %d: %w", i, err) 426 } 427 } 428 return res, nil 429 }(arr[index]) 430 if err != nil { 431 return fmt.Errorf("field A: %w", err) 432 } 433 434 return nil 435 } 436 437 // SomeUnexportedFieldEventsFromApplicationLog retrieves a set of all emitted events 438 // with "SomeUnexportedField" name from the provided [result.ApplicationLog]. 439 func SomeUnexportedFieldEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeUnexportedFieldEvent, error) { 440 if log == nil { 441 return nil, errors.New("nil application log") 442 } 443 444 var res []*SomeUnexportedFieldEvent 445 for i, ex := range log.Executions { 446 for j, e := range ex.Events { 447 if e.Name != "SomeUnexportedField" { 448 continue 449 } 450 event := new(SomeUnexportedFieldEvent) 451 err := event.FromStackItem(e.Item) 452 if err != nil { 453 return nil, fmt.Errorf("failed to deserialize SomeUnexportedFieldEvent from stackitem (execution #%d, event #%d): %w", i, j, err) 454 } 455 res = append(res, event) 456 } 457 } 458 459 return res, nil 460 } 461 462 // FromStackItem converts provided [stackitem.Array] to SomeUnexportedFieldEvent or 463 // returns an error if it's not possible to do to so. 464 func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error { 465 if item == nil { 466 return errors.New("nil item") 467 } 468 arr, ok := item.Value().([]stackitem.Item) 469 if !ok { 470 return errors.New("not an array") 471 } 472 if len(arr) != 1 { 473 return errors.New("wrong number of structure elements") 474 } 475 476 var ( 477 index = -1 478 err error 479 ) 480 index++ 481 e.S, err = func(item stackitem.Item) ([]any, error) { 482 arr, ok := item.Value().([]stackitem.Item) 483 if !ok { 484 return nil, errors.New("not an array") 485 } 486 res := make([]any, len(arr)) 487 for i := range res { 488 res[i], err = arr[i].Value(), error(nil) 489 if err != nil { 490 return nil, fmt.Errorf("item %d: %w", i, err) 491 } 492 } 493 return res, nil 494 }(arr[index]) 495 if err != nil { 496 return fmt.Errorf("field S: %w", err) 497 } 498 499 return nil 500 }