From d4c1067a69d4e90c2e11e155f59eaf5a6d9d1281 Mon Sep 17 00:00:00 2001 From: Dmitry Shihovtsev Date: Wed, 6 May 2020 09:03:50 +0600 Subject: [PATCH 1/2] Add missing payments smart contracts bindings --- bindings/AccountantImplementationProxy.go | 206 +++++++++++++ bindings/ChannelImplementationProxy.go | 206 +++++++++++++ bindings/Config.go | 352 ++++++++++++++++++++++ crypto/beneficiary.go | 6 +- crypto/crypto.go | 6 +- crypto/message.go | 6 +- crypto/promise.go | 11 +- crypto/promise_test.go | 1 - gen.go | 2 +- 9 files changed, 787 insertions(+), 9 deletions(-) create mode 100644 bindings/AccountantImplementationProxy.go create mode 100644 bindings/ChannelImplementationProxy.go create mode 100644 bindings/Config.go diff --git a/bindings/AccountantImplementationProxy.go b/bindings/AccountantImplementationProxy.go new file mode 100644 index 0000000..1af8950 --- /dev/null +++ b/bindings/AccountantImplementationProxy.go @@ -0,0 +1,206 @@ +/* Mysterium network payment library. + * + * Copyright (C) 2020 BlockDev AG + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package bindings + +import ( + "math/big" + "strings" + + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/event" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = big.NewInt + _ = strings.NewReader + _ = ethereum.NotFound + _ = abi.U256 + _ = bind.Bind + _ = common.Big1 + _ = types.BloomLookup + _ = event.NewSubscription +) + +// AccountantImplementationProxyABI is the input ABI used to generate the binding from. +const AccountantImplementationProxyABI = "[{\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"fallback\"}]" + +// AccountantImplementationProxyBin is the compiled bytecode used for deploying new contracts. +var AccountantImplementationProxyBin = "0x608060405234801561001057600080fd5b5060f48061001f6000396000f3fe608060408190526321f8a72160e01b81527fe6906d4b6048dd18329c27945d05f766dd19b003dc60f82fd4037c490ee55be06084526000907346e9742c098267122da466d6b7a3fb844436ac37906321f8a7219060a49060209060248186803b158015606a57600080fd5b505afa158015607d573d6000803e3d6000fd5b505050506040513d6020811015609257600080fd5b505160405190915036600082376000803683856127105a03f43d806000843e81801560bb578184f35b8184fdfea265627a7a7231582025c268b084e48dd8e7e2609c80f384372ceb16a8c2cc903d74041bbd13f9a56264736f6c63430005110032" + +// DeployAccountantImplementationProxy deploys a new Ethereum contract, binding an instance of AccountantImplementationProxy to it. +func DeployAccountantImplementationProxy(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *AccountantImplementationProxy, error) { + parsed, err := abi.JSON(strings.NewReader(AccountantImplementationProxyABI)) + if err != nil { + return common.Address{}, nil, nil, err + } + + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(AccountantImplementationProxyBin), backend) + if err != nil { + return common.Address{}, nil, nil, err + } + return address, tx, &AccountantImplementationProxy{AccountantImplementationProxyCaller: AccountantImplementationProxyCaller{contract: contract}, AccountantImplementationProxyTransactor: AccountantImplementationProxyTransactor{contract: contract}, AccountantImplementationProxyFilterer: AccountantImplementationProxyFilterer{contract: contract}}, nil +} + +// AccountantImplementationProxy is an auto generated Go binding around an Ethereum contract. +type AccountantImplementationProxy struct { + AccountantImplementationProxyCaller // Read-only binding to the contract + AccountantImplementationProxyTransactor // Write-only binding to the contract + AccountantImplementationProxyFilterer // Log filterer for contract events +} + +// AccountantImplementationProxyCaller is an auto generated read-only Go binding around an Ethereum contract. +type AccountantImplementationProxyCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// AccountantImplementationProxyTransactor is an auto generated write-only Go binding around an Ethereum contract. +type AccountantImplementationProxyTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// AccountantImplementationProxyFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type AccountantImplementationProxyFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// AccountantImplementationProxySession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type AccountantImplementationProxySession struct { + Contract *AccountantImplementationProxy // Generic contract binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// AccountantImplementationProxyCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type AccountantImplementationProxyCallerSession struct { + Contract *AccountantImplementationProxyCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// AccountantImplementationProxyTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type AccountantImplementationProxyTransactorSession struct { + Contract *AccountantImplementationProxyTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// AccountantImplementationProxyRaw is an auto generated low-level Go binding around an Ethereum contract. +type AccountantImplementationProxyRaw struct { + Contract *AccountantImplementationProxy // Generic contract binding to access the raw methods on +} + +// AccountantImplementationProxyCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type AccountantImplementationProxyCallerRaw struct { + Contract *AccountantImplementationProxyCaller // Generic read-only contract binding to access the raw methods on +} + +// AccountantImplementationProxyTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type AccountantImplementationProxyTransactorRaw struct { + Contract *AccountantImplementationProxyTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewAccountantImplementationProxy creates a new instance of AccountantImplementationProxy, bound to a specific deployed contract. +func NewAccountantImplementationProxy(address common.Address, backend bind.ContractBackend) (*AccountantImplementationProxy, error) { + contract, err := bindAccountantImplementationProxy(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &AccountantImplementationProxy{AccountantImplementationProxyCaller: AccountantImplementationProxyCaller{contract: contract}, AccountantImplementationProxyTransactor: AccountantImplementationProxyTransactor{contract: contract}, AccountantImplementationProxyFilterer: AccountantImplementationProxyFilterer{contract: contract}}, nil +} + +// NewAccountantImplementationProxyCaller creates a new read-only instance of AccountantImplementationProxy, bound to a specific deployed contract. +func NewAccountantImplementationProxyCaller(address common.Address, caller bind.ContractCaller) (*AccountantImplementationProxyCaller, error) { + contract, err := bindAccountantImplementationProxy(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &AccountantImplementationProxyCaller{contract: contract}, nil +} + +// NewAccountantImplementationProxyTransactor creates a new write-only instance of AccountantImplementationProxy, bound to a specific deployed contract. +func NewAccountantImplementationProxyTransactor(address common.Address, transactor bind.ContractTransactor) (*AccountantImplementationProxyTransactor, error) { + contract, err := bindAccountantImplementationProxy(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &AccountantImplementationProxyTransactor{contract: contract}, nil +} + +// NewAccountantImplementationProxyFilterer creates a new log filterer instance of AccountantImplementationProxy, bound to a specific deployed contract. +func NewAccountantImplementationProxyFilterer(address common.Address, filterer bind.ContractFilterer) (*AccountantImplementationProxyFilterer, error) { + contract, err := bindAccountantImplementationProxy(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &AccountantImplementationProxyFilterer{contract: contract}, nil +} + +// bindAccountantImplementationProxy binds a generic wrapper to an already deployed contract. +func bindAccountantImplementationProxy(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(AccountantImplementationProxyABI)) + if err != nil { + return nil, err + } + return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_AccountantImplementationProxy *AccountantImplementationProxyRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _AccountantImplementationProxy.Contract.AccountantImplementationProxyCaller.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_AccountantImplementationProxy *AccountantImplementationProxyRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _AccountantImplementationProxy.Contract.AccountantImplementationProxyTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_AccountantImplementationProxy *AccountantImplementationProxyRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _AccountantImplementationProxy.Contract.AccountantImplementationProxyTransactor.contract.Transact(opts, method, params...) +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_AccountantImplementationProxy *AccountantImplementationProxyCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _AccountantImplementationProxy.Contract.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_AccountantImplementationProxy *AccountantImplementationProxyTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _AccountantImplementationProxy.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_AccountantImplementationProxy *AccountantImplementationProxyTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _AccountantImplementationProxy.Contract.contract.Transact(opts, method, params...) +} diff --git a/bindings/ChannelImplementationProxy.go b/bindings/ChannelImplementationProxy.go new file mode 100644 index 0000000..9341d7e --- /dev/null +++ b/bindings/ChannelImplementationProxy.go @@ -0,0 +1,206 @@ +/* Mysterium network payment library. + * + * Copyright (C) 2020 BlockDev AG + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package bindings + +import ( + "math/big" + "strings" + + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/event" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = big.NewInt + _ = strings.NewReader + _ = ethereum.NotFound + _ = abi.U256 + _ = bind.Bind + _ = common.Big1 + _ = types.BloomLookup + _ = event.NewSubscription +) + +// ChannelImplementationProxyABI is the input ABI used to generate the binding from. +const ChannelImplementationProxyABI = "[{\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"fallback\"}]" + +// ChannelImplementationProxyBin is the compiled bytecode used for deploying new contracts. +var ChannelImplementationProxyBin = "0x608060405234801561001057600080fd5b5060f48061001f6000396000f3fe608060408190526321f8a72160e01b81527f48df65c92c1c0e8e19a219c69bfeb4cf7c1c123e0c266d555abb508d37c6d96e6084526000907346e9742c098267122da466d6b7a3fb844436ac37906321f8a7219060a49060209060248186803b158015606a57600080fd5b505afa158015607d573d6000803e3d6000fd5b505050506040513d6020811015609257600080fd5b505160405190915036600082376000803683856127105a03f43d806000843e81801560bb578184f35b8184fdfea265627a7a72315820be0a94ca9ff3862ff040176ea8239366993ca7d0d1e681eb579ca700055574b364736f6c63430005110032" + +// DeployChannelImplementationProxy deploys a new Ethereum contract, binding an instance of ChannelImplementationProxy to it. +func DeployChannelImplementationProxy(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *ChannelImplementationProxy, error) { + parsed, err := abi.JSON(strings.NewReader(ChannelImplementationProxyABI)) + if err != nil { + return common.Address{}, nil, nil, err + } + + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(ChannelImplementationProxyBin), backend) + if err != nil { + return common.Address{}, nil, nil, err + } + return address, tx, &ChannelImplementationProxy{ChannelImplementationProxyCaller: ChannelImplementationProxyCaller{contract: contract}, ChannelImplementationProxyTransactor: ChannelImplementationProxyTransactor{contract: contract}, ChannelImplementationProxyFilterer: ChannelImplementationProxyFilterer{contract: contract}}, nil +} + +// ChannelImplementationProxy is an auto generated Go binding around an Ethereum contract. +type ChannelImplementationProxy struct { + ChannelImplementationProxyCaller // Read-only binding to the contract + ChannelImplementationProxyTransactor // Write-only binding to the contract + ChannelImplementationProxyFilterer // Log filterer for contract events +} + +// ChannelImplementationProxyCaller is an auto generated read-only Go binding around an Ethereum contract. +type ChannelImplementationProxyCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// ChannelImplementationProxyTransactor is an auto generated write-only Go binding around an Ethereum contract. +type ChannelImplementationProxyTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// ChannelImplementationProxyFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type ChannelImplementationProxyFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// ChannelImplementationProxySession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type ChannelImplementationProxySession struct { + Contract *ChannelImplementationProxy // Generic contract binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// ChannelImplementationProxyCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type ChannelImplementationProxyCallerSession struct { + Contract *ChannelImplementationProxyCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// ChannelImplementationProxyTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type ChannelImplementationProxyTransactorSession struct { + Contract *ChannelImplementationProxyTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// ChannelImplementationProxyRaw is an auto generated low-level Go binding around an Ethereum contract. +type ChannelImplementationProxyRaw struct { + Contract *ChannelImplementationProxy // Generic contract binding to access the raw methods on +} + +// ChannelImplementationProxyCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type ChannelImplementationProxyCallerRaw struct { + Contract *ChannelImplementationProxyCaller // Generic read-only contract binding to access the raw methods on +} + +// ChannelImplementationProxyTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type ChannelImplementationProxyTransactorRaw struct { + Contract *ChannelImplementationProxyTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewChannelImplementationProxy creates a new instance of ChannelImplementationProxy, bound to a specific deployed contract. +func NewChannelImplementationProxy(address common.Address, backend bind.ContractBackend) (*ChannelImplementationProxy, error) { + contract, err := bindChannelImplementationProxy(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &ChannelImplementationProxy{ChannelImplementationProxyCaller: ChannelImplementationProxyCaller{contract: contract}, ChannelImplementationProxyTransactor: ChannelImplementationProxyTransactor{contract: contract}, ChannelImplementationProxyFilterer: ChannelImplementationProxyFilterer{contract: contract}}, nil +} + +// NewChannelImplementationProxyCaller creates a new read-only instance of ChannelImplementationProxy, bound to a specific deployed contract. +func NewChannelImplementationProxyCaller(address common.Address, caller bind.ContractCaller) (*ChannelImplementationProxyCaller, error) { + contract, err := bindChannelImplementationProxy(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &ChannelImplementationProxyCaller{contract: contract}, nil +} + +// NewChannelImplementationProxyTransactor creates a new write-only instance of ChannelImplementationProxy, bound to a specific deployed contract. +func NewChannelImplementationProxyTransactor(address common.Address, transactor bind.ContractTransactor) (*ChannelImplementationProxyTransactor, error) { + contract, err := bindChannelImplementationProxy(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &ChannelImplementationProxyTransactor{contract: contract}, nil +} + +// NewChannelImplementationProxyFilterer creates a new log filterer instance of ChannelImplementationProxy, bound to a specific deployed contract. +func NewChannelImplementationProxyFilterer(address common.Address, filterer bind.ContractFilterer) (*ChannelImplementationProxyFilterer, error) { + contract, err := bindChannelImplementationProxy(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &ChannelImplementationProxyFilterer{contract: contract}, nil +} + +// bindChannelImplementationProxy binds a generic wrapper to an already deployed contract. +func bindChannelImplementationProxy(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(ChannelImplementationProxyABI)) + if err != nil { + return nil, err + } + return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_ChannelImplementationProxy *ChannelImplementationProxyRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _ChannelImplementationProxy.Contract.ChannelImplementationProxyCaller.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_ChannelImplementationProxy *ChannelImplementationProxyRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _ChannelImplementationProxy.Contract.ChannelImplementationProxyTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_ChannelImplementationProxy *ChannelImplementationProxyRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _ChannelImplementationProxy.Contract.ChannelImplementationProxyTransactor.contract.Transact(opts, method, params...) +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_ChannelImplementationProxy *ChannelImplementationProxyCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _ChannelImplementationProxy.Contract.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_ChannelImplementationProxy *ChannelImplementationProxyTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _ChannelImplementationProxy.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_ChannelImplementationProxy *ChannelImplementationProxyTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _ChannelImplementationProxy.Contract.contract.Transact(opts, method, params...) +} diff --git a/bindings/Config.go b/bindings/Config.go new file mode 100644 index 0000000..0413150 --- /dev/null +++ b/bindings/Config.go @@ -0,0 +1,352 @@ +/* Mysterium network payment library. + * + * Copyright (C) 2020 BlockDev AG + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package bindings + +import ( + "math/big" + "strings" + + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/event" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = big.NewInt + _ = strings.NewReader + _ = ethereum.NotFound + _ = abi.U256 + _ = bind.Bind + _ = common.Big1 + _ = types.BloomLookup + _ = event.NewSubscription +) + +// ConfigABI is the input ABI used to generate the binding from. +const ConfigABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"slot\",\"type\":\"bytes32\"}],\"name\":\"getConfig\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"res\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"slot\",\"type\":\"bytes32\"}],\"name\":\"getAddress\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"res\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"slot\",\"type\":\"bytes32\"}],\"name\":\"getUint\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"res\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"slot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"value\",\"type\":\"bytes32\"}],\"name\":\"addConfig\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"setOwner\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" + +// ConfigBin is the compiled bytecode used for deploying new contracts. +var ConfigBin = "0x608060405234801561001057600080fd5b506101d5806100206000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c806313af40351461006757806321f8a7211461008f5780636dd5b69d146100c85780638da5cb5b146100f0578063bd02d0f5146100c8578063c4909a70146100f8575b600080fd5b61008d6004803603602081101561007d57600080fd5b50356001600160a01b031661011b565b005b6100ac600480360360208110156100a557600080fd5b5035610168565b604080516001600160a01b039092168252519081900360200190f35b6100de600480360360208110156100a557600080fd5b60408051918252519081900360200190f35b6100ac61016c565b61008d6004803603604081101561010e57600080fd5b508035906020013561017b565b6000546001600160a01b031633148061013d57506000546001600160a01b0316155b61014657600080fd5b600080546001600160a01b0319166001600160a01b0392909216919091179055565b5490565b6000546001600160a01b031681565b6000546001600160a01b0316331461019257600080fd5b8161019c57600080fd5b905556fea265627a7a72315820fd48926f0bb43cfdee827e2f7782cfc9d01323ca2c40ea5deb31ff37709ddbc964736f6c63430005110032" + +// DeployConfig deploys a new Ethereum contract, binding an instance of Config to it. +func DeployConfig(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *Config, error) { + parsed, err := abi.JSON(strings.NewReader(ConfigABI)) + if err != nil { + return common.Address{}, nil, nil, err + } + + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(ConfigBin), backend) + if err != nil { + return common.Address{}, nil, nil, err + } + return address, tx, &Config{ConfigCaller: ConfigCaller{contract: contract}, ConfigTransactor: ConfigTransactor{contract: contract}, ConfigFilterer: ConfigFilterer{contract: contract}}, nil +} + +// Config is an auto generated Go binding around an Ethereum contract. +type Config struct { + ConfigCaller // Read-only binding to the contract + ConfigTransactor // Write-only binding to the contract + ConfigFilterer // Log filterer for contract events +} + +// ConfigCaller is an auto generated read-only Go binding around an Ethereum contract. +type ConfigCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// ConfigTransactor is an auto generated write-only Go binding around an Ethereum contract. +type ConfigTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// ConfigFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type ConfigFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// ConfigSession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type ConfigSession struct { + Contract *Config // Generic contract binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// ConfigCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type ConfigCallerSession struct { + Contract *ConfigCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// ConfigTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type ConfigTransactorSession struct { + Contract *ConfigTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// ConfigRaw is an auto generated low-level Go binding around an Ethereum contract. +type ConfigRaw struct { + Contract *Config // Generic contract binding to access the raw methods on +} + +// ConfigCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type ConfigCallerRaw struct { + Contract *ConfigCaller // Generic read-only contract binding to access the raw methods on +} + +// ConfigTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type ConfigTransactorRaw struct { + Contract *ConfigTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewConfig creates a new instance of Config, bound to a specific deployed contract. +func NewConfig(address common.Address, backend bind.ContractBackend) (*Config, error) { + contract, err := bindConfig(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &Config{ConfigCaller: ConfigCaller{contract: contract}, ConfigTransactor: ConfigTransactor{contract: contract}, ConfigFilterer: ConfigFilterer{contract: contract}}, nil +} + +// NewConfigCaller creates a new read-only instance of Config, bound to a specific deployed contract. +func NewConfigCaller(address common.Address, caller bind.ContractCaller) (*ConfigCaller, error) { + contract, err := bindConfig(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &ConfigCaller{contract: contract}, nil +} + +// NewConfigTransactor creates a new write-only instance of Config, bound to a specific deployed contract. +func NewConfigTransactor(address common.Address, transactor bind.ContractTransactor) (*ConfigTransactor, error) { + contract, err := bindConfig(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &ConfigTransactor{contract: contract}, nil +} + +// NewConfigFilterer creates a new log filterer instance of Config, bound to a specific deployed contract. +func NewConfigFilterer(address common.Address, filterer bind.ContractFilterer) (*ConfigFilterer, error) { + contract, err := bindConfig(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &ConfigFilterer{contract: contract}, nil +} + +// bindConfig binds a generic wrapper to an already deployed contract. +func bindConfig(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(ConfigABI)) + if err != nil { + return nil, err + } + return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Config *ConfigRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _Config.Contract.ConfigCaller.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Config *ConfigRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Config.Contract.ConfigTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Config *ConfigRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Config.Contract.ConfigTransactor.contract.Transact(opts, method, params...) +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Config *ConfigCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _Config.Contract.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Config *ConfigTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Config.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Config *ConfigTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Config.Contract.contract.Transact(opts, method, params...) +} + +// GetAddress is a free data retrieval call binding the contract method 0x21f8a721. +// +// Solidity: function getAddress(bytes32 slot) constant returns(address res) +func (_Config *ConfigCaller) GetAddress(opts *bind.CallOpts, slot [32]byte) (common.Address, error) { + var ( + ret0 = new(common.Address) + ) + out := ret0 + err := _Config.contract.Call(opts, out, "getAddress", slot) + return *ret0, err +} + +// GetAddress is a free data retrieval call binding the contract method 0x21f8a721. +// +// Solidity: function getAddress(bytes32 slot) constant returns(address res) +func (_Config *ConfigSession) GetAddress(slot [32]byte) (common.Address, error) { + return _Config.Contract.GetAddress(&_Config.CallOpts, slot) +} + +// GetAddress is a free data retrieval call binding the contract method 0x21f8a721. +// +// Solidity: function getAddress(bytes32 slot) constant returns(address res) +func (_Config *ConfigCallerSession) GetAddress(slot [32]byte) (common.Address, error) { + return _Config.Contract.GetAddress(&_Config.CallOpts, slot) +} + +// GetConfig is a free data retrieval call binding the contract method 0x6dd5b69d. +// +// Solidity: function getConfig(bytes32 slot) constant returns(bytes32 res) +func (_Config *ConfigCaller) GetConfig(opts *bind.CallOpts, slot [32]byte) ([32]byte, error) { + var ( + ret0 = new([32]byte) + ) + out := ret0 + err := _Config.contract.Call(opts, out, "getConfig", slot) + return *ret0, err +} + +// GetConfig is a free data retrieval call binding the contract method 0x6dd5b69d. +// +// Solidity: function getConfig(bytes32 slot) constant returns(bytes32 res) +func (_Config *ConfigSession) GetConfig(slot [32]byte) ([32]byte, error) { + return _Config.Contract.GetConfig(&_Config.CallOpts, slot) +} + +// GetConfig is a free data retrieval call binding the contract method 0x6dd5b69d. +// +// Solidity: function getConfig(bytes32 slot) constant returns(bytes32 res) +func (_Config *ConfigCallerSession) GetConfig(slot [32]byte) ([32]byte, error) { + return _Config.Contract.GetConfig(&_Config.CallOpts, slot) +} + +// GetUint is a free data retrieval call binding the contract method 0xbd02d0f5. +// +// Solidity: function getUint(bytes32 slot) constant returns(uint256 res) +func (_Config *ConfigCaller) GetUint(opts *bind.CallOpts, slot [32]byte) (*big.Int, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + err := _Config.contract.Call(opts, out, "getUint", slot) + return *ret0, err +} + +// GetUint is a free data retrieval call binding the contract method 0xbd02d0f5. +// +// Solidity: function getUint(bytes32 slot) constant returns(uint256 res) +func (_Config *ConfigSession) GetUint(slot [32]byte) (*big.Int, error) { + return _Config.Contract.GetUint(&_Config.CallOpts, slot) +} + +// GetUint is a free data retrieval call binding the contract method 0xbd02d0f5. +// +// Solidity: function getUint(bytes32 slot) constant returns(uint256 res) +func (_Config *ConfigCallerSession) GetUint(slot [32]byte) (*big.Int, error) { + return _Config.Contract.GetUint(&_Config.CallOpts, slot) +} + +// Owner is a free data retrieval call binding the contract method 0x8da5cb5b. +// +// Solidity: function owner() constant returns(address) +func (_Config *ConfigCaller) Owner(opts *bind.CallOpts) (common.Address, error) { + var ( + ret0 = new(common.Address) + ) + out := ret0 + err := _Config.contract.Call(opts, out, "owner") + return *ret0, err +} + +// Owner is a free data retrieval call binding the contract method 0x8da5cb5b. +// +// Solidity: function owner() constant returns(address) +func (_Config *ConfigSession) Owner() (common.Address, error) { + return _Config.Contract.Owner(&_Config.CallOpts) +} + +// Owner is a free data retrieval call binding the contract method 0x8da5cb5b. +// +// Solidity: function owner() constant returns(address) +func (_Config *ConfigCallerSession) Owner() (common.Address, error) { + return _Config.Contract.Owner(&_Config.CallOpts) +} + +// AddConfig is a paid mutator transaction binding the contract method 0xc4909a70. +// +// Solidity: function addConfig(bytes32 slot, bytes32 value) returns() +func (_Config *ConfigTransactor) AddConfig(opts *bind.TransactOpts, slot [32]byte, value [32]byte) (*types.Transaction, error) { + return _Config.contract.Transact(opts, "addConfig", slot, value) +} + +// AddConfig is a paid mutator transaction binding the contract method 0xc4909a70. +// +// Solidity: function addConfig(bytes32 slot, bytes32 value) returns() +func (_Config *ConfigSession) AddConfig(slot [32]byte, value [32]byte) (*types.Transaction, error) { + return _Config.Contract.AddConfig(&_Config.TransactOpts, slot, value) +} + +// AddConfig is a paid mutator transaction binding the contract method 0xc4909a70. +// +// Solidity: function addConfig(bytes32 slot, bytes32 value) returns() +func (_Config *ConfigTransactorSession) AddConfig(slot [32]byte, value [32]byte) (*types.Transaction, error) { + return _Config.Contract.AddConfig(&_Config.TransactOpts, slot, value) +} + +// SetOwner is a paid mutator transaction binding the contract method 0x13af4035. +// +// Solidity: function setOwner(address _owner) returns() +func (_Config *ConfigTransactor) SetOwner(opts *bind.TransactOpts, _owner common.Address) (*types.Transaction, error) { + return _Config.contract.Transact(opts, "setOwner", _owner) +} + +// SetOwner is a paid mutator transaction binding the contract method 0x13af4035. +// +// Solidity: function setOwner(address _owner) returns() +func (_Config *ConfigSession) SetOwner(_owner common.Address) (*types.Transaction, error) { + return _Config.Contract.SetOwner(&_Config.TransactOpts, _owner) +} + +// SetOwner is a paid mutator transaction binding the contract method 0x13af4035. +// +// Solidity: function setOwner(address _owner) returns() +func (_Config *ConfigTransactorSession) SetOwner(_owner common.Address) (*types.Transaction, error) { + return _Config.Contract.SetOwner(&_Config.TransactOpts, _owner) +} diff --git a/crypto/beneficiary.go b/crypto/beneficiary.go index 6e2d717..8c2d5b1 100644 --- a/crypto/beneficiary.go +++ b/crypto/beneficiary.go @@ -19,6 +19,7 @@ package crypto import ( "encoding/hex" "errors" + "fmt" "math/big" "strings" @@ -60,7 +61,10 @@ func CreateBeneficiaryRequest(channelID, beneficiary string, nonce uint64, ks ha return nil, err } - ReformatSignatureVForBC(signature) + if err := ReformatSignatureVForBC(signature); err != nil { + return nil, fmt.Errorf("failed to reformat signature: %w", err) + } + request.Signature = hex.EncodeToString(signature) return &request, nil diff --git a/crypto/crypto.go b/crypto/crypto.go index d797e7f..7306436 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -59,7 +59,7 @@ func deriveCreate2Address(salt string, msgSender string, implementation string) // GenerateChannelAddress generate channel address from given identity hash func GenerateChannelAddress(identity, accountant, registry, channelImplementation string) (address string, err error) { if !isHexAddress(identity) || !isHexAddress(registry) || !isHexAddress(channelImplementation) { - return "", errors.New("Given identity, registry and channelImplementation params have to be hex addresses") + return "", errors.New("given identity, registry and channelImplementation params have to be hex addresses") } saltBytes, err := hex.DecodeString(ensureNoPrefix(identity) + ensureNoPrefix(accountant)) @@ -74,7 +74,7 @@ func GenerateChannelAddress(identity, accountant, registry, channelImplementatio // GenerateProviderChannelID generated channelID for provider channels from given identity hash func GenerateProviderChannelID(providerIdentity, accountantAddress string) (string, error) { if !isHexAddress(providerIdentity) || !isHexAddress(accountantAddress) { - return "", errors.New("Given providerIdentity and accountantAddress params have to be hex addresses") + return "", errors.New("given providerIdentity and accountantAddress params have to be hex addresses") } channelID := crypto.Keccak256(append( @@ -96,7 +96,7 @@ func GenerateProviderChannelIDBytes(providerIdentity, accountantAddress common.A // GenerateAccountantAddress generate accountant address from given accountant operator address func GenerateAccountantAddress(operator string, registry string, accountantImplementation string) (address string, err error) { if !isHexAddress(operator) || !isHexAddress(registry) || !isHexAddress(accountantImplementation) { - return "", errors.New("Given operator, registry and accountantImplementation params have to be hex addresses") + return "", errors.New("given operator, registry and accountantImplementation params have to be hex addresses") } salt, err := toBytes32(operator) diff --git a/crypto/message.go b/crypto/message.go index be5467a..2e12ccb 100644 --- a/crypto/message.go +++ b/crypto/message.go @@ -18,6 +18,7 @@ package crypto import ( "encoding/hex" + "fmt" "math/big" "strings" @@ -59,7 +60,10 @@ func CreateExchangeMessage(invoice Invoice, promiseAmount uint64, channelID stri return nil, err } - ReformatSignatureVForBC(signature) + if err := ReformatSignatureVForBC(signature); err != nil { + return nil, fmt.Errorf("failed to reformat signature: %w", err) + } + message.Signature = hex.EncodeToString(signature) return &message, nil diff --git a/crypto/promise.go b/crypto/promise.go index c16620d..02cdf19 100644 --- a/crypto/promise.go +++ b/crypto/promise.go @@ -18,6 +18,7 @@ package crypto import ( "encoding/hex" + "fmt" "math/big" "github.com/ethereum/go-ethereum/accounts" @@ -74,7 +75,10 @@ func CreatePromise(channelID string, amount uint64, fee uint64, hashlock string, return nil, err } - ReformatSignatureVForBC(signature) + if err := ReformatSignatureVForBC(signature); err != nil { + return nil, fmt.Errorf("failed to reformat signature: %w", err) + } + promise.Signature = signature return &promise, nil @@ -127,7 +131,10 @@ func (p *Promise) Sign(ks *keystore.KeyStore, signer common.Address) error { return err } - ReformatSignatureVForBC(signature) + if err := ReformatSignatureVForBC(signature); err != nil { + return fmt.Errorf("failed to reformat signature: %w", err) + } + p.Signature = signature return nil diff --git a/crypto/promise_test.go b/crypto/promise_test.go index 13a5506..0fbee4b 100644 --- a/crypto/promise_test.go +++ b/crypto/promise_test.go @@ -155,7 +155,6 @@ func TestCreatePromise(t *testing.T) { _, err = CreatePromise("NotHex", amount, fee, hashlock, ks, account.Address) assert.Error(t, err) assert.Equal(t, "channelID and hashlock have to be proper hex strings", err.Error()) - } func TestNewPromise(t *testing.T) { diff --git a/gen.go b/gen.go index afa40f0..0a537de 100644 --- a/gen.go +++ b/gen.go @@ -23,4 +23,4 @@ package bindings * looked up in migration script here: https://github.com/mysteriumnetwork/payments-smart-contracts/blob/master/migrations/2_deploy_contracts.js */ -//go:generate go run bindings/abi/abigen.go --githubrepo=mysteriumnetwork/payments-smart-contracts -githubrelease=v0.5.2 --contracts=SafeMathLib.json,MystToken.json,MystDEX.json,ChannelImplementation.json,AccountantImplementation.json,Registry.json --out=bindings --pkg=bindings +//go:generate go run bindings/abi/abigen.go --githubrepo=mysteriumnetwork/payments-smart-contracts -githubrelease=v0.5.2 --contracts=Config.json,SafeMathLib.json,MystToken.json,MystDEX.json,ChannelImplementation.json,ChannelImplementationProxy.json,AccountantImplementation.json,AccountantImplementationProxy.json,Registry.json --out=bindings --pkg=bindings From fe21695a912723053696490daa1869e78ce4afc2 Mon Sep 17 00:00:00 2001 From: Dmitry Shihovtsev Date: Wed, 6 May 2020 09:04:10 +0600 Subject: [PATCH 2/2] Add config deployment with a static address --- crypto/deploy.go | 147 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 crypto/deploy.go diff --git a/crypto/deploy.go b/crypto/deploy.go new file mode 100644 index 0000000..7feca36 --- /dev/null +++ b/crypto/deploy.go @@ -0,0 +1,147 @@ +package crypto + +import ( + "context" + "crypto/ecdsa" + "fmt" + "log" + "math/big" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" + "github.com/mysteriumnetwork/payments/bindings" + "github.com/pkg/errors" +) + +const ( + staticDeployer = "0x5B501f5dB54A1652F2f58B4bE7aaDAA117dCE622" + staticSignature = "0xffb2d0383ab970139a7e0fa9263c446199464b5778b92bf9e7936b5a383a8fd00abababababababababababababababababababababababababababababababa00" + staticConfigAddress = "0x46e9742C098267122DA466d6b7a3fb844436Ac37" +) + +// DeployConfigContract deploys config contract. +// It requires manually transaction build to make sure we are always deploying to the exact address. +// All the static arguments cannot be changed to allow having the exact address. +func DeployConfigContract(privkey string, client *ethclient.Client) (common.Address, error) { + err := TransferEth(privkey, common.HexToAddress(staticDeployer), big.NewInt(20000000000000000), client) + if err != nil { + return common.Address{}, fmt.Errorf("failed transfer eth: %w", err) + } + + auth := &bind.TransactOpts{ + Nonce: big.NewInt(0), + GasPrice: big.NewInt(100000000000), + GasLimit: 200000, + Value: big.NewInt(0), + } + + auth.Signer = func(types.Signer, common.Address, *types.Transaction) (*types.Transaction, error) { + tx := types.NewContractCreation(0, auth.Value, auth.GasLimit, auth.GasPrice, common.FromHex(bindings.ConfigBin)) + signer := types.NewEIP155Signer(nil) + sig := common.FromHex(staticSignature) + + return tx.WithSignature(signer, sig) + } + + _, _, _, err = bindings.DeployConfig(auth, client) + if err != nil { + return common.Address{}, fmt.Errorf("failed to deploy config contract: %w", err) + } + + return common.HexToAddress(staticConfigAddress), nil +} + +// SetupConfig adds required configuration options to the deployed config. +// It sets config owner, channel implementation and accountant implementation addresses. +func SetupConfig(opts *bind.TransactOpts, client bind.ContractBackend, owner string, channelImplProxyAddress, channelImplAddress, accountantImplAddress, accountantImplProxyAddress common.Address) error { + cfg, err := bindings.NewConfig(common.HexToAddress(staticConfigAddress), client) + if err != nil { + return fmt.Errorf("failed to get config by provided address: %w", err) + } + + _, err = cfg.SetOwner(opts, common.HexToAddress(owner)) + if err != nil { + return fmt.Errorf("failed to set config owner: %w", err) + } + + _, err = cfg.AddConfig(opts, bytes32(common.FromHex("0x2ef7e7c50e1b6a574193d0d32b7c0456cf12390a0872cf00be4797e71c3756f7")), + bytes32(channelImplAddress.Hash().Bytes())) + if err != nil { + return fmt.Errorf("failed to add channel implementation to config: %w", err) + } + + _, err = cfg.AddConfig(opts, bytes32(common.FromHex("0x48df65c92c1c0e8e19a219c69bfeb4cf7c1c123e0c266d555abb508d37c6d96e")), + bytes32(channelImplProxyAddress.Hash().Bytes())) + if err != nil { + return fmt.Errorf("failed to add channel implementation proxy to config: %w", err) + } + + _, err = cfg.AddConfig(opts, bytes32(common.FromHex("0xe6906d4b6048dd18329c27945d05f766dd19b003dc60f82fd4037c490ee55be0")), + bytes32(accountantImplAddress.Hash().Bytes())) + if err != nil { + return fmt.Errorf("failed to add accountant implementation to config: %w", err) + } + + _, err = cfg.AddConfig(opts, bytes32(common.FromHex("0x52948fa93a94851571e57fddc2be83c51e0a64bb5e9ca55f4f90439b9802b575")), + bytes32(accountantImplProxyAddress.Hash().Bytes())) + if err != nil { + return fmt.Errorf("failed to add accountant implementation proxy to config: %w", err) + } + + return nil +} + +func TransferEth(from string, target common.Address, amount *big.Int, client *ethclient.Client) error { + pk, addr, err := ParsePrivkey(from) + if err != nil { + return errors.Wrap(err, "could not parse private key") + } + + nonce, err := client.PendingNonceAt(context.Background(), addr) + if err != nil { + return errors.Wrap(err, "could not get nonce") + } + + gasPrice, err := client.SuggestGasPrice(context.Background()) + if err != nil { + return errors.Wrap(err, "could not get gas price") + } + gasLimit := uint64(21000) // in units + + tx := types.NewTransaction(nonce, target, amount, gasLimit, gasPrice, nil) + + chainID, err := client.NetworkID(context.Background()) + if err != nil { + log.Fatal(err) + } + + signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), pk) + if err != nil { + return errors.Wrap(err, "could not sign tx") + } + + return errors.Wrap(client.SendTransaction(context.Background(), signedTx), "could not send transaction") +} + +func ParsePrivkey(privkey string) (*ecdsa.PrivateKey, common.Address, error) { + privateKey, err := crypto.HexToECDSA(privkey) + if err != nil { + return nil, common.Address{}, errors.Wrap(err, "could not decode private key") + } + + return privateKey, ParsePubKey(privateKey), nil +} + +func ParsePubKey(privateKey *ecdsa.PrivateKey) common.Address { + publicKey := privateKey.Public().(*ecdsa.PublicKey) + addr := crypto.PubkeyToAddress(*publicKey) + return addr +} + +func bytes32(arr []byte) (res [32]byte) { + copy(res[:], arr) + return res +}