From 575ce7aa09db64b1f97bbfe0fff09652044cd110 Mon Sep 17 00:00:00 2001 From: subowei <954075159@qq.com> Date: Wed, 9 Aug 2023 10:12:55 +0800 Subject: [PATCH 1/2] add bfs and sharding, add appendColumns in curd_service --- precompiled/bfs/bfs.go | 453 ++++++++++++++++++ precompiled/bfs/bfs_service.go | 123 +++++ precompiled/bfs/bfs_service_test.go | 265 ++++++++++ precompiled/crud/crud_service.go | 12 + precompiled/crud/crud_service_test.go | 49 ++ precompiled/sharding/sharding.go | 306 ++++++++++++ precompiled/sharding/sharding_service.go | 63 +++ precompiled/sharding/sharding_service_test.go | 162 +++++++ 8 files changed, 1433 insertions(+) create mode 100644 precompiled/bfs/bfs.go create mode 100644 precompiled/bfs/bfs_service.go create mode 100644 precompiled/bfs/bfs_service_test.go create mode 100644 precompiled/sharding/sharding.go create mode 100644 precompiled/sharding/sharding_service.go create mode 100644 precompiled/sharding/sharding_service_test.go diff --git a/precompiled/bfs/bfs.go b/precompiled/bfs/bfs.go new file mode 100644 index 00000000..7252728c --- /dev/null +++ b/precompiled/bfs/bfs.go @@ -0,0 +1,453 @@ +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package bfs + +import ( + "math/big" + "strings" + + "github.com/FISCO-BCOS/go-sdk/abi" + "github.com/FISCO-BCOS/go-sdk/abi/bind" + "github.com/FISCO-BCOS/go-sdk/core/types" + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/common" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = big.NewInt + _ = strings.NewReader + _ = ethereum.NotFound + _ = abi.U256 + _ = bind.Bind + _ = common.Big1 +) + +// BfsInfo is an auto generated low-level Go binding around an user-defined struct. +type BfsInfo struct { + FileName string + FileType string + Ext []string +} + +// BfsABI is the input ABI used to generate the binding from. +const BfsABI = "[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"absolutePath\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"_address\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"_abi\",\"type\":\"string\"}],\"name\":\"link\",\"outputs\":[{\"internalType\":\"int256\",\"name\":\"\",\"type\":\"int256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"name\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"version\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"_address\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"_abi\",\"type\":\"string\"}],\"name\":\"link\",\"outputs\":[{\"internalType\":\"int32\",\"name\":\"\",\"type\":\"int32\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"absolutePath\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"offset\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"limit\",\"type\":\"uint256\"}],\"name\":\"list\",\"outputs\":[{\"internalType\":\"int256\",\"name\":\"\",\"type\":\"int256\"},{\"components\":[{\"internalType\":\"string\",\"name\":\"file_name\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"file_type\",\"type\":\"string\"},{\"internalType\":\"string[]\",\"name\":\"ext\",\"type\":\"string[]\"}],\"internalType\":\"structBfsInfo[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"absolutePath\",\"type\":\"string\"}],\"name\":\"list\",\"outputs\":[{\"internalType\":\"int32\",\"name\":\"\",\"type\":\"int32\"},{\"components\":[{\"internalType\":\"string\",\"name\":\"file_name\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"file_type\",\"type\":\"string\"},{\"internalType\":\"string[]\",\"name\":\"ext\",\"type\":\"string[]\"}],\"internalType\":\"structBfsInfo[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"absolutePath\",\"type\":\"string\"}],\"name\":\"mkdir\",\"outputs\":[{\"internalType\":\"int32\",\"name\":\"\",\"type\":\"int32\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"absolutePath\",\"type\":\"string\"}],\"name\":\"readlink\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"rebuildBfs\",\"outputs\":[{\"internalType\":\"int256\",\"name\":\"\",\"type\":\"int256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"absolutePath\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"fileType\",\"type\":\"string\"}],\"name\":\"touch\",\"outputs\":[{\"internalType\":\"int32\",\"name\":\"\",\"type\":\"int32\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" + +// Bfs is an auto generated Go binding around a Solidity contract. +type Bfs struct { + BfsCaller // Read-only binding to the contract + BfsTransactor // Write-only binding to the contract + BfsFilterer // Log filterer for contract events +} + +// BfsCaller is an auto generated read-only Go binding around a Solidity contract. +type BfsCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// BfsTransactor is an auto generated write-only Go binding around a Solidity contract. +type BfsTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// BfsFilterer is an auto generated log filtering Go binding around a Solidity contract events. +type BfsFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// BfsSession is an auto generated Go binding around a Solidity contract, +// with pre-set call and transact options. +type BfsSession struct { + Contract *Bfs // 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 +} + +// BfsCallerSession is an auto generated read-only Go binding around a Solidity contract, +// with pre-set call options. +type BfsCallerSession struct { + Contract *BfsCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// BfsTransactorSession is an auto generated write-only Go binding around a Solidity contract, +// with pre-set transact options. +type BfsTransactorSession struct { + Contract *BfsTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// BfsRaw is an auto generated low-level Go binding around a Solidity contract. +type BfsRaw struct { + Contract *Bfs // Generic contract binding to access the raw methods on +} + +// BfsCallerRaw is an auto generated low-level read-only Go binding around a Solidity contract. +type BfsCallerRaw struct { + Contract *BfsCaller // Generic read-only contract binding to access the raw methods on +} + +// BfsTransactorRaw is an auto generated low-level write-only Go binding around a Solidity contract. +type BfsTransactorRaw struct { + Contract *BfsTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewBfs creates a new instance of Bfs, bound to a specific deployed contract. +func NewBfs(address common.Address, backend bind.ContractBackend) (*Bfs, error) { + contract, err := bindBfs(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &Bfs{BfsCaller: BfsCaller{contract: contract}, BfsTransactor: BfsTransactor{contract: contract}, BfsFilterer: BfsFilterer{contract: contract}}, nil +} + +// NewBfsCaller creates a new read-only instance of Bfs, bound to a specific deployed contract. +func NewBfsCaller(address common.Address, caller bind.ContractCaller) (*BfsCaller, error) { + contract, err := bindBfs(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &BfsCaller{contract: contract}, nil +} + +// NewBfsTransactor creates a new write-only instance of Bfs, bound to a specific deployed contract. +func NewBfsTransactor(address common.Address, transactor bind.ContractTransactor) (*BfsTransactor, error) { + contract, err := bindBfs(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &BfsTransactor{contract: contract}, nil +} + +// NewBfsFilterer creates a new log filterer instance of Bfs, bound to a specific deployed contract. +func NewBfsFilterer(address common.Address, filterer bind.ContractFilterer) (*BfsFilterer, error) { + contract, err := bindBfs(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &BfsFilterer{contract: contract}, nil +} + +// bindBfs binds a generic wrapper to an already deployed contract. +func bindBfs(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(BfsABI)) + 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 (_Bfs *BfsRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _Bfs.Contract.BfsCaller.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 (_Bfs *BfsRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.BfsTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Bfs *BfsRaw) TransactWithResult(opts *bind.TransactOpts, result interface{}, method string, params ...interface{}) (*types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.BfsTransactor.contract.TransactWithResult(opts, result, 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 (_Bfs *BfsCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _Bfs.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 (_Bfs *BfsTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Bfs *BfsTransactorRaw) TransactWithResult(opts *bind.TransactOpts, result interface{}, method string, params ...interface{}) (*types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.contract.TransactWithResult(opts, result, method, params...) +} + +// List is a free data retrieval call binding the contract method 0x912f3095. +// +// Solidity: function list(string absolutePath, uint256 offset, uint256 limit) constant returns(int256, []BfsInfo) +func (_Bfs *BfsCaller) List(opts *bind.CallOpts, absolutePath string, offset *big.Int, limit *big.Int) (*big.Int, []BfsInfo, error) { + var ( + ret0 = new(*big.Int) + ret1 = new([]BfsInfo) + ) + out := &[]interface{}{ + ret0, + ret1, + } + err := _Bfs.contract.Call(opts, out, "list", absolutePath, offset, limit) + return *ret0, *ret1, err +} + +// List is a free data retrieval call binding the contract method 0x912f3095. +// +// Solidity: function list(string absolutePath, uint256 offset, uint256 limit) constant returns(int256, []BfsInfo) +func (_Bfs *BfsSession) List(absolutePath string, offset *big.Int, limit *big.Int) (*big.Int, []BfsInfo, error) { + return _Bfs.Contract.List(&_Bfs.CallOpts, absolutePath, offset, limit) +} + +// List is a free data retrieval call binding the contract method 0x912f3095. +// +// Solidity: function list(string absolutePath, uint256 offset, uint256 limit) constant returns(int256, []BfsInfo) +func (_Bfs *BfsCallerSession) List(absolutePath string, offset *big.Int, limit *big.Int) (*big.Int, []BfsInfo, error) { + return _Bfs.Contract.List(&_Bfs.CallOpts, absolutePath, offset, limit) +} + +// List0 is a free data retrieval call binding the contract method 0xfe42bf1a. +// +// Solidity: function list(string absolutePath) constant returns(int32, []BfsInfo) +func (_Bfs *BfsCaller) List0(opts *bind.CallOpts, absolutePath string) (int32, []BfsInfo, error) { + var ( + ret0 = new(int32) + ret1 = new([]BfsInfo) + ) + out := &[]interface{}{ + ret0, + ret1, + } + err := _Bfs.contract.Call(opts, out, "list0", absolutePath) + return *ret0, *ret1, err +} + +// List0 is a free data retrieval call binding the contract method 0xfe42bf1a. +// +// Solidity: function list(string absolutePath) constant returns(int32, []BfsInfo) +func (_Bfs *BfsSession) List0(absolutePath string) (int32, []BfsInfo, error) { + return _Bfs.Contract.List0(&_Bfs.CallOpts, absolutePath) +} + +// List0 is a free data retrieval call binding the contract method 0xfe42bf1a. +// +// Solidity: function list(string absolutePath) constant returns(int32, []BfsInfo) +func (_Bfs *BfsCallerSession) List0(absolutePath string) (int32, []BfsInfo, error) { + return _Bfs.Contract.List0(&_Bfs.CallOpts, absolutePath) +} + +// Readlink is a free data retrieval call binding the contract method 0x1d05a836. +// +// Solidity: function readlink(string absolutePath) constant returns(address) +func (_Bfs *BfsCaller) Readlink(opts *bind.CallOpts, absolutePath string) (common.Address, error) { + var ( + ret0 = new(common.Address) + ) + out := ret0 + err := _Bfs.contract.Call(opts, out, "readlink", absolutePath) + return *ret0, err +} + +// Readlink is a free data retrieval call binding the contract method 0x1d05a836. +// +// Solidity: function readlink(string absolutePath) constant returns(address) +func (_Bfs *BfsSession) Readlink(absolutePath string) (common.Address, error) { + return _Bfs.Contract.Readlink(&_Bfs.CallOpts, absolutePath) +} + +// Readlink is a free data retrieval call binding the contract method 0x1d05a836. +// +// Solidity: function readlink(string absolutePath) constant returns(address) +func (_Bfs *BfsCallerSession) Readlink(absolutePath string) (common.Address, error) { + return _Bfs.Contract.Readlink(&_Bfs.CallOpts, absolutePath) +} + +// Link is a paid mutator transaction binding the contract method 0x8df118af. +// +// Solidity: function link(string absolutePath, string _address, string _abi) returns(int256) +func (_Bfs *BfsTransactor) Link(opts *bind.TransactOpts, absolutePath string, _address string, _abi string) (*big.Int, *types.Transaction, *types.Receipt, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + transaction, receipt, err := _Bfs.contract.TransactWithResult(opts, out, "link", absolutePath, _address, _abi) + return *ret0, transaction, receipt, err +} + +func (_Bfs *BfsTransactor) AsyncLink(handler func(*types.Receipt, error), opts *bind.TransactOpts, absolutePath string, _address string, _abi string) (*types.Transaction, error) { + return _Bfs.contract.AsyncTransact(opts, handler, "link", absolutePath, _address, _abi) +} + +// Link is a paid mutator transaction binding the contract method 0x8df118af. +// +// Solidity: function link(string absolutePath, string _address, string _abi) returns(int256) +func (_Bfs *BfsSession) Link(absolutePath string, _address string, _abi string) (*big.Int, *types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.Link(&_Bfs.TransactOpts, absolutePath, _address, _abi) +} + +func (_Bfs *BfsSession) AsyncLink(handler func(*types.Receipt, error), absolutePath string, _address string, _abi string) (*types.Transaction, error) { + return _Bfs.Contract.AsyncLink(handler, &_Bfs.TransactOpts, absolutePath, _address, _abi) +} + +// Link is a paid mutator transaction binding the contract method 0x8df118af. +// +// Solidity: function link(string absolutePath, string _address, string _abi) returns(int256) +func (_Bfs *BfsTransactorSession) Link(absolutePath string, _address string, _abi string) (*big.Int, *types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.Link(&_Bfs.TransactOpts, absolutePath, _address, _abi) +} + +func (_Bfs *BfsTransactorSession) AsyncLink(handler func(*types.Receipt, error), absolutePath string, _address string, _abi string) (*types.Transaction, error) { + return _Bfs.Contract.AsyncLink(handler, &_Bfs.TransactOpts, absolutePath, _address, _abi) +} + +// Link0 is a paid mutator transaction binding the contract method 0xe19c2fcf. +// +// Solidity: function link(string name, string version, string _address, string _abi) returns(int32) +func (_Bfs *BfsTransactor) Link0(opts *bind.TransactOpts, name string, version string, _address string, _abi string) (int32, *types.Transaction, *types.Receipt, error) { + var ( + ret0 = new(int32) + ) + out := ret0 + transaction, receipt, err := _Bfs.contract.TransactWithResult(opts, out, "link0", name, version, _address, _abi) + return *ret0, transaction, receipt, err +} + +func (_Bfs *BfsTransactor) AsyncLink0(handler func(*types.Receipt, error), opts *bind.TransactOpts, name string, version string, _address string, _abi string) (*types.Transaction, error) { + return _Bfs.contract.AsyncTransact(opts, handler, "link0", name, version, _address, _abi) +} + +// Link0 is a paid mutator transaction binding the contract method 0xe19c2fcf. +// +// Solidity: function link(string name, string version, string _address, string _abi) returns(int32) +func (_Bfs *BfsSession) Link0(name string, version string, _address string, _abi string) (int32, *types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.Link0(&_Bfs.TransactOpts, name, version, _address, _abi) +} + +func (_Bfs *BfsSession) AsyncLink0(handler func(*types.Receipt, error), name string, version string, _address string, _abi string) (*types.Transaction, error) { + return _Bfs.Contract.AsyncLink0(handler, &_Bfs.TransactOpts, name, version, _address, _abi) +} + +// Link0 is a paid mutator transaction binding the contract method 0xe19c2fcf. +// +// Solidity: function link(string name, string version, string _address, string _abi) returns(int32) +func (_Bfs *BfsTransactorSession) Link0(name string, version string, _address string, _abi string) (int32, *types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.Link0(&_Bfs.TransactOpts, name, version, _address, _abi) +} + +func (_Bfs *BfsTransactorSession) AsyncLink0(handler func(*types.Receipt, error), name string, version string, _address string, _abi string) (*types.Transaction, error) { + return _Bfs.Contract.AsyncLink0(handler, &_Bfs.TransactOpts, name, version, _address, _abi) +} + +// Mkdir is a paid mutator transaction binding the contract method 0x876b0eb2. +// +// Solidity: function mkdir(string absolutePath) returns(int32) +func (_Bfs *BfsTransactor) Mkdir(opts *bind.TransactOpts, absolutePath string) (int32, *types.Transaction, *types.Receipt, error) { + var ( + ret0 = new(int32) + ) + out := ret0 + transaction, receipt, err := _Bfs.contract.TransactWithResult(opts, out, "mkdir", absolutePath) + return *ret0, transaction, receipt, err +} + +func (_Bfs *BfsTransactor) AsyncMkdir(handler func(*types.Receipt, error), opts *bind.TransactOpts, absolutePath string) (*types.Transaction, error) { + return _Bfs.contract.AsyncTransact(opts, handler, "mkdir", absolutePath) +} + +// Mkdir is a paid mutator transaction binding the contract method 0x876b0eb2. +// +// Solidity: function mkdir(string absolutePath) returns(int32) +func (_Bfs *BfsSession) Mkdir(absolutePath string) (int32, *types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.Mkdir(&_Bfs.TransactOpts, absolutePath) +} + +func (_Bfs *BfsSession) AsyncMkdir(handler func(*types.Receipt, error), absolutePath string) (*types.Transaction, error) { + return _Bfs.Contract.AsyncMkdir(handler, &_Bfs.TransactOpts, absolutePath) +} + +// Mkdir is a paid mutator transaction binding the contract method 0x876b0eb2. +// +// Solidity: function mkdir(string absolutePath) returns(int32) +func (_Bfs *BfsTransactorSession) Mkdir(absolutePath string) (int32, *types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.Mkdir(&_Bfs.TransactOpts, absolutePath) +} + +func (_Bfs *BfsTransactorSession) AsyncMkdir(handler func(*types.Receipt, error), absolutePath string) (*types.Transaction, error) { + return _Bfs.Contract.AsyncMkdir(handler, &_Bfs.TransactOpts, absolutePath) +} + +// RebuildBfs is a paid mutator transaction binding the contract method 0xa007e274. +// +// Solidity: function rebuildBfs() returns(int256) +func (_Bfs *BfsTransactor) RebuildBfs(opts *bind.TransactOpts) (*big.Int, *types.Transaction, *types.Receipt, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + transaction, receipt, err := _Bfs.contract.TransactWithResult(opts, out, "rebuildBfs") + return *ret0, transaction, receipt, err +} + +func (_Bfs *BfsTransactor) AsyncRebuildBfs(handler func(*types.Receipt, error), opts *bind.TransactOpts) (*types.Transaction, error) { + return _Bfs.contract.AsyncTransact(opts, handler, "rebuildBfs") +} + +// RebuildBfs is a paid mutator transaction binding the contract method 0xa007e274. +// +// Solidity: function rebuildBfs() returns(int256) +func (_Bfs *BfsSession) RebuildBfs() (*big.Int, *types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.RebuildBfs(&_Bfs.TransactOpts) +} + +func (_Bfs *BfsSession) AsyncRebuildBfs(handler func(*types.Receipt, error)) (*types.Transaction, error) { + return _Bfs.Contract.AsyncRebuildBfs(handler, &_Bfs.TransactOpts) +} + +// RebuildBfs is a paid mutator transaction binding the contract method 0xa007e274. +// +// Solidity: function rebuildBfs() returns(int256) +func (_Bfs *BfsTransactorSession) RebuildBfs() (*big.Int, *types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.RebuildBfs(&_Bfs.TransactOpts) +} + +func (_Bfs *BfsTransactorSession) AsyncRebuildBfs(handler func(*types.Receipt, error)) (*types.Transaction, error) { + return _Bfs.Contract.AsyncRebuildBfs(handler, &_Bfs.TransactOpts) +} + +// Touch is a paid mutator transaction binding the contract method 0x131ffcdd. +// +// Solidity: function touch(string absolutePath, string fileType) returns(int32) +func (_Bfs *BfsTransactor) Touch(opts *bind.TransactOpts, absolutePath string, fileType string) (int32, *types.Transaction, *types.Receipt, error) { + var ( + ret0 = new(int32) + ) + out := ret0 + transaction, receipt, err := _Bfs.contract.TransactWithResult(opts, out, "touch", absolutePath, fileType) + return *ret0, transaction, receipt, err +} + +func (_Bfs *BfsTransactor) AsyncTouch(handler func(*types.Receipt, error), opts *bind.TransactOpts, absolutePath string, fileType string) (*types.Transaction, error) { + return _Bfs.contract.AsyncTransact(opts, handler, "touch", absolutePath, fileType) +} + +// Touch is a paid mutator transaction binding the contract method 0x131ffcdd. +// +// Solidity: function touch(string absolutePath, string fileType) returns(int32) +func (_Bfs *BfsSession) Touch(absolutePath string, fileType string) (int32, *types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.Touch(&_Bfs.TransactOpts, absolutePath, fileType) +} + +func (_Bfs *BfsSession) AsyncTouch(handler func(*types.Receipt, error), absolutePath string, fileType string) (*types.Transaction, error) { + return _Bfs.Contract.AsyncTouch(handler, &_Bfs.TransactOpts, absolutePath, fileType) +} + +// Touch is a paid mutator transaction binding the contract method 0x131ffcdd. +// +// Solidity: function touch(string absolutePath, string fileType) returns(int32) +func (_Bfs *BfsTransactorSession) Touch(absolutePath string, fileType string) (int32, *types.Transaction, *types.Receipt, error) { + return _Bfs.Contract.Touch(&_Bfs.TransactOpts, absolutePath, fileType) +} + +func (_Bfs *BfsTransactorSession) AsyncTouch(handler func(*types.Receipt, error), absolutePath string, fileType string) (*types.Transaction, error) { + return _Bfs.Contract.AsyncTouch(handler, &_Bfs.TransactOpts, absolutePath, fileType) +} diff --git a/precompiled/bfs/bfs_service.go b/precompiled/bfs/bfs_service.go new file mode 100644 index 00000000..4124ca97 --- /dev/null +++ b/precompiled/bfs/bfs_service.go @@ -0,0 +1,123 @@ +package bfs + +import ( + "fmt" + + "github.com/FISCO-BCOS/go-sdk/abi/bind" + "github.com/FISCO-BCOS/go-sdk/client" + "github.com/FISCO-BCOS/go-sdk/core/types" + "github.com/FISCO-BCOS/go-sdk/precompiled" + "github.com/ethereum/go-ethereum/common" + "math/big" +) + +type Service struct { + bfs *Bfs + bfsAuth *bind.TransactOpts + client *client.Client +} + +// contract address +var bfsPrecompileAddress = common.HexToAddress("000000000000000000000000000000000000100e") + +// NewCnsService returns ptr of Service +func NewBfsService(client *client.Client) (*Service, error) { + instance, err := NewBfs(bfsPrecompileAddress, client) + if err != nil { + return nil, fmt.Errorf("construct Service failed: %+v", err) + } + auth := client.GetTransactOpts() + return &Service{bfs: instance, bfsAuth: auth, client: client}, nil +} + +func (service *Service) List0(absolutePath string) (int64, []BfsInfo, error) { + opts := &bind.CallOpts{From: service.bfsAuth.From} + ret0, ret1, err := service.bfs.List0(opts, absolutePath) + if err != nil { + return precompiled.DefaultErrorCode, nil, fmt.Errorf("service List0 failed: %+v", err) + } + return int64(ret0), ret1, err +} + +func (service *Service) List(absolutePath string, offset *big.Int, limit *big.Int) (int64, []BfsInfo, error) { + opts := &bind.CallOpts{From: service.bfsAuth.From} + ret0, ret1, err := service.bfs.List(opts, absolutePath, offset, limit) + if err != nil { + return precompiled.DefaultErrorCode, nil, fmt.Errorf("service List failed: %+v", err) + } + return ret0.Int64(), ret1, err +} + +func (service *Service) AsyncMkdir(handler func(*types.Receipt, error), absolutePath string) (*types.Transaction, error) { + return service.bfs.AsyncMkdir(handler, service.bfsAuth, absolutePath) +} + +func (service *Service) Mkdir(absolutePath string) (int64, error) { + ret0, _, _, err := service.bfs.Mkdir(service.bfsAuth, absolutePath) + if err != nil { + return precompiled.DefaultErrorCode, fmt.Errorf("service Mkdir failed: %+v", err) + } + return int64(ret0), err +} + +func (service *Service) Link(absolutePath string, _address string, _abi string) (int64, error) { + ret0, _, _, err := service.bfs.Link(service.bfsAuth, absolutePath, _address, _abi) + if err != nil { + return precompiled.DefaultErrorCode, fmt.Errorf("service Link failed: %+v", err) + } + return ret0.Int64(), err +} + +func (service *Service) AsyncLink(handler func(*types.Receipt, error), absolutePath string, _address string, _abi string) (*types.Transaction, error) { + return service.bfs.AsyncLink(handler, service.bfsAuth, absolutePath, _address, _abi) +} + +func (service *Service) Link0(name string, version string, _address string, _abi string) (int64, error) { + ret0, _, _, err := service.bfs.Link0(service.bfsAuth, name, version, _address, _abi) + if err != nil { + return precompiled.DefaultErrorCode, fmt.Errorf("service Link0 failed: %+v", err) + } + return int64(ret0), err +} + +func (service *Service) AsyncLink0(handler func(*types.Receipt, error), name string, version string, _address string, _abi string) (*types.Transaction, error) { + return service.bfs.AsyncLink0(handler, service.bfsAuth, name, version, _address, _abi) +} + +func (service *Service) Readlink(absolutePath string) (common.Address, error) { + opts := &bind.CallOpts{From: service.bfsAuth.From} + ret0, err := service.bfs.Readlink(opts, absolutePath) + if err != nil { + return common.Address{}, fmt.Errorf("service Readlink failed: %+v", err) + } + return ret0, err +} + +// func (service *Service) Touch(absolutePath string, fileType string) (int64, error) { +// ret0, _, _, err := service.bfs.Touch(service.bfsAuth, absolutePath, fileType) +// if err != nil { +// return precompiled.DefaultErrorCode, fmt.Errorf("service Touch failed: %+v", err) +// } +// return int64(ret0), err +// } + +// func (service *Service) AsyncTouch(handler func(*types.Receipt, error), absolutePath string, fileType string) (*types.Transaction, error) { +// opts := &bind.CallOpts{From: service.bfsAuth.From} +// return service.bfs.AsyncTouch(handler, opts, absolutePath, fileType) +// } + +// func (service *Service) RebuildBfs() (*big.Int, error) { +// opts := &bind.CallOpts{From: service.bfsAuth.From} +// ret0, _, _, err := service.bfs.RebuildBfs(opts) +// if err != nil { +// return common.Address{}, fmt.Errorf("service RebuildBfs failed: %+v", err) +// } +// return ret0, err +// } + +// func (service *Service) AsyncRebuildBfs(handler func(*types.Receipt, error)) (*types.Transaction, error) { +// opts := &bind.CallOpts{From: service.bfsAuth.From} +// return service.bfs.AsyncRebuildBfs(handler, opts) +// } + + diff --git a/precompiled/bfs/bfs_service_test.go b/precompiled/bfs/bfs_service_test.go new file mode 100644 index 00000000..df505362 --- /dev/null +++ b/precompiled/bfs/bfs_service_test.go @@ -0,0 +1,265 @@ +package bfs + +import ( + "context" + "encoding/hex" + "os" + "testing" + "fmt" + "math/big" + "reflect" + "time" + "strings" + + "github.com/FISCO-BCOS/go-sdk/client" + "github.com/FISCO-BCOS/go-sdk/core/types" + "github.com/FISCO-BCOS/go-sdk/precompiled" + // "github.com/ethereum/go-ethereum/common" +) + +const ( + standardOutput = 0 + timeout = 1 * time.Second + name = "hello_v11" + version = "11.0" + address = "0xc92ad282ba7868b032341a3921b3635b0c45de74" + testABI = `[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"get","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"n","type":"string"}],"name":"set","outputs":[],"stateMutability":"nonpayable","type":"function"}]` + absolutePath_link = "/testlink" +) + +func getClient(t *testing.T) *client.Client { + privateKey, _ := hex.DecodeString("145e247e170ba3afd6ae97e88f00dbc976c2345d511b0f6713355d19d8b80b58") + config := &client.Config{IsSMCrypto: false, GroupID: "group0", + PrivateKey: privateKey, Host: "127.0.0.1", Port: 20200, TLSCaFile: "./ca.crt", TLSKeyFile: "./sdk.key", TLSCertFile: "./sdk.crt"} + c, err := client.DialContext(context.Background(), config) + if err != nil { + t.Fatalf("Dial to %s:%d failed of %v", config.Host, config.Port, err) + } + return c +} + +func getService(t *testing.T) { + c := getClient(t) + newService, err := NewBfsService(c) + if err != nil { + t.Fatalf("init CnsService failed: %+v", err) + } + service = newService +} + +var ( + service *Service + channel = make(chan int) +) + +func TestMain(m *testing.M) { + getService(&testing.T{}) + exitCode := m.Run() + os.Exit(exitCode) +} + +func TestList0(t *testing.T) { + absolutePath := "/sys/bfs" + testInfo := BfsInfo{"bfs", "link", []string{"000000000000000000000000000000000000100e"} } + + ret0, ret1, err := service.List0(absolutePath) + if err != nil { + t.Fatalf("Service List0 failed: %+v\n", err) + } + + if ret0!=standardOutput || ret1[0].FileName != testInfo.FileName || ret1[0].FileType != testInfo.FileType || reflect.DeepEqual(ret1[0].Ext[:len(testInfo.Ext)], testInfo.Ext)==false{ + t.Fatalf("TestList0 failed, the ret1 %v is inconsistent with \"%v\"", ret1, testInfo) + } + + t.Logf("TestList0 ret0:%v, ret1:%v", ret0, ret1) +} + +func TestList(t *testing.T) { + absolutePath := "/sys" + offset := big.NewInt(2) + limit := big.NewInt(1) + testInfo := BfsInfo{"bfs", "link", []string{"0","0"} } + + ret0, ret1, err := service.List(absolutePath,offset,limit) + if err != nil { + t.Fatalf("Service List failed: %+v\n", err) + } + + if ret1[0].FileName != testInfo.FileName || ret1[0].FileType != testInfo.FileType || reflect.DeepEqual(ret1[0].Ext[:len(testInfo.Ext)], testInfo.Ext)==false{ + t.Fatalf("TestList failed, the ret1 %v is inconsistent with \"%v\"", ret1, testInfo) + } + + t.Logf("TestList ret0:%v, ret1:%v", ret0, ret1) +} + +func TestMkdir(t *testing.T) { + absolutePath := "/apps/testBfsv0" + + ret0, err := service.Mkdir(absolutePath) + if err != nil { + t.Fatalf("Service Mkdir failed: %+v\n", err) + } + + if ret0 != standardOutput { + t.Fatalf("TestList0 failed, the ret0 %v is inconsistent with \"%v\"", ret0, standardOutput) + } + + t.Logf("TestList0 ret0:%v", ret0) +} + +func TestAsyncMkdir(t *testing.T) { + absolutePath := "/apps/testBfsv1" + + handler := func(receipt *types.Receipt, err error) { + if err != nil { + t.Fatalf("receive receipt failed, %v\n", err) + } + var bigNum *big.Int + bigNum, err = precompiled.ParseBigIntFromOutput(receipt) + if err != nil { + t.Fatalf("parseReturnValue failed, err: %v\n", err) + } + result, err := precompiled.BigIntToInt64(bigNum) + if err != nil { + t.Fatalf("%v\n", err) + } + if result != 0 { + t.Fatalf("TestAsyncMkdir failed, the result \"%v\" is inconsistent with \"0\"", result) + } + t.Logf("result: %d\n", result) + channel <- 0 + } + + _, err := service.AsyncMkdir(handler, absolutePath) + if err != nil { + t.Fatalf("remove data failed: %v", err) + } + select { + case <-channel: + return + case <-time.After(timeout): + t.Fatal("timeout") + } +} + +func TestLink(t *testing.T) { + ret0, err := service.Link(absolutePath_link,address, testABI) + if err != nil { + t.Fatalf("Service Link failed: %+v\n", err) + } + + if ret0 != standardOutput { + t.Fatalf("TestLink failed, the ret0 %v is inconsistent with \"%v\"", ret0, standardOutput) + } + + t.Logf("TestLink ret0:%v", ret0) +} + +func TestAsyncLink(t *testing.T) { + handler := func(receipt *types.Receipt, err error) { + if err != nil { + t.Fatalf("receive receipt failed, %v\n", err) + } + var bigNum *big.Int + bigNum, err = precompiled.ParseBigIntFromOutput(receipt) + if err != nil { + t.Fatalf("parseReturnValue failed, err: %v\n", err) + } + result, err := precompiled.BigIntToInt64(bigNum) + if err != nil { + t.Fatalf("%v\n", err) + } + if result != 0 { + t.Fatalf("TestAsyncLink failed, the result \"%v\" is inconsistent with \"0\"", result) + } + t.Logf("result: %d\n", result) + channel <- 0 + } + + _, err := service.AsyncLink(handler,absolutePath_link,address, testABI) + if err != nil { + t.Fatalf("remove data failed: %v", err) + } + select { + case <-channel: + return + case <-time.After(timeout): + t.Fatal("timeout") + } +} + +func TestLink0(t *testing.T) { + ret0, err := service.Link0(name, version, address, testABI) + if err != nil { + t.Fatalf("Service Link0 failed: %+v\n", err) + } + + if ret0 != standardOutput { + t.Fatalf("TestLink0 failed, the ret0 %v is inconsistent with \"%v\"", ret0, standardOutput) + } + + t.Logf("TestLink0 ret0:%v", ret0) +} + +func TestAsyncLink0(t *testing.T) { + handler := func(receipt *types.Receipt, err error) { + if err != nil { + t.Fatalf("receive receipt failed, %v\n", err) + } + var bigNum *big.Int + bigNum, err = precompiled.ParseBigIntFromOutput(receipt) + if err != nil { + t.Fatalf("parseReturnValue failed, err: %v\n", err) + } + result, err := precompiled.BigIntToInt64(bigNum) + if err != nil { + t.Fatalf("%v\n", err) + } + if result != 0 { + t.Fatalf("TestAsyncLink0 failed, the result \"%v\" is inconsistent with \"0\"", result) + } + t.Logf("result: %d\n", result) + channel <- 0 + } + + _, err := service.AsyncLink0(handler, name, version, address, testABI) + if err != nil { + t.Fatalf("remove data failed: %v", err) + } + select { + case <-channel: + return + case <-time.After(timeout): + t.Fatal("timeout") + } +} + +func TestReadlink(t *testing.T) { + ret0, err := service.Readlink("/apps"+absolutePath_link) + if err != nil { + t.Fatalf("Service Link0 failed: %+v\n", err) + } + fmt.Println("ret0",ret0) + + if strings.ToLower(ret0.Hex()) != address { + t.Fatalf("TestLink0 failed, the ret0 %v is inconsistent with \"%v\"", ret0, address) + } + + t.Logf("TestLink0 ret0:%v", ret0) +} + +// func TestTouch(t *testing.T) { +// absolutePath:="/apps/sbw" +// fileType:="txt" +// ret0, err := service.Touch(absolutePath, fileType) +// if err != nil { +// t.Fatalf("Service Link0 failed: %+v\n", err) +// } +// fmt.Println("ret0",ret0) + +// if ret0 != standardOutput { +// t.Fatalf("TestTouch failed, the ret0 %v is inconsistent with \"%v\"", ret0, standardOutput) +// } + +// t.Logf("TestTouch ret0:%v", ret0) +// } \ No newline at end of file diff --git a/precompiled/crud/crud_service.go b/precompiled/crud/crud_service.go index 41ed0234..3a33002d 100644 --- a/precompiled/crud/crud_service.go +++ b/precompiled/crud/crud_service.go @@ -263,3 +263,15 @@ func parseReturnValue(receipt *types.Receipt, name string) (int64, error) { } return errorCode, errorCodeToError(errorCode) } + +func (service *Service) AppendColumns(path string, newColumns []string) (int64, error) { + _, receipt, err := service.tableFactory.AppendColumns(service.crudAuth, path, newColumns) + if err != nil { + return precompiled.DefaultErrorCode, fmt.Errorf("CRUDService AppendColumns failed: %v", err) + } + return parseReturnValue(receipt, "createTable") +} + +func (service *Service) AsyncAppendColumns(handler func(*types.Receipt, error), path string, newColumns []string) (*types.Transaction, error) { + return service.tableFactory.AsyncAppendColumns(handler, service.crudAuth, path, newColumns) +} diff --git a/precompiled/crud/crud_service_test.go b/precompiled/crud/crud_service_test.go index b8cc25a1..604d8223 100644 --- a/precompiled/crud/crud_service_test.go +++ b/precompiled/crud/crud_service_test.go @@ -16,6 +16,7 @@ import ( const ( tableName = "t_test9" tableNameForAsync = "t_test_async9" + tablePath = "/tables/t_test9" key = "name" keyAsync = "name_async" timeout = 1 * time.Second @@ -292,3 +293,51 @@ func TestDesc(t *testing.T) { t.Logf("keyFiled is:%s\n", tableInfo.KeyColumn) t.Logf("valueField is:%s\n", tableInfo.ValueColumns[0]) } + +func TestAppendColumns(t *testing.T) { + newColumns := []string{"test0", "test1"} + + result, err := service.AppendColumns(tablePath, newColumns) + if err != nil { + t.Fatalf("create AppendColumns failed: %v", err) + } + if result != 0 { + t.Fatalf("TestAppendColumns failed, the result \"%v\" is inconsistent with \"0\"", result) + } + t.Logf("result: %d\n", result) +} + +func TestAsyncAppendColumns(t *testing.T) { + newColumns := []string{"test0", "test1"} + + handler := func(receipt *types.Receipt, err error) { + if err != nil { + t.Fatalf("receive receipt failed, %v\n", err) + } + var bigNum *big.Int + bigNum, err = precompiled.ParseBigIntFromOutput(receipt) + if err != nil { + t.Fatalf("parseReturnValue failed, err: %v\n", err) + } + result, err := precompiled.BigIntToInt64(bigNum) + if err != nil { + t.Fatalf("%v\n", err) + } + if result != 0 { + t.Fatalf("TestAsyncAppendColumns failed, the result \"%v\" is inconsistent with \"0\"", result) + } + t.Logf("result: %d\n", result) + channel <- 0 + } + + _, err := service.AsyncAppendColumns(handler, tablePath, newColumns) + if err != nil { + t.Fatalf("AsyncAppendColumns failed: %v", err) + } + select { + case <-channel: + return + case <-time.After(timeout): + t.Fatal("timeout") + } +} diff --git a/precompiled/sharding/sharding.go b/precompiled/sharding/sharding.go new file mode 100644 index 00000000..5b46083a --- /dev/null +++ b/precompiled/sharding/sharding.go @@ -0,0 +1,306 @@ +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package sharding + +import ( + "math/big" + "strings" + + "github.com/FISCO-BCOS/go-sdk/abi" + "github.com/FISCO-BCOS/go-sdk/abi/bind" + "github.com/FISCO-BCOS/go-sdk/core/types" + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/common" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = big.NewInt + _ = strings.NewReader + _ = ethereum.NotFound + _ = abi.U256 + _ = bind.Bind + _ = common.Big1 +) + +// ShardingABI is the input ABI used to generate the binding from. +const ShardingABI = "[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"absolutePath\",\"type\":\"string\"}],\"name\":\"getContractShard\",\"outputs\":[{\"internalType\":\"int256\",\"name\":\"\",\"type\":\"int256\"},{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"shardName\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"_address\",\"type\":\"string\"}],\"name\":\"linkShard\",\"outputs\":[{\"internalType\":\"int256\",\"name\":\"\",\"type\":\"int256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"shardName\",\"type\":\"string\"}],\"name\":\"makeShard\",\"outputs\":[{\"internalType\":\"int256\",\"name\":\"\",\"type\":\"int256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" + +// ShardingBin is the compiled bytecode used for deploying new contracts. +var ShardingBin = "0x608060405234801561001057600080fd5b5061042c806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80631d82d998146100465780639c1284bc14610076578063b7ede6cb146100a7575b600080fd5b610060600480360381019061005b9190610249565b6100d7565b60405161006d91906102ab565b60405180910390f35b610090600480360381019061008b9190610249565b6100de565b60405161009e92919061034e565b60405180910390f35b6100c160048036038101906100bc919061037e565b6100e7565b6040516100ce91906102ab565b60405180910390f35b6000919050565b60006060915091565b600092915050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6101568261010d565b810181811067ffffffffffffffff821117156101755761017461011e565b5b80604052505050565b60006101886100ef565b9050610194828261014d565b919050565b600067ffffffffffffffff8211156101b4576101b361011e565b5b6101bd8261010d565b9050602081019050919050565b82818337600083830152505050565b60006101ec6101e784610199565b61017e565b90508281526020810184848401111561020857610207610108565b5b6102138482856101ca565b509392505050565b600082601f8301126102305761022f610103565b5b81356102408482602086016101d9565b91505092915050565b60006020828403121561025f5761025e6100f9565b5b600082013567ffffffffffffffff81111561027d5761027c6100fe565b5b6102898482850161021b565b91505092915050565b6000819050919050565b6102a581610292565b82525050565b60006020820190506102c0600083018461029c565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103005780820151818401526020810190506102e5565b8381111561030f576000848401525b50505050565b6000610320826102c6565b61032a81856102d1565b935061033a8185602086016102e2565b6103438161010d565b840191505092915050565b6000604082019050610363600083018561029c565b81810360208301526103758184610315565b90509392505050565b60008060408385031215610395576103946100f9565b5b600083013567ffffffffffffffff8111156103b3576103b26100fe565b5b6103bf8582860161021b565b925050602083013567ffffffffffffffff8111156103e0576103df6100fe565b5b6103ec8582860161021b565b915050925092905056fea2646970667358221220baad85981073d50ee009743acebf2bece8d1deb0d1966340563e3341bedf4da464736f6c634300080b0033" + +// DeploySharding deploys a new contract, binding an instance of Sharding to it. +func DeploySharding(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Receipt, *Sharding, error) { + parsed, err := abi.JSON(strings.NewReader(ShardingABI)) + if err != nil { + return common.Address{}, nil, nil, err + } + + address, receipt, contract, err := bind.DeployContract(auth, parsed, common.FromHex(ShardingBin), backend) + if err != nil { + return common.Address{}, nil, nil, err + } + return address, receipt, &Sharding{ShardingCaller: ShardingCaller{contract: contract}, ShardingTransactor: ShardingTransactor{contract: contract}, ShardingFilterer: ShardingFilterer{contract: contract}}, nil +} + +func AsyncDeploySharding(auth *bind.TransactOpts, handler func(*types.Receipt, error), backend bind.ContractBackend) (*types.Transaction, error) { + parsed, err := abi.JSON(strings.NewReader(ShardingABI)) + if err != nil { + return nil, err + } + + tx, err := bind.AsyncDeployContract(auth, handler, parsed, common.FromHex(ShardingBin), backend) + if err != nil { + return nil, err + } + return tx, nil +} + +// Sharding is an auto generated Go binding around a Solidity contract. +type Sharding struct { + ShardingCaller // Read-only binding to the contract + ShardingTransactor // Write-only binding to the contract + ShardingFilterer // Log filterer for contract events +} + +// ShardingCaller is an auto generated read-only Go binding around a Solidity contract. +type ShardingCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// ShardingTransactor is an auto generated write-only Go binding around a Solidity contract. +type ShardingTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// ShardingFilterer is an auto generated log filtering Go binding around a Solidity contract events. +type ShardingFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// ShardingSession is an auto generated Go binding around a Solidity contract, +// with pre-set call and transact options. +type ShardingSession struct { + Contract *Sharding // 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 +} + +// ShardingCallerSession is an auto generated read-only Go binding around a Solidity contract, +// with pre-set call options. +type ShardingCallerSession struct { + Contract *ShardingCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// ShardingTransactorSession is an auto generated write-only Go binding around a Solidity contract, +// with pre-set transact options. +type ShardingTransactorSession struct { + Contract *ShardingTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// ShardingRaw is an auto generated low-level Go binding around a Solidity contract. +type ShardingRaw struct { + Contract *Sharding // Generic contract binding to access the raw methods on +} + +// ShardingCallerRaw is an auto generated low-level read-only Go binding around a Solidity contract. +type ShardingCallerRaw struct { + Contract *ShardingCaller // Generic read-only contract binding to access the raw methods on +} + +// ShardingTransactorRaw is an auto generated low-level write-only Go binding around a Solidity contract. +type ShardingTransactorRaw struct { + Contract *ShardingTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewSharding creates a new instance of Sharding, bound to a specific deployed contract. +func NewSharding(address common.Address, backend bind.ContractBackend) (*Sharding, error) { + contract, err := bindSharding(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &Sharding{ShardingCaller: ShardingCaller{contract: contract}, ShardingTransactor: ShardingTransactor{contract: contract}, ShardingFilterer: ShardingFilterer{contract: contract}}, nil +} + +// NewShardingCaller creates a new read-only instance of Sharding, bound to a specific deployed contract. +func NewShardingCaller(address common.Address, caller bind.ContractCaller) (*ShardingCaller, error) { + contract, err := bindSharding(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &ShardingCaller{contract: contract}, nil +} + +// NewShardingTransactor creates a new write-only instance of Sharding, bound to a specific deployed contract. +func NewShardingTransactor(address common.Address, transactor bind.ContractTransactor) (*ShardingTransactor, error) { + contract, err := bindSharding(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &ShardingTransactor{contract: contract}, nil +} + +// NewShardingFilterer creates a new log filterer instance of Sharding, bound to a specific deployed contract. +func NewShardingFilterer(address common.Address, filterer bind.ContractFilterer) (*ShardingFilterer, error) { + contract, err := bindSharding(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &ShardingFilterer{contract: contract}, nil +} + +// bindSharding binds a generic wrapper to an already deployed contract. +func bindSharding(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(ShardingABI)) + 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 (_Sharding *ShardingRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _Sharding.Contract.ShardingCaller.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 (_Sharding *ShardingRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, *types.Receipt, error) { + return _Sharding.Contract.ShardingTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Sharding *ShardingRaw) TransactWithResult(opts *bind.TransactOpts, result interface{}, method string, params ...interface{}) (*types.Transaction, *types.Receipt, error) { + return _Sharding.Contract.ShardingTransactor.contract.TransactWithResult(opts, result, 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 (_Sharding *ShardingCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _Sharding.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 (_Sharding *ShardingTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, *types.Receipt, error) { + return _Sharding.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Sharding *ShardingTransactorRaw) TransactWithResult(opts *bind.TransactOpts, result interface{}, method string, params ...interface{}) (*types.Transaction, *types.Receipt, error) { + return _Sharding.Contract.contract.TransactWithResult(opts, result, method, params...) +} + +// GetContractShard is a free data retrieval call binding the contract method 0x9c1284bc. +// +// Solidity: function getContractShard(string absolutePath) constant returns(int256, string) +func (_Sharding *ShardingCaller) GetContractShard(opts *bind.CallOpts, absolutePath string) (*big.Int, string, error) { + var ( + ret0 = new(*big.Int) + ret1 = new(string) + ) + out := &[]interface{}{ + ret0, + ret1, + } + err := _Sharding.contract.Call(opts, out, "getContractShard", absolutePath) + return *ret0, *ret1, err +} + +// GetContractShard is a free data retrieval call binding the contract method 0x9c1284bc. +// +// Solidity: function getContractShard(string absolutePath) constant returns(int256, string) +func (_Sharding *ShardingSession) GetContractShard(absolutePath string) (*big.Int, string, error) { + return _Sharding.Contract.GetContractShard(&_Sharding.CallOpts, absolutePath) +} + +// GetContractShard is a free data retrieval call binding the contract method 0x9c1284bc. +// +// Solidity: function getContractShard(string absolutePath) constant returns(int256, string) +func (_Sharding *ShardingCallerSession) GetContractShard(absolutePath string) (*big.Int, string, error) { + return _Sharding.Contract.GetContractShard(&_Sharding.CallOpts, absolutePath) +} + +// LinkShard is a paid mutator transaction binding the contract method 0xb7ede6cb. +// +// Solidity: function linkShard(string shardName, string _address) returns(int256) +func (_Sharding *ShardingTransactor) LinkShard(opts *bind.TransactOpts, shardName string, _address string) (*big.Int, *types.Transaction, *types.Receipt, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + transaction, receipt, err := _Sharding.contract.TransactWithResult(opts, out, "linkShard", shardName, _address) + return *ret0, transaction, receipt, err +} + +func (_Sharding *ShardingTransactor) AsyncLinkShard(handler func(*types.Receipt, error), opts *bind.TransactOpts, shardName string, _address string) (*types.Transaction, error) { + return _Sharding.contract.AsyncTransact(opts, handler, "linkShard", shardName, _address) +} + +// LinkShard is a paid mutator transaction binding the contract method 0xb7ede6cb. +// +// Solidity: function linkShard(string shardName, string _address) returns(int256) +func (_Sharding *ShardingSession) LinkShard(shardName string, _address string) (*big.Int, *types.Transaction, *types.Receipt, error) { + return _Sharding.Contract.LinkShard(&_Sharding.TransactOpts, shardName, _address) +} + +func (_Sharding *ShardingSession) AsyncLinkShard(handler func(*types.Receipt, error), shardName string, _address string) (*types.Transaction, error) { + return _Sharding.Contract.AsyncLinkShard(handler, &_Sharding.TransactOpts, shardName, _address) +} + +// LinkShard is a paid mutator transaction binding the contract method 0xb7ede6cb. +// +// Solidity: function linkShard(string shardName, string _address) returns(int256) +func (_Sharding *ShardingTransactorSession) LinkShard(shardName string, _address string) (*big.Int, *types.Transaction, *types.Receipt, error) { + return _Sharding.Contract.LinkShard(&_Sharding.TransactOpts, shardName, _address) +} + +func (_Sharding *ShardingTransactorSession) AsyncLinkShard(handler func(*types.Receipt, error), shardName string, _address string) (*types.Transaction, error) { + return _Sharding.Contract.AsyncLinkShard(handler, &_Sharding.TransactOpts, shardName, _address) +} + +// MakeShard is a paid mutator transaction binding the contract method 0x1d82d998. +// +// Solidity: function makeShard(string shardName) returns(int256) +func (_Sharding *ShardingTransactor) MakeShard(opts *bind.TransactOpts, shardName string) (*big.Int, *types.Transaction, *types.Receipt, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + transaction, receipt, err := _Sharding.contract.TransactWithResult(opts, out, "makeShard", shardName) + return *ret0, transaction, receipt, err +} + +func (_Sharding *ShardingTransactor) AsyncMakeShard(handler func(*types.Receipt, error), opts *bind.TransactOpts, shardName string) (*types.Transaction, error) { + return _Sharding.contract.AsyncTransact(opts, handler, "makeShard", shardName) +} + +// MakeShard is a paid mutator transaction binding the contract method 0x1d82d998. +// +// Solidity: function makeShard(string shardName) returns(int256) +func (_Sharding *ShardingSession) MakeShard(shardName string) (*big.Int, *types.Transaction, *types.Receipt, error) { + return _Sharding.Contract.MakeShard(&_Sharding.TransactOpts, shardName) +} + +func (_Sharding *ShardingSession) AsyncMakeShard(handler func(*types.Receipt, error), shardName string) (*types.Transaction, error) { + return _Sharding.Contract.AsyncMakeShard(handler, &_Sharding.TransactOpts, shardName) +} + +// MakeShard is a paid mutator transaction binding the contract method 0x1d82d998. +// +// Solidity: function makeShard(string shardName) returns(int256) +func (_Sharding *ShardingTransactorSession) MakeShard(shardName string) (*big.Int, *types.Transaction, *types.Receipt, error) { + return _Sharding.Contract.MakeShard(&_Sharding.TransactOpts, shardName) +} + +func (_Sharding *ShardingTransactorSession) AsyncMakeShard(handler func(*types.Receipt, error), shardName string) (*types.Transaction, error) { + return _Sharding.Contract.AsyncMakeShard(handler, &_Sharding.TransactOpts, shardName) +} diff --git a/precompiled/sharding/sharding_service.go b/precompiled/sharding/sharding_service.go new file mode 100644 index 00000000..a3e02238 --- /dev/null +++ b/precompiled/sharding/sharding_service.go @@ -0,0 +1,63 @@ +package sharding + +import ( + "fmt" + + "github.com/FISCO-BCOS/go-sdk/abi/bind" + "github.com/FISCO-BCOS/go-sdk/client" + "github.com/FISCO-BCOS/go-sdk/core/types" + "github.com/FISCO-BCOS/go-sdk/precompiled" + "github.com/ethereum/go-ethereum/common" +) + +type Service struct { + sharding *Sharding + shardingAuth *bind.TransactOpts + client *client.Client +} + +// contract address +var shardingPrecompileAddress = common.HexToAddress("0000000000000000000000000000000000001010") + +// NewCnsService returns ptr of Service +func NewShardingService(client *client.Client) (*Service, error) { + instance, err := NewSharding(shardingPrecompileAddress, client) + if err != nil { + return nil, fmt.Errorf("construct Service failed: %+v", err) + } + auth := client.GetTransactOpts() + return &Service{sharding: instance, shardingAuth: auth, client: client}, nil +} + +func (service *Service) GetContractShard(absolutePath string) (int64, string, error) { + opts := &bind.CallOpts{From: service.shardingAuth.From} + ret0, ret1, err := service.sharding.GetContractShard(opts, absolutePath) + if err != nil { + return precompiled.DefaultErrorCode, ret1, fmt.Errorf("service GetContractShard failed: %+v", err) + } + return ret0.Int64(), ret1, err +} + +func (service *Service) MakeShard(shardName string) (int64, *types.Transaction, *types.Receipt, error) { + ret0, ret1, ret2, err := service.sharding.MakeShard(service.shardingAuth, shardName) + if err != nil { + return precompiled.DefaultErrorCode, nil, nil, fmt.Errorf("service MakeShard failed: %+v", err) + } + return ret0.Int64(), ret1, ret2, err +} + +func (service *Service) AsyncMakeShard(handler func(*types.Receipt, error), shardName string) (*types.Transaction, error) { + return service.sharding.AsyncMakeShard(handler, service.shardingAuth, shardName) +} + +func (service *Service) LinkShard(shardName string, _address string) (int64, *types.Transaction, *types.Receipt, error) { + ret0, ret1, ret2, err := service.sharding.LinkShard(service.shardingAuth, shardName, _address) + if err != nil { + return precompiled.DefaultErrorCode, nil, nil, fmt.Errorf("service LinkShard failed: %+v", err) + } + return ret0.Int64(), ret1, ret2, err +} + +func (service *Service) AsyncLinkShard(handler func(*types.Receipt, error), shardName string, _address string) (*types.Transaction, error) { + return service.sharding.AsyncLinkShard(handler, service.shardingAuth, shardName, _address) +} \ No newline at end of file diff --git a/precompiled/sharding/sharding_service_test.go b/precompiled/sharding/sharding_service_test.go new file mode 100644 index 00000000..00d95c88 --- /dev/null +++ b/precompiled/sharding/sharding_service_test.go @@ -0,0 +1,162 @@ +package sharding + +import ( + "context" + "encoding/hex" + "os" + "testing" + // "fmt" + "time" + "math/big" + "github.com/FISCO-BCOS/go-sdk/client" + "github.com/FISCO-BCOS/go-sdk/core/types" + "github.com/FISCO-BCOS/go-sdk/precompiled" + // "github.com/ethereum/go-ethereum/common" +) + +const ( + standardOutput = 0 + timeout = 1 * time.Second + name = "hello_v11" + version = "11.0" + address = "0xc92ad282ba7868b032341a3921b3635b0c45de74" + addressAsync = "0x272d69cfdb321d147f63fdfa9126c4ad1969265a" + shardName = "shardName" + shardNameAsync = "shardName_async" +) + +func getClient(t *testing.T) *client.Client { + privateKey, _ := hex.DecodeString("145e247e170ba3afd6ae97e88f00dbc976c2345d511b0f6713355d19d8b80b58") + config := &client.Config{IsSMCrypto: false, GroupID: "group0", + PrivateKey: privateKey, Host: "127.0.0.1", Port: 20200, TLSCaFile: "./ca.crt", TLSKeyFile: "./sdk.key", TLSCertFile: "./sdk.crt"} + c, err := client.DialContext(context.Background(), config) + if err != nil { + t.Fatalf("Dial to %s:%d failed of %v", config.Host, config.Port, err) + } + return c +} + +func getService(t *testing.T) { + c := getClient(t) + newService, err := NewShardingService(c) + if err != nil { + t.Fatalf("init CnsService failed: %+v", err) + } + service = newService +} + +var ( + service *Service + channel = make(chan int) +) + +func TestMain(m *testing.M) { + getService(&testing.T{}) + exitCode := m.Run() + os.Exit(exitCode) +} + +func TestMakeShard(t *testing.T) { + ret0, _, _, err := service.MakeShard(shardName) + if err != nil { + t.Fatalf("Service MakeShard failed: %+v\n", err) + } + + if ret0 != standardOutput{ + t.Fatalf("TestMakeShard failed, the ret0 %v is inconsistent with \"%v\"", ret0, standardOutput) + } + + t.Logf("TestMakeShard ret0:%v", ret0) +} + +func TestAsyncMakeShard(t *testing.T) { + handler := func(receipt *types.Receipt, err error) { + if err != nil { + t.Fatalf("receive receipt failed, %v\n", err) + } + var bigNum *big.Int + bigNum, err = precompiled.ParseBigIntFromOutput(receipt) + if err != nil { + t.Fatalf("parseReturnValue failed, err: %v\n", err) + } + result, err := precompiled.BigIntToInt64(bigNum) + if err != nil { + t.Fatalf("%v\n", err) + } + if result != 0 { + t.Fatalf("TestAsyncMakeShard failed, the result \"%v\" is inconsistent with \"0\"", result) + } + t.Logf("result: %d\n", result) + channel <- 0 + } + + _, err := service.AsyncMakeShard(handler, shardNameAsync) + if err != nil { + t.Fatalf("remove data failed: %v", err) + } + select { + case <-channel: + return + case <-time.After(timeout): + t.Fatal("timeout") + } +} + +func TestLinkShard(t *testing.T) { + ret0, _, _, err := service.LinkShard(shardName, address) + if err != nil { + t.Fatalf("Service LinkShard failed: %+v\n", err) + } + + if ret0 != standardOutput{ + t.Fatalf("TestLinkShard failed, the ret0 %v is inconsistent with \"%v\"", ret0, standardOutput) + } + + t.Logf("TestMakeShard ret0:%v", ret0) +} + +func TestAsyncLinkShard(t *testing.T) { + handler := func(receipt *types.Receipt, err error) { + if err != nil { + t.Fatalf("receive receipt failed, %v\n", err) + } + var bigNum *big.Int + bigNum, err = precompiled.ParseBigIntFromOutput(receipt) + if err != nil { + t.Fatalf("parseReturnValue failed, err: %v\n", err) + } + result, err := precompiled.BigIntToInt64(bigNum) + if err != nil { + t.Fatalf("%v\n", err) + } + if result != 0 { + t.Fatalf("TestAsyncLinkShard failed, the result \"%v\" is inconsistent with \"0\"", result) + } + t.Logf("result: %d\n", result) + channel <- 0 + } + + _, err := service.AsyncLinkShard(handler, shardNameAsync, addressAsync) + if err != nil { + t.Fatalf("remove data failed: %v", err) + } + select { + case <-channel: + return + case <-time.After(timeout): + t.Fatal("timeout") + } +} + +func TestGetContractShard(t *testing.T) { + ret0, ret1, err := service.GetContractShard(address) + if err != nil { + t.Fatalf("Service GetContractShard failed: %+v\n", err) + } + + if ret0 != standardOutput{ + t.Fatalf("TestGetContractShard failed, the ret0 %v is inconsistent with \"%v\"", ret0, standardOutput) + } + + t.Logf("TestGetContractShard ret0:%v, ret0:%v", ret0, ret1) +} \ No newline at end of file From fda56e167d2846ffbb2f6da0e43f04e605dc92c7 Mon Sep 17 00:00:00 2001 From: subowei <954075159@qq.com> Date: Wed, 9 Aug 2023 14:14:51 +0800 Subject: [PATCH 2/2] modify input in TestAsyncAppendColumns function --- precompiled/crud/crud_service_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/precompiled/crud/crud_service_test.go b/precompiled/crud/crud_service_test.go index 604d8223..287e89d7 100644 --- a/precompiled/crud/crud_service_test.go +++ b/precompiled/crud/crud_service_test.go @@ -308,7 +308,7 @@ func TestAppendColumns(t *testing.T) { } func TestAsyncAppendColumns(t *testing.T) { - newColumns := []string{"test0", "test1"} + newColumns := []string{"test2", "test3"} handler := func(receipt *types.Receipt, err error) { if err != nil {