github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/contract_function_parameters.go (about) 1 package hedera 2 3 /*- 4 * 5 * Hedera Go SDK 6 * 7 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 */ 22 23 import ( 24 "encoding/binary" 25 "encoding/hex" 26 "errors" 27 "fmt" 28 "math/big" 29 30 "github.com/ethereum/go-ethereum/common/math" 31 ) 32 33 // ContractFunctionParameters is a struct which builds a solidity function call 34 // Use the builder methods `Add<Type>()` to add a parameter. Not all solidity types 35 // are supported out of the box, but the most common types are. The larger variants 36 // of number types require the parameter to be `[]byte`. This is a little unintuitive, 37 // so here is an example of how to use those larger number variants using 38 // "github.com/ethereum/go-ethereum/common/math" and "math/big" 39 // ``` 40 // AddUint88(math.PaddedBigBytes(n, 88 / 8)) 41 // ``` 42 // If you're using `Uint256` specifically you can opt into using 43 // ``` 44 // AddUin256(math.PaddedBigBytes(math.U256(n), 32)) 45 // ``` 46 type ContractFunctionParameters struct { 47 function ContractFunctionSelector 48 arguments []Argument 49 } 50 51 type Argument struct { 52 value []byte 53 dynamic bool 54 } 55 56 // Builder for encoding parameters for a Solidity contract constructor/function call. 57 func NewContractFunctionParameters() *ContractFunctionParameters { 58 return &ContractFunctionParameters{ 59 function: NewContractFunctionSelector(""), 60 arguments: []Argument{}, 61 } 62 } 63 64 // AddBool adds a bool parameter to the function call 65 func (contract *ContractFunctionParameters) AddBool(value bool) *ContractFunctionParameters { 66 argument := _NewArgument() 67 68 if value { 69 argument.value[31] = 1 70 } else { 71 argument.value[31] = 0 72 } 73 74 contract.function.AddBool() 75 contract.arguments = append(contract.arguments, argument) 76 77 return contract 78 } 79 80 // AddFunction adds a Solidity function reference and a function selector. 81 func (contract *ContractFunctionParameters) AddFunction(address string, selector ContractFunctionSelector) (*ContractFunctionParameters, error) { 82 if len(address) != 40 { 83 return contract, errors.Unwrap(fmt.Errorf("address is required to be 40 characters")) 84 } 85 86 argument := _NewArgument() 87 argument.dynamic = false 88 89 addressBytes, err := hex.DecodeString(address) 90 if err != nil { 91 return contract, err 92 } 93 94 bytes := make([]byte, 12) 95 bytes = append(bytes, addressBytes[0:20]...) 96 97 function := selector._Build(nil) 98 99 bytes = append(bytes, function[0:4]...) 100 argument.value = bytes 101 102 contract.function.AddFunction() 103 contract.arguments = append(contract.arguments, argument) 104 return contract, nil 105 } 106 107 // AddInt8 adds an int8 parameter to the function call 108 func (contract *ContractFunctionParameters) AddInt8(value int8) *ContractFunctionParameters { 109 argument := _NewIntArgument(value) 110 111 argument.value[31] = uint8(value) 112 113 contract.function.AddInt8() 114 contract.arguments = append(contract.arguments, argument) 115 116 return contract 117 } 118 119 // AddInt16 adds an int16 parameter to the function call 120 func (contract *ContractFunctionParameters) AddInt16(value int16) *ContractFunctionParameters { 121 argument := _NewIntArgument(value) 122 123 binary.BigEndian.PutUint16(argument.value[30:32], uint16(value)) 124 125 contract.function.AddInt16() 126 contract.arguments = append(contract.arguments, argument) 127 128 return contract 129 } 130 131 // AddInt24 adds an int24 parameter to the function call 132 func (contract *ContractFunctionParameters) AddInt24(value int32) *ContractFunctionParameters { 133 argument := _NewIntArgument(value) 134 135 binary.BigEndian.PutUint32(argument.value[28:32], uint32(value)) 136 137 contract.function.AddInt24() 138 contract.arguments = append(contract.arguments, argument) 139 140 return contract 141 } 142 143 // AddInt32 adds an int32 parameter to the function call 144 func (contract *ContractFunctionParameters) AddInt32(value int32) *ContractFunctionParameters { 145 argument := _NewIntArgument(value) 146 147 binary.BigEndian.PutUint32(argument.value[28:32], uint32(value)) 148 149 contract.function.AddInt32() 150 contract.arguments = append(contract.arguments, argument) 151 152 return contract 153 } 154 155 // AddInt40 adds an int40 parameter to the function call 156 func (contract *ContractFunctionParameters) AddInt40(value int64) *ContractFunctionParameters { 157 argument := _NewIntArgument(value) 158 159 binary.BigEndian.PutUint64(argument.value[24:32], uint64(value)) 160 161 contract.function.AddInt40() 162 contract.arguments = append(contract.arguments, argument) 163 164 return contract 165 } 166 167 // AddInt48 adds an int48 parameter to the function call 168 func (contract *ContractFunctionParameters) AddInt48(value int64) *ContractFunctionParameters { 169 argument := _NewIntArgument(value) 170 171 binary.BigEndian.PutUint64(argument.value[24:32], uint64(value)) 172 173 contract.function.AddInt48() 174 contract.arguments = append(contract.arguments, argument) 175 176 return contract 177 } 178 179 // AddInt56 adds an int56 parameter to the function call 180 func (contract *ContractFunctionParameters) AddInt56(value int64) *ContractFunctionParameters { 181 argument := _NewIntArgument(value) 182 183 binary.BigEndian.PutUint64(argument.value[24:32], uint64(value)) 184 185 contract.function.AddInt56() 186 contract.arguments = append(contract.arguments, argument) 187 188 return contract 189 } 190 191 // AddInt64 adds an int64 parameter to the function call 192 func (contract *ContractFunctionParameters) AddInt64(value int64) *ContractFunctionParameters { 193 argument := _NewIntArgument(value) 194 195 binary.BigEndian.PutUint64(argument.value[24:32], uint64(value)) 196 197 contract.function.AddInt64() 198 contract.arguments = append(contract.arguments, argument) 199 200 return contract 201 } 202 203 // AddInt72 adds an int72 parameter to the function call 204 func (contract *ContractFunctionParameters) AddInt72(value []byte) *ContractFunctionParameters { 205 argument := _NewArgument() 206 207 argument.value = value 208 209 contract.function.AddInt72() 210 contract.arguments = append(contract.arguments, argument) 211 212 return contract 213 } 214 215 // AddInt72BigInt adds an int72parameter to the function call 216 func (contract *ContractFunctionParameters) AddInt72BigInt(value *big.Int) *ContractFunctionParameters { 217 argument := _NewArgument() 218 219 valueCopy := new(big.Int).Set(value) 220 argument.value = math.U256Bytes(valueCopy) 221 222 contract.function.AddInt72() 223 contract.arguments = append(contract.arguments, argument) 224 225 return contract 226 } 227 228 // AddInt80 adds an int80 parameter to the function call 229 func (contract *ContractFunctionParameters) AddInt80(value []byte) *ContractFunctionParameters { 230 argument := _NewArgument() 231 232 argument.value = value 233 234 contract.function.AddInt80() 235 contract.arguments = append(contract.arguments, argument) 236 237 return contract 238 } 239 240 // AddInt80igInt adds an int80parameter to the function call 241 func (contract *ContractFunctionParameters) AddInt80BigInt(value *big.Int) *ContractFunctionParameters { 242 argument := _NewArgument() 243 244 valueCopy := new(big.Int).Set(value) 245 argument.value = math.U256Bytes(valueCopy) 246 247 contract.function.AddInt80() 248 contract.arguments = append(contract.arguments, argument) 249 250 return contract 251 } 252 253 // AddInt88 adds an int88 parameter to the function call 254 func (contract *ContractFunctionParameters) AddInt88(value []byte) *ContractFunctionParameters { 255 argument := _NewArgument() 256 257 argument.value = value 258 259 contract.function.AddInt88() 260 contract.arguments = append(contract.arguments, argument) 261 262 return contract 263 } 264 265 // AddInt88BigInt adds an int88parameter to the function call 266 func (contract *ContractFunctionParameters) AddIn88BigInt(value *big.Int) *ContractFunctionParameters { 267 argument := _NewArgument() 268 269 valueCopy := new(big.Int).Set(value) 270 argument.value = math.U256Bytes(valueCopy) 271 272 contract.function.AddInt88() 273 contract.arguments = append(contract.arguments, argument) 274 275 return contract 276 } 277 278 // AddInt96 adds an int96 parameter to the function call 279 func (contract *ContractFunctionParameters) AddInt96(value []byte) *ContractFunctionParameters { 280 argument := _NewArgument() 281 282 argument.value = value 283 284 contract.function.AddInt96() 285 contract.arguments = append(contract.arguments, argument) 286 287 return contract 288 } 289 290 // AddInt96BigInt adds an int96parameter to the function call 291 func (contract *ContractFunctionParameters) AddInt96BigInt(value *big.Int) *ContractFunctionParameters { 292 argument := _NewArgument() 293 294 valueCopy := new(big.Int).Set(value) 295 argument.value = math.U256Bytes(valueCopy) 296 297 contract.function.AddInt96() 298 contract.arguments = append(contract.arguments, argument) 299 300 return contract 301 } 302 303 // AddInt104 adds an int104 parameter to the function call 304 func (contract *ContractFunctionParameters) AddInt104(value []byte) *ContractFunctionParameters { 305 argument := _NewArgument() 306 307 argument.value = value 308 309 contract.function.AddInt104() 310 contract.arguments = append(contract.arguments, argument) 311 312 return contract 313 } 314 315 // AddInt104BigInt adds an int104 parameter to the function call 316 func (contract *ContractFunctionParameters) AddInt104BigInt(value *big.Int) *ContractFunctionParameters { 317 argument := _NewArgument() 318 319 valueCopy := new(big.Int).Set(value) 320 argument.value = math.U256Bytes(valueCopy) 321 322 contract.function.AddInt104() 323 contract.arguments = append(contract.arguments, argument) 324 325 return contract 326 } 327 328 // AddInt112 adds an int112 parameter to the function call 329 func (contract *ContractFunctionParameters) AddInt112(value []byte) *ContractFunctionParameters { 330 argument := _NewArgument() 331 332 argument.value = value 333 334 contract.function.AddInt112() 335 contract.arguments = append(contract.arguments, argument) 336 337 return contract 338 } 339 340 // AddInt112BigInt adds an int112 parameter to the function call 341 func (contract *ContractFunctionParameters) AddInt112BigInt(value *big.Int) *ContractFunctionParameters { 342 argument := _NewArgument() 343 344 valueCopy := new(big.Int).Set(value) 345 argument.value = math.U256Bytes(valueCopy) 346 347 contract.function.AddInt112() 348 contract.arguments = append(contract.arguments, argument) 349 350 return contract 351 } 352 353 // AddInt120 adds an int120 parameter to the function call 354 func (contract *ContractFunctionParameters) AddInt120(value []byte) *ContractFunctionParameters { 355 argument := _NewArgument() 356 357 argument.value = value 358 359 contract.function.AddInt120() 360 contract.arguments = append(contract.arguments, argument) 361 362 return contract 363 } 364 365 // AddInt120BigInt adds an int120parameter to the function call 366 func (contract *ContractFunctionParameters) AddInt120BigInt(value *big.Int) *ContractFunctionParameters { 367 argument := _NewArgument() 368 369 valueCopy := new(big.Int).Set(value) 370 argument.value = math.U256Bytes(valueCopy) 371 372 contract.function.AddInt120() 373 contract.arguments = append(contract.arguments, argument) 374 375 return contract 376 } 377 378 // AddInt128 adds an int128 parameter to the function call 379 func (contract *ContractFunctionParameters) AddInt128(value []byte) *ContractFunctionParameters { 380 argument := _NewArgument() 381 382 argument.value = value 383 384 contract.function.AddInt128() 385 contract.arguments = append(contract.arguments, argument) 386 387 return contract 388 } 389 390 // AddInt128BigInt adds an int128parameter to the function call 391 func (contract *ContractFunctionParameters) AddInt128BigInt(value *big.Int) *ContractFunctionParameters { 392 argument := _NewArgument() 393 394 valueCopy := new(big.Int).Set(value) 395 argument.value = math.U256Bytes(valueCopy) 396 397 contract.function.AddInt128() 398 contract.arguments = append(contract.arguments, argument) 399 400 return contract 401 } 402 403 // AddInt136 adds an int136 parameter to the function call 404 func (contract *ContractFunctionParameters) AddInt136(value []byte) *ContractFunctionParameters { 405 argument := _NewArgument() 406 407 argument.value = value 408 409 contract.function.AddInt136() 410 contract.arguments = append(contract.arguments, argument) 411 412 return contract 413 } 414 415 // AddInt136BigInt adds an int136 parameter to the function call 416 func (contract *ContractFunctionParameters) AddInt136BigInt(value *big.Int) *ContractFunctionParameters { 417 argument := _NewArgument() 418 419 valueCopy := new(big.Int).Set(value) 420 argument.value = math.U256Bytes(valueCopy) 421 422 contract.function.AddInt136() 423 contract.arguments = append(contract.arguments, argument) 424 425 return contract 426 } 427 428 // AddInt144 adds an int144 parameter to the function call 429 func (contract *ContractFunctionParameters) AddInt144(value []byte) *ContractFunctionParameters { 430 argument := _NewArgument() 431 432 argument.value = value 433 434 contract.function.AddInt144() 435 contract.arguments = append(contract.arguments, argument) 436 437 return contract 438 } 439 440 // AddInt144BigInt adds an int144 parameter to the function call 441 func (contract *ContractFunctionParameters) AddInt144BigInt(value *big.Int) *ContractFunctionParameters { 442 argument := _NewArgument() 443 444 valueCopy := new(big.Int).Set(value) 445 argument.value = math.U256Bytes(valueCopy) 446 447 contract.function.AddInt144() 448 contract.arguments = append(contract.arguments, argument) 449 450 return contract 451 } 452 453 // AddInt152 adds an int152 parameter to the function call 454 func (contract *ContractFunctionParameters) AddInt152(value []byte) *ContractFunctionParameters { 455 argument := _NewArgument() 456 457 argument.value = value 458 459 contract.function.AddInt152() 460 contract.arguments = append(contract.arguments, argument) 461 462 return contract 463 } 464 465 // AddInt152BigInt adds an int152 parameter to the function call 466 func (contract *ContractFunctionParameters) AddInt152BigInt(value *big.Int) *ContractFunctionParameters { 467 argument := _NewArgument() 468 469 valueCopy := new(big.Int).Set(value) 470 argument.value = math.U256Bytes(valueCopy) 471 472 contract.function.AddInt152() 473 contract.arguments = append(contract.arguments, argument) 474 475 return contract 476 } 477 478 // AddInt160 adds an int160 parameter to the function call 479 func (contract *ContractFunctionParameters) AddInt160(value []byte) *ContractFunctionParameters { 480 argument := _NewArgument() 481 482 argument.value = value 483 484 contract.function.AddInt160() 485 contract.arguments = append(contract.arguments, argument) 486 487 return contract 488 } 489 490 // AddInt160BigInt adds an int160 parameter to the function call 491 func (contract *ContractFunctionParameters) AddInt160BigInt(value *big.Int) *ContractFunctionParameters { 492 argument := _NewArgument() 493 494 valueCopy := new(big.Int).Set(value) 495 argument.value = math.U256Bytes(valueCopy) 496 497 contract.function.AddInt160() 498 contract.arguments = append(contract.arguments, argument) 499 500 return contract 501 } 502 503 // AddInt168 adds an int168 parameter to the function call 504 func (contract *ContractFunctionParameters) AddInt168(value []byte) *ContractFunctionParameters { 505 argument := _NewArgument() 506 507 argument.value = value 508 509 contract.function.AddInt168() 510 contract.arguments = append(contract.arguments, argument) 511 512 return contract 513 } 514 515 // AddInt168BigInt adds an int168 parameter to the function call 516 func (contract *ContractFunctionParameters) AddInt168BigInt(value *big.Int) *ContractFunctionParameters { 517 argument := _NewArgument() 518 519 valueCopy := new(big.Int).Set(value) 520 argument.value = math.U256Bytes(valueCopy) 521 522 contract.function.AddInt168() 523 contract.arguments = append(contract.arguments, argument) 524 525 return contract 526 } 527 528 // AddInt176 adds an int176 parameter to the function call 529 func (contract *ContractFunctionParameters) AddInt176(value []byte) *ContractFunctionParameters { 530 argument := _NewArgument() 531 532 argument.value = value 533 534 contract.function.AddInt176() 535 contract.arguments = append(contract.arguments, argument) 536 537 return contract 538 } 539 540 // AddInt176BigInt adds an int176 parameter to the function call 541 func (contract *ContractFunctionParameters) AddInt176BigInt(value *big.Int) *ContractFunctionParameters { 542 argument := _NewArgument() 543 544 valueCopy := new(big.Int).Set(value) 545 argument.value = math.U256Bytes(valueCopy) 546 547 contract.function.AddInt176() 548 contract.arguments = append(contract.arguments, argument) 549 550 return contract 551 } 552 553 // AddInt184 adds an int184 parameter to the function call 554 func (contract *ContractFunctionParameters) AddInt184(value []byte) *ContractFunctionParameters { 555 argument := _NewArgument() 556 557 argument.value = value 558 559 contract.function.AddInt184() 560 contract.arguments = append(contract.arguments, argument) 561 562 return contract 563 } 564 565 // AddInt184BigInt adds an int184 parameter to the function call 566 func (contract *ContractFunctionParameters) AddInt184BigInt(value *big.Int) *ContractFunctionParameters { 567 argument := _NewArgument() 568 569 valueCopy := new(big.Int).Set(value) 570 argument.value = math.U256Bytes(valueCopy) 571 572 contract.function.AddInt184() 573 contract.arguments = append(contract.arguments, argument) 574 575 return contract 576 } 577 578 // AddInt192 adds an int192 parameter to the function call 579 func (contract *ContractFunctionParameters) AddInt192(value []byte) *ContractFunctionParameters { 580 argument := _NewArgument() 581 582 argument.value = value 583 584 contract.function.AddInt192() 585 contract.arguments = append(contract.arguments, argument) 586 587 return contract 588 } 589 590 // AddInt192BigInt adds an int192 parameter to the function call 591 func (contract *ContractFunctionParameters) AddInt192BigInt(value *big.Int) *ContractFunctionParameters { 592 argument := _NewArgument() 593 594 valueCopy := new(big.Int).Set(value) 595 argument.value = math.U256Bytes(valueCopy) 596 597 contract.function.AddInt192() 598 contract.arguments = append(contract.arguments, argument) 599 600 return contract 601 } 602 603 // AddInt200 adds an int200 parameter to the function call 604 func (contract *ContractFunctionParameters) AddInt200(value []byte) *ContractFunctionParameters { 605 argument := _NewArgument() 606 607 argument.value = value 608 609 contract.function.AddInt200() 610 contract.arguments = append(contract.arguments, argument) 611 612 return contract 613 } 614 615 // AddInt200BigInt adds an int200 parameter to the function call 616 func (contract *ContractFunctionParameters) AddInt200BigInt(value *big.Int) *ContractFunctionParameters { 617 argument := _NewArgument() 618 valueCopy := new(big.Int).Set(value) 619 argument.value = math.U256Bytes(valueCopy) 620 621 contract.function.AddInt200() 622 contract.arguments = append(contract.arguments, argument) 623 624 return contract 625 } 626 627 // AddInt208 adds an int208 parameter to the function call 628 func (contract *ContractFunctionParameters) AddInt208(value []byte) *ContractFunctionParameters { 629 argument := _NewArgument() 630 631 argument.value = value 632 633 contract.function.AddInt208() 634 contract.arguments = append(contract.arguments, argument) 635 636 return contract 637 } 638 639 // AddInt208BigInt adds an int208parameter to the function call 640 func (contract *ContractFunctionParameters) AddInt208BigInt(value *big.Int) *ContractFunctionParameters { 641 argument := _NewArgument() 642 643 valueCopy := new(big.Int).Set(value) 644 argument.value = math.U256Bytes(valueCopy) 645 646 contract.function.AddInt208() 647 contract.arguments = append(contract.arguments, argument) 648 649 return contract 650 } 651 652 // AddInt216 adds an int216 parameter to the function call 653 func (contract *ContractFunctionParameters) AddInt216(value []byte) *ContractFunctionParameters { 654 argument := _NewArgument() 655 656 argument.value = value 657 658 contract.function.AddInt216() 659 contract.arguments = append(contract.arguments, argument) 660 661 return contract 662 } 663 664 // AddInt216BigInt adds an int216 parameter to the function call 665 func (contract *ContractFunctionParameters) AddInt216BigInt(value *big.Int) *ContractFunctionParameters { 666 argument := _NewArgument() 667 668 valueCopy := new(big.Int).Set(value) 669 argument.value = math.U256Bytes(valueCopy) 670 671 contract.function.AddInt216() 672 contract.arguments = append(contract.arguments, argument) 673 674 return contract 675 } 676 677 // AddInt224 adds an int224 parameter to the function call 678 func (contract *ContractFunctionParameters) AddInt224(value []byte) *ContractFunctionParameters { 679 argument := _NewArgument() 680 681 argument.value = value 682 683 contract.function.AddInt224() 684 contract.arguments = append(contract.arguments, argument) 685 686 return contract 687 } 688 689 // AddInt224BigInt adds an int224 parameter to the function call 690 func (contract *ContractFunctionParameters) AddInt224BigInt(value *big.Int) *ContractFunctionParameters { 691 argument := _NewArgument() 692 693 valueCopy := new(big.Int).Set(value) 694 argument.value = math.U256Bytes(valueCopy) 695 696 contract.function.AddInt224() 697 contract.arguments = append(contract.arguments, argument) 698 699 return contract 700 } 701 702 // AddInt232 adds an int232 parameter to the function call 703 func (contract *ContractFunctionParameters) AddInt232(value []byte) *ContractFunctionParameters { 704 argument := _NewArgument() 705 706 argument.value = value 707 708 contract.function.AddInt232() 709 contract.arguments = append(contract.arguments, argument) 710 711 return contract 712 } 713 714 // AddInt232BigInt adds an int232 parameter to the function call 715 func (contract *ContractFunctionParameters) AddInt232BigInt(value *big.Int) *ContractFunctionParameters { 716 argument := _NewArgument() 717 718 valueCopy := new(big.Int).Set(value) 719 argument.value = math.U256Bytes(valueCopy) 720 721 contract.function.AddInt232() 722 contract.arguments = append(contract.arguments, argument) 723 724 return contract 725 } 726 727 // AddInt240 adds an int240 parameter to the function call 728 func (contract *ContractFunctionParameters) AddInt240(value []byte) *ContractFunctionParameters { 729 argument := _NewArgument() 730 731 argument.value = value 732 733 contract.function.AddInt240() 734 contract.arguments = append(contract.arguments, argument) 735 736 return contract 737 } 738 739 // AddInt240BigInt adds an int240 parameter to the function call 740 func (contract *ContractFunctionParameters) AddInt240BigInt(value *big.Int) *ContractFunctionParameters { 741 argument := _NewArgument() 742 743 valueCopy := new(big.Int).Set(value) 744 argument.value = math.U256Bytes(valueCopy) 745 746 contract.function.AddInt240() 747 contract.arguments = append(contract.arguments, argument) 748 749 return contract 750 } 751 752 // AddInt248 adds an int248 parameter to the function call 753 func (contract *ContractFunctionParameters) AddInt248(value []byte) *ContractFunctionParameters { 754 argument := _NewArgument() 755 756 argument.value = value 757 758 contract.function.AddInt248() 759 contract.arguments = append(contract.arguments, argument) 760 761 return contract 762 } 763 764 // AddInt248BigInt adds an int248 parameter to the function call 765 func (contract *ContractFunctionParameters) AddInt248BigInt(value *big.Int) *ContractFunctionParameters { 766 argument := _NewArgument() 767 768 valueCopy := new(big.Int).Set(value) 769 argument.value = math.U256Bytes(valueCopy) 770 771 contract.function.AddInt248() 772 contract.arguments = append(contract.arguments, argument) 773 774 return contract 775 } 776 777 // AddInt256 adds an int256 parameter to the function call 778 func (contract *ContractFunctionParameters) AddInt256(value []byte) *ContractFunctionParameters { 779 argument := _NewArgument() 780 781 argument.value = value 782 783 contract.function.AddInt256() 784 contract.arguments = append(contract.arguments, argument) 785 786 return contract 787 } 788 789 // AddInt256BigInt adds an int256 parameter to the function call 790 func (contract *ContractFunctionParameters) AddInt256BigInt(value *big.Int) *ContractFunctionParameters { 791 argument := _NewArgument() 792 793 valueCopy := new(big.Int).Set(value) 794 argument.value = math.U256Bytes(valueCopy) 795 796 contract.function.AddInt256() 797 contract.arguments = append(contract.arguments, argument) 798 799 return contract 800 } 801 802 // AddUint8 adds a uint8 parameter to the function call 803 func (contract *ContractFunctionParameters) AddUint8(value uint8) *ContractFunctionParameters { 804 argument := _NewArgument() 805 806 argument.value[31] = value 807 808 contract.function.AddUint8() 809 contract.arguments = append(contract.arguments, argument) 810 811 return contract 812 } 813 814 // AddUint16 adds a uint16 parameter to the function call 815 func (contract *ContractFunctionParameters) AddUint16(value uint16) *ContractFunctionParameters { 816 argument := _NewArgument() 817 818 binary.BigEndian.PutUint16(argument.value[30:32], value) 819 820 contract.function.AddUint16() 821 contract.arguments = append(contract.arguments, argument) 822 823 return contract 824 } 825 826 // AddUint24 adds a uint24 parameter to the function call 827 func (contract *ContractFunctionParameters) AddUint24(value uint32) *ContractFunctionParameters { 828 argument := _NewArgument() 829 830 binary.BigEndian.PutUint32(argument.value[28:32], value) 831 832 contract.function.AddUint24() 833 contract.arguments = append(contract.arguments, argument) 834 835 return contract 836 } 837 838 // AddUint32 adds a uint32 parameter to the function call 839 func (contract *ContractFunctionParameters) AddUint32(value uint32) *ContractFunctionParameters { 840 argument := _NewArgument() 841 842 binary.BigEndian.PutUint32(argument.value[28:32], value) 843 844 contract.function.AddUint32() 845 contract.arguments = append(contract.arguments, argument) 846 847 return contract 848 } 849 850 // AddUint40 adds a uint40 parameter to the function call 851 func (contract *ContractFunctionParameters) AddUint40(value uint64) *ContractFunctionParameters { 852 argument := _NewArgument() 853 854 binary.BigEndian.PutUint64(argument.value[24:32], value) 855 856 contract.function.AddUint40() 857 contract.arguments = append(contract.arguments, argument) 858 859 return contract 860 } 861 862 // AddUint48 adds a uint48 parameter to the function call 863 func (contract *ContractFunctionParameters) AddUint48(value uint64) *ContractFunctionParameters { 864 argument := _NewArgument() 865 866 binary.BigEndian.PutUint64(argument.value[24:32], value) 867 868 contract.function.AddUint48() 869 contract.arguments = append(contract.arguments, argument) 870 871 return contract 872 } 873 874 // AddUint56 adds a uint56 parameter to the function call 875 func (contract *ContractFunctionParameters) AddUint56(value uint64) *ContractFunctionParameters { 876 argument := _NewArgument() 877 878 binary.BigEndian.PutUint64(argument.value[24:32], value) 879 880 contract.function.AddUint56() 881 contract.arguments = append(contract.arguments, argument) 882 883 return contract 884 } 885 886 // AddUint64 adds a uint64 parameter to the function call 887 func (contract *ContractFunctionParameters) AddUint64(value uint64) *ContractFunctionParameters { 888 argument := _NewArgument() 889 890 binary.BigEndian.PutUint64(argument.value[24:32], value) 891 892 contract.function.AddUint64() 893 contract.arguments = append(contract.arguments, argument) 894 895 return contract 896 } 897 898 // AddUint72 adds a uint72 parameter to the function call 899 func (contract *ContractFunctionParameters) AddUint72(value []byte) *ContractFunctionParameters { 900 argument := _NewArgument() 901 902 argument.value = value 903 904 contract.function.AddUint72() 905 contract.arguments = append(contract.arguments, argument) 906 907 return contract 908 } 909 910 // AddUint72BigInt adds a uint72 parameter to the function call 911 func (contract *ContractFunctionParameters) AddUint72BigInt(value *big.Int) *ContractFunctionParameters { 912 argument := _NewArgument() 913 914 valueCopy := new(big.Int).Set(value) 915 argument.value = math.U256Bytes(valueCopy) 916 917 contract.function.AddUint72() 918 contract.arguments = append(contract.arguments, argument) 919 920 return contract 921 } 922 923 // AddUint80 adds a uint80 parameter to the function call 924 func (contract *ContractFunctionParameters) AddUint80(value []byte) *ContractFunctionParameters { 925 argument := _NewArgument() 926 927 argument.value = value 928 929 contract.function.AddUint80() 930 contract.arguments = append(contract.arguments, argument) 931 932 return contract 933 } 934 935 // AddUint80BigInt adds a uint80parameter to the function call 936 func (contract *ContractFunctionParameters) AddUint80BigInt(value *big.Int) *ContractFunctionParameters { 937 argument := _NewArgument() 938 939 valueCopy := new(big.Int).Set(value) 940 argument.value = math.U256Bytes(valueCopy) 941 942 contract.function.AddUint80() 943 contract.arguments = append(contract.arguments, argument) 944 945 return contract 946 } 947 948 // AddUint88 adds a uint88 parameter to the function call 949 func (contract *ContractFunctionParameters) AddUint88(value []byte) *ContractFunctionParameters { 950 argument := _NewArgument() 951 952 argument.value = value 953 954 contract.function.AddUint88() 955 contract.arguments = append(contract.arguments, argument) 956 957 return contract 958 } 959 960 // AddUint88BigInt adds a uint88parameter to the function call 961 func (contract *ContractFunctionParameters) AddUint88BigInt(value *big.Int) *ContractFunctionParameters { 962 argument := _NewArgument() 963 964 valueCopy := new(big.Int).Set(value) 965 argument.value = math.U256Bytes(valueCopy) 966 967 contract.function.AddUint88() 968 contract.arguments = append(contract.arguments, argument) 969 970 return contract 971 } 972 973 // AddUint96 adds a uint96 parameter to the function call 974 func (contract *ContractFunctionParameters) AddUint96(value []byte) *ContractFunctionParameters { 975 argument := _NewArgument() 976 977 argument.value = value 978 979 contract.function.AddUint96() 980 contract.arguments = append(contract.arguments, argument) 981 982 return contract 983 } 984 985 // AddUint96BigInt adds a uint96parameter to the function call 986 func (contract *ContractFunctionParameters) AddUint96BigInt(value *big.Int) *ContractFunctionParameters { 987 argument := _NewArgument() 988 989 valueCopy := new(big.Int).Set(value) 990 argument.value = math.U256Bytes(valueCopy) 991 992 contract.function.AddUint96() 993 contract.arguments = append(contract.arguments, argument) 994 995 return contract 996 } 997 998 // AddUint104 adds a uint104 parameter to the function call 999 func (contract *ContractFunctionParameters) AddUint104(value []byte) *ContractFunctionParameters { 1000 argument := _NewArgument() 1001 1002 argument.value = value 1003 1004 contract.function.AddUint104() 1005 contract.arguments = append(contract.arguments, argument) 1006 1007 return contract 1008 } 1009 1010 // AddUint104BigInt adds a uint104 parameter to the function call 1011 func (contract *ContractFunctionParameters) AddUint104igInt(value *big.Int) *ContractFunctionParameters { 1012 argument := _NewArgument() 1013 1014 valueCopy := new(big.Int).Set(value) 1015 argument.value = math.U256Bytes(valueCopy) 1016 1017 contract.function.AddUint104() 1018 contract.arguments = append(contract.arguments, argument) 1019 1020 return contract 1021 } 1022 1023 // AddUint112 adds a uint112 parameter to the function call 1024 func (contract *ContractFunctionParameters) AddUint112(value []byte) *ContractFunctionParameters { 1025 argument := _NewArgument() 1026 1027 argument.value = value 1028 1029 contract.function.AddUint112() 1030 contract.arguments = append(contract.arguments, argument) 1031 1032 return contract 1033 } 1034 1035 // AddUint112BigInt adds a uint112 parameter to the function call 1036 func (contract *ContractFunctionParameters) AddUint112BigInt(value *big.Int) *ContractFunctionParameters { 1037 argument := _NewArgument() 1038 1039 valueCopy := new(big.Int).Set(value) 1040 argument.value = math.U256Bytes(valueCopy) 1041 1042 contract.function.AddUint112() 1043 contract.arguments = append(contract.arguments, argument) 1044 1045 return contract 1046 } 1047 1048 // AddUint120 adds a uint120 parameter to the function call 1049 func (contract *ContractFunctionParameters) AddUint120(value []byte) *ContractFunctionParameters { 1050 argument := _NewArgument() 1051 1052 argument.value = value 1053 1054 contract.function.AddUint120() 1055 contract.arguments = append(contract.arguments, argument) 1056 1057 return contract 1058 } 1059 1060 // AddUint120BigInt adds a uint120 parameter to the function call 1061 func (contract *ContractFunctionParameters) AddUint120BigInt(value *big.Int) *ContractFunctionParameters { 1062 argument := _NewArgument() 1063 1064 valueCopy := new(big.Int).Set(value) 1065 argument.value = math.U256Bytes(valueCopy) 1066 1067 contract.function.AddUint120() 1068 contract.arguments = append(contract.arguments, argument) 1069 1070 return contract 1071 } 1072 1073 // AddUint128 adds a uint128 parameter to the function call 1074 func (contract *ContractFunctionParameters) AddUint128(value []byte) *ContractFunctionParameters { 1075 argument := _NewArgument() 1076 1077 argument.value = value 1078 1079 contract.function.AddUint128() 1080 contract.arguments = append(contract.arguments, argument) 1081 1082 return contract 1083 } 1084 1085 // AddUint128BigInt adds a uint128 parameter to the function call 1086 func (contract *ContractFunctionParameters) AddUint128BigInt(value *big.Int) *ContractFunctionParameters { 1087 argument := _NewArgument() 1088 1089 valueCopy := new(big.Int).Set(value) 1090 argument.value = math.U256Bytes(valueCopy) 1091 1092 contract.function.AddUint128() 1093 contract.arguments = append(contract.arguments, argument) 1094 1095 return contract 1096 } 1097 1098 // AddUint136 adds a uint136 parameter to the function call 1099 func (contract *ContractFunctionParameters) AddUint136(value []byte) *ContractFunctionParameters { 1100 argument := _NewArgument() 1101 1102 argument.value = value 1103 1104 contract.function.AddUint136() 1105 contract.arguments = append(contract.arguments, argument) 1106 1107 return contract 1108 } 1109 1110 // AddUint136BigInt adds a uint136 parameter to the function call 1111 func (contract *ContractFunctionParameters) AddUint136BigInt(value *big.Int) *ContractFunctionParameters { 1112 argument := _NewArgument() 1113 1114 valueCopy := new(big.Int).Set(value) 1115 argument.value = math.U256Bytes(valueCopy) 1116 1117 contract.function.AddUint136() 1118 contract.arguments = append(contract.arguments, argument) 1119 1120 return contract 1121 } 1122 1123 // AddUint144 adds a uint144 parameter to the function call 1124 func (contract *ContractFunctionParameters) AddUint144(value []byte) *ContractFunctionParameters { 1125 argument := _NewArgument() 1126 1127 argument.value = value 1128 1129 contract.function.AddUint144() 1130 contract.arguments = append(contract.arguments, argument) 1131 1132 return contract 1133 } 1134 1135 // AddUint144BigInt adds a uint144 parameter to the function call 1136 func (contract *ContractFunctionParameters) AddUint144BigInt(value *big.Int) *ContractFunctionParameters { 1137 argument := _NewArgument() 1138 1139 valueCopy := new(big.Int).Set(value) 1140 argument.value = math.U256Bytes(valueCopy) 1141 1142 contract.function.AddUint144() 1143 contract.arguments = append(contract.arguments, argument) 1144 1145 return contract 1146 } 1147 1148 // AddUint152 adds a uint152 parameter to the function call 1149 func (contract *ContractFunctionParameters) AddUint152(value []byte) *ContractFunctionParameters { 1150 argument := _NewArgument() 1151 1152 argument.value = value 1153 1154 contract.function.AddUint152() 1155 contract.arguments = append(contract.arguments, argument) 1156 1157 return contract 1158 } 1159 1160 // AddUint152BigInt adds a uint152 parameter to the function call 1161 func (contract *ContractFunctionParameters) AddUint152BigInt(value *big.Int) *ContractFunctionParameters { 1162 argument := _NewArgument() 1163 1164 valueCopy := new(big.Int).Set(value) 1165 argument.value = math.U256Bytes(valueCopy) 1166 1167 contract.function.AddUint152() 1168 contract.arguments = append(contract.arguments, argument) 1169 1170 return contract 1171 } 1172 1173 // AddUint160 adds a uint160 parameter to the function call 1174 func (contract *ContractFunctionParameters) AddUint160(value []byte) *ContractFunctionParameters { 1175 argument := _NewArgument() 1176 1177 argument.value = value 1178 1179 contract.function.AddUint160() 1180 contract.arguments = append(contract.arguments, argument) 1181 1182 return contract 1183 } 1184 1185 // AddUint160BigInt adds a uint160 parameter to the function call 1186 func (contract *ContractFunctionParameters) AddUint160BigInt(value *big.Int) *ContractFunctionParameters { 1187 argument := _NewArgument() 1188 1189 valueCopy := new(big.Int).Set(value) 1190 argument.value = math.U256Bytes(valueCopy) 1191 1192 contract.function.AddUint160() 1193 contract.arguments = append(contract.arguments, argument) 1194 1195 return contract 1196 } 1197 1198 // AddUint168 adds a uint168 parameter to the function call 1199 func (contract *ContractFunctionParameters) AddUint168(value []byte) *ContractFunctionParameters { 1200 argument := _NewArgument() 1201 1202 argument.value = value 1203 1204 contract.function.AddUint168() 1205 contract.arguments = append(contract.arguments, argument) 1206 1207 return contract 1208 } 1209 1210 // AddUint168BigInt adds a uint168 parameter to the function call 1211 func (contract *ContractFunctionParameters) AddUint168BigInt(value *big.Int) *ContractFunctionParameters { 1212 argument := _NewArgument() 1213 1214 valueCopy := new(big.Int).Set(value) 1215 argument.value = math.U256Bytes(valueCopy) 1216 1217 contract.function.AddUint168() 1218 contract.arguments = append(contract.arguments, argument) 1219 1220 return contract 1221 } 1222 1223 // AddUint176 adds a uint176 parameter to the function call 1224 func (contract *ContractFunctionParameters) AddUint176(value []byte) *ContractFunctionParameters { 1225 argument := _NewArgument() 1226 1227 argument.value = value 1228 1229 contract.function.AddUint176() 1230 contract.arguments = append(contract.arguments, argument) 1231 1232 return contract 1233 } 1234 1235 // AddUint176BigInt adds a uint176 parameter to the function call 1236 func (contract *ContractFunctionParameters) AddUint176BigInt(value *big.Int) *ContractFunctionParameters { 1237 argument := _NewArgument() 1238 1239 valueCopy := new(big.Int).Set(value) 1240 argument.value = math.U256Bytes(valueCopy) 1241 1242 contract.function.AddUint176() 1243 contract.arguments = append(contract.arguments, argument) 1244 1245 return contract 1246 } 1247 1248 // AddUint184 adds a uint184 parameter to the function call 1249 func (contract *ContractFunctionParameters) AddUint184(value []byte) *ContractFunctionParameters { 1250 argument := _NewArgument() 1251 1252 argument.value = value 1253 1254 contract.function.AddUint184() 1255 contract.arguments = append(contract.arguments, argument) 1256 1257 return contract 1258 } 1259 1260 // AddUint184BigInt adds a uint184 parameter to the function call 1261 func (contract *ContractFunctionParameters) AddUint184BigInt(value *big.Int) *ContractFunctionParameters { 1262 argument := _NewArgument() 1263 1264 valueCopy := new(big.Int).Set(value) 1265 argument.value = math.U256Bytes(valueCopy) 1266 1267 contract.function.AddUint184() 1268 contract.arguments = append(contract.arguments, argument) 1269 1270 return contract 1271 } 1272 1273 // AddUint192 adds a uint192 parameter to the function call 1274 func (contract *ContractFunctionParameters) AddUint192(value []byte) *ContractFunctionParameters { 1275 argument := _NewArgument() 1276 1277 argument.value = value 1278 1279 contract.function.AddUint192() 1280 contract.arguments = append(contract.arguments, argument) 1281 1282 return contract 1283 } 1284 1285 // AddUint192BigInt adds a uint192 parameter to the function call 1286 func (contract *ContractFunctionParameters) AddUint192BigInt(value *big.Int) *ContractFunctionParameters { 1287 argument := _NewArgument() 1288 1289 valueCopy := new(big.Int).Set(value) 1290 argument.value = math.U256Bytes(valueCopy) 1291 1292 contract.function.AddUint192() 1293 contract.arguments = append(contract.arguments, argument) 1294 1295 return contract 1296 } 1297 1298 // AddUint200 adds a uint200 parameter to the function call 1299 func (contract *ContractFunctionParameters) AddUint200(value []byte) *ContractFunctionParameters { 1300 argument := _NewArgument() 1301 1302 argument.value = value 1303 1304 contract.function.AddUint200() 1305 contract.arguments = append(contract.arguments, argument) 1306 1307 return contract 1308 } 1309 1310 // AddUint200BigInt adds a uint200 parameter to the function call 1311 func (contract *ContractFunctionParameters) AddUint200BigInt(value *big.Int) *ContractFunctionParameters { 1312 argument := _NewArgument() 1313 1314 valueCopy := new(big.Int).Set(value) 1315 argument.value = math.U256Bytes(valueCopy) 1316 1317 contract.function.AddUint200() 1318 contract.arguments = append(contract.arguments, argument) 1319 1320 return contract 1321 } 1322 1323 // AddUint208 adds a uint208 parameter to the function call 1324 func (contract *ContractFunctionParameters) AddUint208(value []byte) *ContractFunctionParameters { 1325 argument := _NewArgument() 1326 1327 argument.value = value 1328 1329 contract.function.AddUint208() 1330 contract.arguments = append(contract.arguments, argument) 1331 1332 return contract 1333 } 1334 1335 // AddUint208BigInt adds a uint208 parameter to the function call 1336 func (contract *ContractFunctionParameters) AddUint208BigInt(value *big.Int) *ContractFunctionParameters { 1337 argument := _NewArgument() 1338 1339 valueCopy := new(big.Int).Set(value) 1340 argument.value = math.U256Bytes(valueCopy) 1341 1342 contract.function.AddUint208() 1343 contract.arguments = append(contract.arguments, argument) 1344 1345 return contract 1346 } 1347 1348 // AddUint216 adds a uint216 parameter to the function call 1349 func (contract *ContractFunctionParameters) AddUint216(value []byte) *ContractFunctionParameters { 1350 argument := _NewArgument() 1351 1352 argument.value = value 1353 1354 contract.function.AddUint216() 1355 contract.arguments = append(contract.arguments, argument) 1356 1357 return contract 1358 } 1359 1360 // AddUint216BigInt adds a uint216 parameter to the function call 1361 func (contract *ContractFunctionParameters) AddUint216BigInt(value *big.Int) *ContractFunctionParameters { 1362 argument := _NewArgument() 1363 1364 valueCopy := new(big.Int).Set(value) 1365 argument.value = math.U256Bytes(valueCopy) 1366 1367 contract.function.AddUint216() 1368 contract.arguments = append(contract.arguments, argument) 1369 1370 return contract 1371 } 1372 1373 // AddUint224 adds a uint224 parameter to the function call 1374 func (contract *ContractFunctionParameters) AddUint224(value []byte) *ContractFunctionParameters { 1375 argument := _NewArgument() 1376 1377 argument.value = value 1378 1379 contract.function.AddUint224() 1380 contract.arguments = append(contract.arguments, argument) 1381 1382 return contract 1383 } 1384 1385 // AddUint224BigInt adds a uint224 parameter to the function call 1386 func (contract *ContractFunctionParameters) AddUint224BigInt(value *big.Int) *ContractFunctionParameters { 1387 argument := _NewArgument() 1388 1389 valueCopy := new(big.Int).Set(value) 1390 argument.value = math.U256Bytes(valueCopy) 1391 1392 contract.function.AddUint224() 1393 contract.arguments = append(contract.arguments, argument) 1394 1395 return contract 1396 } 1397 1398 // AddUint232 adds a uint232 parameter to the function call 1399 func (contract *ContractFunctionParameters) AddUint232(value []byte) *ContractFunctionParameters { 1400 argument := _NewArgument() 1401 1402 argument.value = value 1403 1404 contract.function.AddUint232() 1405 contract.arguments = append(contract.arguments, argument) 1406 1407 return contract 1408 } 1409 1410 // AddUint232BigInt adds a uint232 parameter to the function call 1411 func (contract *ContractFunctionParameters) AddUint232BigInt(value *big.Int) *ContractFunctionParameters { 1412 argument := _NewArgument() 1413 1414 valueCopy := new(big.Int).Set(value) 1415 argument.value = math.U256Bytes(valueCopy) 1416 1417 contract.function.AddUint232() 1418 contract.arguments = append(contract.arguments, argument) 1419 1420 return contract 1421 } 1422 1423 // AddUint240 adds a uint240 parameter to the function call 1424 func (contract *ContractFunctionParameters) AddUint240(value []byte) *ContractFunctionParameters { 1425 argument := _NewArgument() 1426 1427 argument.value = value 1428 1429 contract.function.AddUint240() 1430 contract.arguments = append(contract.arguments, argument) 1431 1432 return contract 1433 } 1434 1435 // AddUint240BigInt adds a uint240 parameter to the function call 1436 func (contract *ContractFunctionParameters) AddUint240BigInt(value *big.Int) *ContractFunctionParameters { 1437 argument := _NewArgument() 1438 1439 valueCopy := new(big.Int).Set(value) 1440 argument.value = math.U256Bytes(valueCopy) 1441 1442 contract.function.AddUint240() 1443 contract.arguments = append(contract.arguments, argument) 1444 1445 return contract 1446 } 1447 1448 // AddUint248 adds a uint248 parameter to the function call 1449 func (contract *ContractFunctionParameters) AddUint248(value []byte) *ContractFunctionParameters { 1450 argument := _NewArgument() 1451 1452 argument.value = value 1453 1454 contract.function.AddUint248() 1455 contract.arguments = append(contract.arguments, argument) 1456 1457 return contract 1458 } 1459 1460 // AddUint248BigInt adds a uint248 parameter to the function call 1461 func (contract *ContractFunctionParameters) AddUint248BigInt(value *big.Int) *ContractFunctionParameters { 1462 argument := _NewArgument() 1463 1464 valueCopy := new(big.Int).Set(value) 1465 argument.value = math.U256Bytes(valueCopy) 1466 1467 contract.function.AddUint248() 1468 contract.arguments = append(contract.arguments, argument) 1469 1470 return contract 1471 } 1472 1473 // AddUint256 adds a uint256 parameter to the function call 1474 func (contract *ContractFunctionParameters) AddUint256(value []byte) *ContractFunctionParameters { 1475 argument := _NewArgument() 1476 1477 argument.value = value 1478 1479 contract.function.AddUint256() 1480 contract.arguments = append(contract.arguments, argument) 1481 1482 return contract 1483 } 1484 1485 // AddUint256BigInt adds a uint256 parameter to the function call 1486 func (contract *ContractFunctionParameters) AddUint256BigInt(value *big.Int) *ContractFunctionParameters { 1487 argument := _NewArgument() 1488 1489 valueCopy := new(big.Int).Set(value) 1490 argument.value = math.U256Bytes(valueCopy) 1491 1492 contract.function.AddUint256() 1493 contract.arguments = append(contract.arguments, argument) 1494 1495 return contract 1496 } 1497 1498 // AddInt8Array adds an int8 array parameter to the function call 1499 func (contract *ContractFunctionParameters) AddInt8Array(value []int8) *ContractFunctionParameters { 1500 argument := _NewArgument() 1501 argument.dynamic = true 1502 1503 result := make([]byte, len(value)*32+32) 1504 1505 binary.BigEndian.PutUint64(result[24:32], uint64(len(value))) 1506 1507 for i, v := range value { 1508 binary.BigEndian.PutUint32(result[i*32+32+28:i*32+32+32], uint32(v)) 1509 } 1510 1511 argument.value = result 1512 1513 contract.function.AddInt32Array() 1514 contract.arguments = append(contract.arguments, argument) 1515 return contract 1516 } 1517 1518 // AddInt16Array adds an int16 array parameter to the function call 1519 func (contract *ContractFunctionParameters) AddInt16Array(value []int16) *ContractFunctionParameters { 1520 argument := _NewArgument() 1521 argument.dynamic = true 1522 1523 result := make([]byte, len(value)*32+32) 1524 1525 binary.BigEndian.PutUint64(result[24:32], uint64(len(value))) 1526 1527 for i, v := range value { 1528 binary.BigEndian.PutUint32(result[i*32+32+28:i*32+32+32], uint32(v)) 1529 } 1530 1531 argument.value = result 1532 1533 contract.function.AddInt32Array() 1534 contract.arguments = append(contract.arguments, argument) 1535 return contract 1536 } 1537 1538 // AddInt24Array adds an int24 array parameter to the function call 1539 func (contract *ContractFunctionParameters) AddInt24Array(value []int32) *ContractFunctionParameters { 1540 argument := _NewArgument() 1541 argument.dynamic = true 1542 1543 result := make([]byte, len(value)*32+32) 1544 1545 binary.BigEndian.PutUint64(result[24:32], uint64(len(value))) 1546 1547 for i, v := range value { 1548 binary.BigEndian.PutUint32(result[i*32+32+28:i*32+32+32], uint32(v)) 1549 } 1550 1551 argument.value = result 1552 1553 contract.function.AddInt32Array() 1554 contract.arguments = append(contract.arguments, argument) 1555 return contract 1556 } 1557 1558 // AddInt32Array adds an int32 array parameter to the function call 1559 func (contract *ContractFunctionParameters) AddInt32Array(value []int32) *ContractFunctionParameters { 1560 argument := _NewArgument() 1561 argument.dynamic = true 1562 1563 result := make([]byte, len(value)+32) 1564 1565 binary.BigEndian.PutUint64(result[24:32], uint64(len(value))) 1566 1567 for i, v := range value { 1568 binary.BigEndian.PutUint32(result[i*32+32+28:i*32+32+32], uint32(v)) 1569 } 1570 1571 argument.value = result 1572 1573 contract.function.AddInt32Array() 1574 contract.arguments = append(contract.arguments, argument) 1575 return contract 1576 } 1577 1578 // AddInt64Array adds an int64 array parameter to the function call 1579 func (contract *ContractFunctionParameters) AddInt64Array(value []int64) *ContractFunctionParameters { 1580 argument := _NewArgument() 1581 argument.dynamic = true 1582 1583 result := make([]byte, len(value)*32+32) 1584 1585 binary.BigEndian.PutUint64(result[24:32], uint64(len(value))) 1586 1587 for i, v := range value { 1588 binary.BigEndian.PutUint64(result[i*32+32+24:i*32+32+32], uint64(v)) 1589 } 1590 1591 argument.value = result 1592 1593 contract.function.AddInt64Array() 1594 contract.arguments = append(contract.arguments, argument) 1595 return contract 1596 } 1597 1598 // AddInt256Array adds an int256 array parameter to the function call 1599 func (contract *ContractFunctionParameters) AddInt256Array(value [][32]byte) *ContractFunctionParameters { 1600 argument := _NewArgument() 1601 argument.dynamic = true 1602 1603 result := make([]byte, len(value)*32+32) 1604 1605 binary.BigEndian.PutUint64(result[24:32], uint64(len(value))) 1606 1607 for i, v := range value { 1608 copy(result[i*32+32:i*32+32+32], v[0:32]) 1609 } 1610 1611 argument.value = result 1612 1613 contract.function.AddInt256Array() 1614 contract.arguments = append(contract.arguments, argument) 1615 return contract 1616 } 1617 1618 // AddUint32Array adds a uint32 array parameter to the function call 1619 func (contract *ContractFunctionParameters) AddUint32Array(value []uint32) *ContractFunctionParameters { 1620 argument := _NewArgument() 1621 argument.dynamic = true 1622 1623 result := make([]byte, len(value)*32+32) 1624 1625 binary.BigEndian.PutUint64(result[24:32], uint64(len(value))) 1626 1627 for i, v := range value { 1628 binary.BigEndian.PutUint32(result[i*32+32+28:i*32+32+32], v) 1629 } 1630 1631 argument.value = result 1632 1633 contract.function.AddUint32Array() 1634 contract.arguments = append(contract.arguments, argument) 1635 return contract 1636 } 1637 1638 // AddUint64Array adds a uint64 array parameter to the function call 1639 func (contract *ContractFunctionParameters) AddUint64Array(value []uint64) *ContractFunctionParameters { 1640 argument := _NewArgument() 1641 argument.dynamic = true 1642 1643 result := make([]byte, len(value)*32+32) 1644 1645 binary.BigEndian.PutUint64(result[24:32], uint64(len(value))) 1646 1647 for i, v := range value { 1648 binary.BigEndian.PutUint64(result[i*32+32+24:i*32+32+32], v) 1649 } 1650 1651 argument.value = result 1652 1653 contract.function.AddUint64Array() 1654 contract.arguments = append(contract.arguments, argument) 1655 return contract 1656 } 1657 1658 // AddUint256Array adds a uint256 array parameter to the function call 1659 func (contract *ContractFunctionParameters) AddUint256Array(value [][32]byte) *ContractFunctionParameters { 1660 argument := _NewArgument() 1661 argument.dynamic = true 1662 1663 result := make([]byte, len(value)*32+32) 1664 1665 binary.BigEndian.PutUint64(result[24:32], uint64(len(value))) 1666 1667 for i, v := range value { 1668 copy(result[i*32+32:i*32+32+32], v[0:32]) 1669 } 1670 1671 argument.value = result 1672 1673 contract.function.AddUint256Array() 1674 contract.arguments = append(contract.arguments, argument) 1675 return contract 1676 } 1677 1678 // AddAddressArray adds an address array parameter to the function call 1679 func (contract *ContractFunctionParameters) AddAddressArray(value []string) (*ContractFunctionParameters, error) { 1680 argument := _NewArgument() 1681 argument.dynamic = true 1682 1683 result := make([]byte, len(value)*32+32) 1684 1685 binary.BigEndian.PutUint64(result[24:32], uint64(len(value))) 1686 1687 for i, v := range value { 1688 if len(v) != 40 { 1689 return contract, errors.Unwrap(fmt.Errorf("address is required to be 40 characters")) 1690 } 1691 1692 addressBytes, err := hex.DecodeString(v) 1693 if err != nil { 1694 return contract, err 1695 } 1696 1697 copy(result[i*32+32+12:i*32+32+32], addressBytes[0:20]) 1698 } 1699 1700 argument.value = result 1701 1702 contract.function.AddAddressArray() 1703 contract.arguments = append(contract.arguments, argument) 1704 return contract, nil 1705 } 1706 1707 // AddString ads a string parameter to the function call 1708 func (contract *ContractFunctionParameters) AddString(value string) *ContractFunctionParameters { 1709 argument := _NewArgument() 1710 argument.dynamic = true 1711 1712 bytes := []byte(value) 1713 binary.BigEndian.PutUint64(argument.value[24:32], uint64(len(bytes))) 1714 argument.value = append(argument.value, bytes...) 1715 argument.value = append(argument.value, make([]byte, 32-len(bytes)%32)...) 1716 1717 contract.function.AddString() 1718 contract.arguments = append(contract.arguments, argument) 1719 return contract 1720 } 1721 1722 // AddBytes adds a bytes parameter to the function call 1723 func (contract *ContractFunctionParameters) AddBytes(value []byte) *ContractFunctionParameters { 1724 argument := _NewArgument() 1725 argument.dynamic = true 1726 1727 binary.BigEndian.PutUint64(argument.value[24:32], uint64(len(value))) 1728 argument.value = append(argument.value, value...) 1729 argument.value = append(argument.value, make([]byte, uint64(32-len(value)%32))...) 1730 1731 contract.function.AddBytes() 1732 contract.arguments = append(contract.arguments, argument) 1733 return contract 1734 } 1735 1736 // AddBytes32 adds a bytes32 parameter to the function call 1737 func (contract *ContractFunctionParameters) AddBytes32(value [32]byte) *ContractFunctionParameters { 1738 argument := _NewArgument() 1739 1740 argument.value = value[:] 1741 1742 contract.function.AddBytes32() 1743 contract.arguments = append(contract.arguments, argument) 1744 1745 return contract 1746 } 1747 1748 // AddAddress adds an address parameter to the function call 1749 func (contract *ContractFunctionParameters) AddAddress(value string) (*ContractFunctionParameters, error) { 1750 if len(value) != 40 { 1751 return contract, errors.Unwrap(fmt.Errorf("address is required to be 40 characters")) 1752 } 1753 1754 addressBytes, err := hex.DecodeString(value) 1755 if err != nil { 1756 return contract, err 1757 } 1758 1759 argument := _NewArgument() 1760 argument.dynamic = false 1761 1762 bytes := make([]byte, 12) 1763 bytes = append(bytes, addressBytes...) 1764 1765 argument.value = bytes 1766 1767 contract.function.AddAddress() 1768 contract.arguments = append(contract.arguments, argument) 1769 return contract, nil 1770 } 1771 1772 // AddBytesArray adds a bytes array parameter to the function call 1773 func (contract *ContractFunctionParameters) AddBytesArray(value [][]byte) *ContractFunctionParameters { 1774 argument := _NewArgument() 1775 1776 argument.dynamic = true 1777 argument.value = bytesArray(value) 1778 1779 contract.function.AddBytesArray() 1780 contract.arguments = append(contract.arguments, argument) 1781 return contract 1782 } 1783 1784 // AddBytes32Array adds a bytes32 array parameter to the function call 1785 func (contract *ContractFunctionParameters) AddBytes32Array(value [][]byte) *ContractFunctionParameters { 1786 argument := _NewArgument() 1787 argument.dynamic = true 1788 // Each item is 32 bytes. The total size should be len(value) * 32 plus 32 bytes for the length header 1789 result := make([]byte, len(value)*32+32) 1790 1791 // Write the length of the array into the first 32 bytes 1792 binary.BigEndian.PutUint64(result[24:32], uint64(len(value))) 1793 1794 for i, v := range value { 1795 // Ensure that each byte slice is 32 bytes long. 1796 var b [32]byte 1797 copy(b[32-len(v):], v) 1798 1799 // Then copy into the result 1800 from := i*32 + 32 1801 to := (i+1)*32 + 32 1802 copy(result[from:to], b[:]) 1803 } 1804 1805 argument.value = result 1806 1807 contract.function.AddBytes32Array() 1808 contract.arguments = append(contract.arguments, argument) 1809 return contract 1810 } 1811 1812 // AddStringArray adds a string array parameter to the function call 1813 func (contract *ContractFunctionParameters) AddStringArray(value []string) *ContractFunctionParameters { 1814 argument := _NewArgument() 1815 argument.dynamic = true 1816 1817 var bytes [][]byte 1818 for _, s := range value { 1819 bytes = append(bytes, []byte(s)) 1820 } 1821 1822 argument.value = bytesArray(bytes) 1823 contract.function.AddStringArray() 1824 contract.arguments = append(contract.arguments, argument) 1825 return contract 1826 } 1827 1828 func (contract *ContractFunctionParameters) _Build(functionName *string) []byte { 1829 length := uint64(0) 1830 1831 functionOffset := uint64(0) 1832 if functionName != nil { 1833 functionOffset = uint64(4) 1834 } 1835 1836 for _, argument := range contract.arguments { 1837 length += uint64(32) 1838 if argument.dynamic { 1839 length += uint64(len(argument.value)) 1840 } 1841 } 1842 1843 result := make([]byte, length+functionOffset) 1844 if functionName != nil { 1845 copy(result[0:4], contract.function._Build(functionName)) 1846 } 1847 1848 offset := uint64(len(contract.arguments) * 32) 1849 1850 for i, argument := range contract.arguments { 1851 j := uint64(i) 1852 if argument.dynamic { 1853 binary.BigEndian.PutUint64(result[(j*32+functionOffset)+24:(j+1)*32+functionOffset], offset) 1854 copy(result[offset+functionOffset:], argument.value) 1855 offset += uint64(len(argument.value)) 1856 } else { 1857 copy(result[j*32+functionOffset:((j+1)*32)+functionOffset], argument.value) 1858 } 1859 } 1860 1861 return result 1862 } 1863 1864 func _NewArgument() Argument { 1865 return Argument{ 1866 value: make([]byte, 32), 1867 dynamic: false, 1868 } 1869 } 1870 1871 func _NewIntArgument(value interface{}) Argument { 1872 var val int64 1873 switch v := value.(type) { 1874 case int64: 1875 val = v 1876 case int32: 1877 val = int64(v) 1878 case int16: 1879 val = int64(v) 1880 case int8: 1881 val = int64(v) 1882 default: 1883 panic(fmt.Sprintf("unsupported type %T", value)) 1884 } 1885 1886 if val > 0 { 1887 return _NewArgument() 1888 } 1889 argument := make([]byte, 32) 1890 for i := range argument { 1891 argument[i] = 0xff 1892 } 1893 return Argument{ 1894 value: argument, 1895 dynamic: false, 1896 } 1897 } 1898 1899 func bytesArray(value [][]byte) []byte { 1900 // Calculate Length of final result 1901 length := uint64(0) 1902 for _, s := range value { 1903 length += 32 + 32 1904 sbytes := s 1905 if len(sbytes)/32 == 0 { 1906 length += 32 1907 } else { 1908 length += uint64(((len(sbytes) / 32) + 1) * 32) 1909 } 1910 } 1911 1912 // Zero initialize final resulting byte array 1913 result := make([]byte, length+32) 1914 1915 // Write length of array into the first 32 bytes 1916 binary.BigEndian.PutUint64(result[24:32], uint64(len(value))) 1917 1918 // Create array of byte arrays to hold each string value 1919 // Needed to concat later 1920 arguments := make([][]byte, len(value)) 1921 1922 // Convert each argument into bytes, and push each argument 1923 // into the argument list 1924 for i, s := range value { 1925 // Get the length of the current argument (again) 1926 var length uint64 1927 if len(s)/32 == 0 { 1928 length = 32 1929 } else { 1930 length = uint64(((len(s) / 32) + 1) * 32) 1931 } 1932 1933 // Create byte array of correct size 1934 // Length of value to the nearest 32 byte boundary + 1935 // 32 bytes to store the length 1936 bytes := make([]byte, length+32) 1937 1938 // Write length into first 32 bytes 1939 binary.BigEndian.PutUint64(bytes[24:32], uint64(len(s))) 1940 1941 // Copy string as bytes to the rest of the buffer 1942 copy(bytes[32:], s) 1943 1944 // Set the argument bytes to be used later 1945 arguments[i] = bytes 1946 } 1947 1948 // Initialize offset to the number of strings 1949 offset := uint64(len(value) * 32) 1950 1951 // For each argument, write the offset into result 1952 // and the argument value (which includes data and length already) 1953 for i, s := range arguments { 1954 binary.BigEndian.PutUint64(result[(i+1)*32+24:(i+2)*32], offset) 1955 copy(result[offset+32:offset+32+uint64(len(s))], s) 1956 offset += uint64(len(s)) 1957 } 1958 1959 return result 1960 }