github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/cli/smartcontract/testdata/rpcbindings/notifications/rpcbindings_guessed.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 "math/big" 14 "unicode/utf8" 15 ) 16 17 // Hash contains contract hash. 18 var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x0} 19 20 // Unnamed is a contract-specific unnamed type used by its methods. 21 type Unnamed struct { 22 I *big.Int 23 B bool 24 } 25 26 // UnnamedX is a contract-specific unnamedX type used by its methods. 27 type UnnamedX struct { 28 I *big.Int 29 } 30 31 // ComplicatedNameEvent represents "! complicated name %$#" event emitted by the contract. 32 type ComplicatedNameEvent struct { 33 ComplicatedParam string 34 } 35 36 // SomeMapEvent represents "SomeMap" event emitted by the contract. 37 type SomeMapEvent struct { 38 M map[*big.Int][]map[string][]util.Uint160 39 } 40 41 // SomeStructEvent represents "SomeStruct" event emitted by the contract. 42 type SomeStructEvent struct { 43 S *Unnamed 44 } 45 46 // SomeArrayEvent represents "SomeArray" event emitted by the contract. 47 type SomeArrayEvent struct { 48 A [][]*big.Int 49 } 50 51 // SomeUnexportedFieldEvent represents "SomeUnexportedField" event emitted by the contract. 52 type SomeUnexportedFieldEvent struct { 53 S *UnnamedX 54 } 55 56 // Actor is used by Contract to call state-changing methods. 57 type Actor interface { 58 MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) 59 MakeRun(script []byte) (*transaction.Transaction, error) 60 MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) 61 MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) 62 SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) 63 SendRun(script []byte) (util.Uint256, uint32, error) 64 } 65 66 // Contract implements all contract methods. 67 type Contract struct { 68 actor Actor 69 hash util.Uint160 70 } 71 72 // New creates an instance of Contract using Hash and the given Actor. 73 func New(actor Actor) *Contract { 74 var hash = Hash 75 return &Contract{actor, hash} 76 } 77 78 // Array creates a transaction invoking `array` method of the contract. 79 // This transaction is signed and immediately sent to the network. 80 // The values returned are its hash, ValidUntilBlock value and error if any. 81 func (c *Contract) Array() (util.Uint256, uint32, error) { 82 return c.actor.SendCall(c.hash, "array") 83 } 84 85 // ArrayTransaction creates a transaction invoking `array` method of the contract. 86 // This transaction is signed, but not sent to the network, instead it's 87 // returned to the caller. 88 func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) { 89 return c.actor.MakeCall(c.hash, "array") 90 } 91 92 // ArrayUnsigned creates a transaction invoking `array` method of the contract. 93 // This transaction is not signed, it's simply returned to the caller. 94 // Any fields of it that do not affect fees can be changed (ValidUntilBlock, 95 // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. 96 func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) { 97 return c.actor.MakeUnsignedCall(c.hash, "array", nil) 98 } 99 100 // CrazyMap creates a transaction invoking `crazyMap` method of the contract. 101 // This transaction is signed and immediately sent to the network. 102 // The values returned are its hash, ValidUntilBlock value and error if any. 103 func (c *Contract) CrazyMap() (util.Uint256, uint32, error) { 104 return c.actor.SendCall(c.hash, "crazyMap") 105 } 106 107 // CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract. 108 // This transaction is signed, but not sent to the network, instead it's 109 // returned to the caller. 110 func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) { 111 return c.actor.MakeCall(c.hash, "crazyMap") 112 } 113 114 // CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract. 115 // This transaction is not signed, it's simply returned to the caller. 116 // Any fields of it that do not affect fees can be changed (ValidUntilBlock, 117 // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. 118 func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) { 119 return c.actor.MakeUnsignedCall(c.hash, "crazyMap", nil) 120 } 121 122 // Main creates a transaction invoking `main` method of the contract. 123 // This transaction is signed and immediately sent to the network. 124 // The values returned are its hash, ValidUntilBlock value and error if any. 125 func (c *Contract) Main() (util.Uint256, uint32, error) { 126 return c.actor.SendCall(c.hash, "main") 127 } 128 129 // MainTransaction creates a transaction invoking `main` method of the contract. 130 // This transaction is signed, but not sent to the network, instead it's 131 // returned to the caller. 132 func (c *Contract) MainTransaction() (*transaction.Transaction, error) { 133 return c.actor.MakeCall(c.hash, "main") 134 } 135 136 // MainUnsigned creates a transaction invoking `main` method of the contract. 137 // This transaction is not signed, it's simply returned to the caller. 138 // Any fields of it that do not affect fees can be changed (ValidUntilBlock, 139 // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. 140 func (c *Contract) MainUnsigned() (*transaction.Transaction, error) { 141 return c.actor.MakeUnsignedCall(c.hash, "main", nil) 142 } 143 144 // Struct creates a transaction invoking `struct` method of the contract. 145 // This transaction is signed and immediately sent to the network. 146 // The values returned are its hash, ValidUntilBlock value and error if any. 147 func (c *Contract) Struct() (util.Uint256, uint32, error) { 148 return c.actor.SendCall(c.hash, "struct") 149 } 150 151 // StructTransaction creates a transaction invoking `struct` method of the contract. 152 // This transaction is signed, but not sent to the network, instead it's 153 // returned to the caller. 154 func (c *Contract) StructTransaction() (*transaction.Transaction, error) { 155 return c.actor.MakeCall(c.hash, "struct") 156 } 157 158 // StructUnsigned creates a transaction invoking `struct` method of the contract. 159 // This transaction is not signed, it's simply returned to the caller. 160 // Any fields of it that do not affect fees can be changed (ValidUntilBlock, 161 // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. 162 func (c *Contract) StructUnsigned() (*transaction.Transaction, error) { 163 return c.actor.MakeUnsignedCall(c.hash, "struct", nil) 164 } 165 166 // UnexportedField creates a transaction invoking `unexportedField` method of the contract. 167 // This transaction is signed and immediately sent to the network. 168 // The values returned are its hash, ValidUntilBlock value and error if any. 169 func (c *Contract) UnexportedField() (util.Uint256, uint32, error) { 170 return c.actor.SendCall(c.hash, "unexportedField") 171 } 172 173 // UnexportedFieldTransaction creates a transaction invoking `unexportedField` method of the contract. 174 // This transaction is signed, but not sent to the network, instead it's 175 // returned to the caller. 176 func (c *Contract) UnexportedFieldTransaction() (*transaction.Transaction, error) { 177 return c.actor.MakeCall(c.hash, "unexportedField") 178 } 179 180 // UnexportedFieldUnsigned creates a transaction invoking `unexportedField` method of the contract. 181 // This transaction is not signed, it's simply returned to the caller. 182 // Any fields of it that do not affect fees can be changed (ValidUntilBlock, 183 // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. 184 func (c *Contract) UnexportedFieldUnsigned() (*transaction.Transaction, error) { 185 return c.actor.MakeUnsignedCall(c.hash, "unexportedField", nil) 186 } 187 188 // itemToUnnamed converts stack item into *Unnamed. 189 func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) { 190 if err != nil { 191 return nil, err 192 } 193 var res = new(Unnamed) 194 err = res.FromStackItem(item) 195 return res, err 196 } 197 198 // FromStackItem retrieves fields of Unnamed from the given 199 // [stackitem.Item] or returns an error if it's not possible to do to so. 200 func (res *Unnamed) FromStackItem(item stackitem.Item) error { 201 arr, ok := item.Value().([]stackitem.Item) 202 if !ok { 203 return errors.New("not an array") 204 } 205 if len(arr) != 2 { 206 return errors.New("wrong number of structure elements") 207 } 208 209 var ( 210 index = -1 211 err error 212 ) 213 index++ 214 res.I, err = arr[index].TryInteger() 215 if err != nil { 216 return fmt.Errorf("field I: %w", err) 217 } 218 219 index++ 220 res.B, err = arr[index].TryBool() 221 if err != nil { 222 return fmt.Errorf("field B: %w", err) 223 } 224 225 return nil 226 } 227 228 // itemToUnnamedX converts stack item into *UnnamedX. 229 func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) { 230 if err != nil { 231 return nil, err 232 } 233 var res = new(UnnamedX) 234 err = res.FromStackItem(item) 235 return res, err 236 } 237 238 // FromStackItem retrieves fields of UnnamedX from the given 239 // [stackitem.Item] or returns an error if it's not possible to do to so. 240 func (res *UnnamedX) FromStackItem(item stackitem.Item) error { 241 arr, ok := item.Value().([]stackitem.Item) 242 if !ok { 243 return errors.New("not an array") 244 } 245 if len(arr) != 1 { 246 return errors.New("wrong number of structure elements") 247 } 248 249 var ( 250 index = -1 251 err error 252 ) 253 index++ 254 res.I, err = arr[index].TryInteger() 255 if err != nil { 256 return fmt.Errorf("field I: %w", err) 257 } 258 259 return nil 260 } 261 262 // ComplicatedNameEventsFromApplicationLog retrieves a set of all emitted events 263 // with "! complicated name %$#" name from the provided [result.ApplicationLog]. 264 func ComplicatedNameEventsFromApplicationLog(log *result.ApplicationLog) ([]*ComplicatedNameEvent, error) { 265 if log == nil { 266 return nil, errors.New("nil application log") 267 } 268 269 var res []*ComplicatedNameEvent 270 for i, ex := range log.Executions { 271 for j, e := range ex.Events { 272 if e.Name != "! complicated name %$#" { 273 continue 274 } 275 event := new(ComplicatedNameEvent) 276 err := event.FromStackItem(e.Item) 277 if err != nil { 278 return nil, fmt.Errorf("failed to deserialize ComplicatedNameEvent from stackitem (execution #%d, event #%d): %w", i, j, err) 279 } 280 res = append(res, event) 281 } 282 } 283 284 return res, nil 285 } 286 287 // FromStackItem converts provided [stackitem.Array] to ComplicatedNameEvent or 288 // returns an error if it's not possible to do to so. 289 func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error { 290 if item == nil { 291 return errors.New("nil item") 292 } 293 arr, ok := item.Value().([]stackitem.Item) 294 if !ok { 295 return errors.New("not an array") 296 } 297 if len(arr) != 1 { 298 return errors.New("wrong number of structure elements") 299 } 300 301 var ( 302 index = -1 303 err error 304 ) 305 index++ 306 e.ComplicatedParam, err = func(item stackitem.Item) (string, error) { 307 b, err := item.TryBytes() 308 if err != nil { 309 return "", err 310 } 311 if !utf8.Valid(b) { 312 return "", errors.New("not a UTF-8 string") 313 } 314 return string(b), nil 315 }(arr[index]) 316 if err != nil { 317 return fmt.Errorf("field ComplicatedParam: %w", err) 318 } 319 320 return nil 321 } 322 323 // SomeMapEventsFromApplicationLog retrieves a set of all emitted events 324 // with "SomeMap" name from the provided [result.ApplicationLog]. 325 func SomeMapEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeMapEvent, error) { 326 if log == nil { 327 return nil, errors.New("nil application log") 328 } 329 330 var res []*SomeMapEvent 331 for i, ex := range log.Executions { 332 for j, e := range ex.Events { 333 if e.Name != "SomeMap" { 334 continue 335 } 336 event := new(SomeMapEvent) 337 err := event.FromStackItem(e.Item) 338 if err != nil { 339 return nil, fmt.Errorf("failed to deserialize SomeMapEvent from stackitem (execution #%d, event #%d): %w", i, j, err) 340 } 341 res = append(res, event) 342 } 343 } 344 345 return res, nil 346 } 347 348 // FromStackItem converts provided [stackitem.Array] to SomeMapEvent or 349 // returns an error if it's not possible to do to so. 350 func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error { 351 if item == nil { 352 return errors.New("nil item") 353 } 354 arr, ok := item.Value().([]stackitem.Item) 355 if !ok { 356 return errors.New("not an array") 357 } 358 if len(arr) != 1 { 359 return errors.New("wrong number of structure elements") 360 } 361 362 var ( 363 index = -1 364 err error 365 ) 366 index++ 367 e.M, err = func(item stackitem.Item) (map[*big.Int][]map[string][]util.Uint160, error) { 368 m, ok := item.Value().([]stackitem.MapElement) 369 if !ok { 370 return nil, fmt.Errorf("%s is not a map", item.Type().String()) 371 } 372 res := make(map[*big.Int][]map[string][]util.Uint160) 373 for i := range m { 374 k, err := m[i].Key.TryInteger() 375 if err != nil { 376 return nil, fmt.Errorf("key %d: %w", i, err) 377 } 378 v, err := func(item stackitem.Item) ([]map[string][]util.Uint160, error) { 379 arr, ok := item.Value().([]stackitem.Item) 380 if !ok { 381 return nil, errors.New("not an array") 382 } 383 res := make([]map[string][]util.Uint160, len(arr)) 384 for i := range res { 385 res[i], err = func(item stackitem.Item) (map[string][]util.Uint160, error) { 386 m, ok := item.Value().([]stackitem.MapElement) 387 if !ok { 388 return nil, fmt.Errorf("%s is not a map", item.Type().String()) 389 } 390 res := make(map[string][]util.Uint160) 391 for i := range m { 392 k, err := func(item stackitem.Item) (string, error) { 393 b, err := item.TryBytes() 394 if err != nil { 395 return "", err 396 } 397 if !utf8.Valid(b) { 398 return "", errors.New("not a UTF-8 string") 399 } 400 return string(b), nil 401 }(m[i].Key) 402 if err != nil { 403 return nil, fmt.Errorf("key %d: %w", i, err) 404 } 405 v, err := func(item stackitem.Item) ([]util.Uint160, error) { 406 arr, ok := item.Value().([]stackitem.Item) 407 if !ok { 408 return nil, errors.New("not an array") 409 } 410 res := make([]util.Uint160, len(arr)) 411 for i := range res { 412 res[i], err = func(item stackitem.Item) (util.Uint160, error) { 413 b, err := item.TryBytes() 414 if err != nil { 415 return util.Uint160{}, err 416 } 417 u, err := util.Uint160DecodeBytesBE(b) 418 if err != nil { 419 return util.Uint160{}, err 420 } 421 return u, nil 422 }(arr[i]) 423 if err != nil { 424 return nil, fmt.Errorf("item %d: %w", i, err) 425 } 426 } 427 return res, nil 428 }(m[i].Value) 429 if err != nil { 430 return nil, fmt.Errorf("value %d: %w", i, err) 431 } 432 res[k] = v 433 } 434 return res, nil 435 }(arr[i]) 436 if err != nil { 437 return nil, fmt.Errorf("item %d: %w", i, err) 438 } 439 } 440 return res, nil 441 }(m[i].Value) 442 if err != nil { 443 return nil, fmt.Errorf("value %d: %w", i, err) 444 } 445 res[k] = v 446 } 447 return res, nil 448 }(arr[index]) 449 if err != nil { 450 return fmt.Errorf("field M: %w", err) 451 } 452 453 return nil 454 } 455 456 // SomeStructEventsFromApplicationLog retrieves a set of all emitted events 457 // with "SomeStruct" name from the provided [result.ApplicationLog]. 458 func SomeStructEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeStructEvent, error) { 459 if log == nil { 460 return nil, errors.New("nil application log") 461 } 462 463 var res []*SomeStructEvent 464 for i, ex := range log.Executions { 465 for j, e := range ex.Events { 466 if e.Name != "SomeStruct" { 467 continue 468 } 469 event := new(SomeStructEvent) 470 err := event.FromStackItem(e.Item) 471 if err != nil { 472 return nil, fmt.Errorf("failed to deserialize SomeStructEvent from stackitem (execution #%d, event #%d): %w", i, j, err) 473 } 474 res = append(res, event) 475 } 476 } 477 478 return res, nil 479 } 480 481 // FromStackItem converts provided [stackitem.Array] to SomeStructEvent or 482 // returns an error if it's not possible to do to so. 483 func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error { 484 if item == nil { 485 return errors.New("nil item") 486 } 487 arr, ok := item.Value().([]stackitem.Item) 488 if !ok { 489 return errors.New("not an array") 490 } 491 if len(arr) != 1 { 492 return errors.New("wrong number of structure elements") 493 } 494 495 var ( 496 index = -1 497 err error 498 ) 499 index++ 500 e.S, err = itemToUnnamed(arr[index], nil) 501 if err != nil { 502 return fmt.Errorf("field S: %w", err) 503 } 504 505 return nil 506 } 507 508 // SomeArrayEventsFromApplicationLog retrieves a set of all emitted events 509 // with "SomeArray" name from the provided [result.ApplicationLog]. 510 func SomeArrayEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeArrayEvent, error) { 511 if log == nil { 512 return nil, errors.New("nil application log") 513 } 514 515 var res []*SomeArrayEvent 516 for i, ex := range log.Executions { 517 for j, e := range ex.Events { 518 if e.Name != "SomeArray" { 519 continue 520 } 521 event := new(SomeArrayEvent) 522 err := event.FromStackItem(e.Item) 523 if err != nil { 524 return nil, fmt.Errorf("failed to deserialize SomeArrayEvent from stackitem (execution #%d, event #%d): %w", i, j, err) 525 } 526 res = append(res, event) 527 } 528 } 529 530 return res, nil 531 } 532 533 // FromStackItem converts provided [stackitem.Array] to SomeArrayEvent or 534 // returns an error if it's not possible to do to so. 535 func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error { 536 if item == nil { 537 return errors.New("nil item") 538 } 539 arr, ok := item.Value().([]stackitem.Item) 540 if !ok { 541 return errors.New("not an array") 542 } 543 if len(arr) != 1 { 544 return errors.New("wrong number of structure elements") 545 } 546 547 var ( 548 index = -1 549 err error 550 ) 551 index++ 552 e.A, err = func(item stackitem.Item) ([][]*big.Int, error) { 553 arr, ok := item.Value().([]stackitem.Item) 554 if !ok { 555 return nil, errors.New("not an array") 556 } 557 res := make([][]*big.Int, len(arr)) 558 for i := range res { 559 res[i], err = func(item stackitem.Item) ([]*big.Int, error) { 560 arr, ok := item.Value().([]stackitem.Item) 561 if !ok { 562 return nil, errors.New("not an array") 563 } 564 res := make([]*big.Int, len(arr)) 565 for i := range res { 566 res[i], err = arr[i].TryInteger() 567 if err != nil { 568 return nil, fmt.Errorf("item %d: %w", i, err) 569 } 570 } 571 return res, nil 572 }(arr[i]) 573 if err != nil { 574 return nil, fmt.Errorf("item %d: %w", i, err) 575 } 576 } 577 return res, nil 578 }(arr[index]) 579 if err != nil { 580 return fmt.Errorf("field A: %w", err) 581 } 582 583 return nil 584 } 585 586 // SomeUnexportedFieldEventsFromApplicationLog retrieves a set of all emitted events 587 // with "SomeUnexportedField" name from the provided [result.ApplicationLog]. 588 func SomeUnexportedFieldEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeUnexportedFieldEvent, error) { 589 if log == nil { 590 return nil, errors.New("nil application log") 591 } 592 593 var res []*SomeUnexportedFieldEvent 594 for i, ex := range log.Executions { 595 for j, e := range ex.Events { 596 if e.Name != "SomeUnexportedField" { 597 continue 598 } 599 event := new(SomeUnexportedFieldEvent) 600 err := event.FromStackItem(e.Item) 601 if err != nil { 602 return nil, fmt.Errorf("failed to deserialize SomeUnexportedFieldEvent from stackitem (execution #%d, event #%d): %w", i, j, err) 603 } 604 res = append(res, event) 605 } 606 } 607 608 return res, nil 609 } 610 611 // FromStackItem converts provided [stackitem.Array] to SomeUnexportedFieldEvent or 612 // returns an error if it's not possible to do to so. 613 func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error { 614 if item == nil { 615 return errors.New("nil item") 616 } 617 arr, ok := item.Value().([]stackitem.Item) 618 if !ok { 619 return errors.New("not an array") 620 } 621 if len(arr) != 1 { 622 return errors.New("wrong number of structure elements") 623 } 624 625 var ( 626 index = -1 627 err error 628 ) 629 index++ 630 e.S, err = itemToUnnamedX(arr[index], nil) 631 if err != nil { 632 return fmt.Errorf("field S: %w", err) 633 } 634 635 return nil 636 }