diff --git a/cmd/tpodserver/registry.go b/cmd/tpodserver/registry.go index 471016e9..0421eb2d 100644 --- a/cmd/tpodserver/registry.go +++ b/cmd/tpodserver/registry.go @@ -179,7 +179,7 @@ var registerCmd = &cobra.Command{ tx, err := registry.RegisterProvider(providerAuth, cid.String()) if err != nil { - return err + return fmt.Errorf("Could not register Provider: %v", err) } prices, err := resource.GetTablesPrices(pricingTables) diff --git a/cmd/trustedpods/deploy.go b/cmd/trustedpods/deploy.go index 0e0820d7..db282b04 100644 --- a/cmd/trustedpods/deploy.go +++ b/cmd/trustedpods/deploy.go @@ -45,6 +45,10 @@ func fetchAndFilterProviders(ipfs *rpc.HttpApi, ethClient *ethclient.Client) (pu return nil, err } + if len(tables) == 0 { + return nil, fmt.Errorf("Marketplace is empty! are you sure you are connected to the right contract?") + } + filter, err := getRegistryTableFilter() if err != nil { return nil, err @@ -55,6 +59,11 @@ func fetchAndFilterProviders(ipfs *rpc.HttpApi, ethClient *ethclient.Client) (pu return nil, fmt.Errorf("no table found by filter") } + err = PrintTableInfo(filteredTables, ethClient, registryContract) + if err != nil { + return nil, err + } + availableProviders, err := publisher.GetProviderHostInfos(ipfs, ethClient, registryContract, filteredTables) if err != nil { return nil, err @@ -65,6 +74,8 @@ func fetchAndFilterProviders(ipfs *rpc.HttpApi, ethClient *ethclient.Client) (pu return nil, err } + PrintProvidersInfo(availableProviders) + return availableProviders, nil } diff --git a/cmd/trustedpods/registry.go b/cmd/trustedpods/registry.go index 02ea9b10..b2395380 100644 --- a/cmd/trustedpods/registry.go +++ b/cmd/trustedpods/registry.go @@ -14,6 +14,7 @@ import ( "github.com/comrade-coop/apocryph/pkg/publisher" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" ) @@ -66,31 +67,12 @@ var getTablesCmd = &cobra.Command{ } filteredTables := publisher.FilterPricingTables(tables, filter) - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"Id", "CPU", "RAM", "STORAGE", "BANDWIDTH EGRESS", "BANDWIDTH INGRESS", "CPU MODEL", "TEE TECHNOLOGY", "Providers"}) - for _, t := range filteredTables { - subscribers, err := publisher.GetPricingTableSubscribers(ethClient, registryContract, t.Id) - if err != nil { - return err - } - // if table has no subscribers skip printing it - if len(subscribers) == 0 { - continue - } - var subs string = "" - for _, subscriber := range subscribers { - subs = subs + subscriber.String() + "\n" - } - row := []string{t.Id.String(), t.CpuPrice.String(), t.RamPrice.String(), - t.StoragePrice.String(), t.BandwidthEgressPrice.String(), - t.BandwidthIngressPrice.String(), t.Cpumodel, t.TeeType, subs} - table.Append(row) - } if len(filteredTables) == 0 { return fmt.Errorf("no table found by given filter") } - table.Render() + + PrintTableInfo(filteredTables, ethClient, registryContract) allProviders, err := publisher.GetProviderHostInfos(ipfs, ethClient, registryContract, filteredTables) if err != nil { @@ -104,20 +86,50 @@ var getTablesCmd = &cobra.Command{ return fmt.Errorf("could not find providers with the given filter") } - infoTable := tablewriter.NewWriter(os.Stdout) - infoTable.SetHeader([]string{"Id", "Regions", "Addresses"}) - for id, info := range filteredInfos { - row := []string{id.Hex(), formatRegions(info.Regions), strings.Join(info.Multiaddrs, "\n")} - infoTable.Append(row) - } - infoTable.SetRowLine(true) - fmt.Printf("\nProviders:\n") - infoTable.Render() + PrintProvidersInfo(filteredInfos) return nil }, } +func PrintProvidersInfo(filteredInfos publisher.ProviderHostInfoList) { + infoTable := tablewriter.NewWriter(os.Stdout) + infoTable.SetHeader([]string{"Id", "Regions", "Addresses"}) + for id, info := range filteredInfos { + row := []string{id.Hex(), formatRegions(info.Regions), strings.Join(info.Multiaddrs, "\n")} + infoTable.Append(row) + } + infoTable.SetRowLine(true) + fmt.Printf("Providers:\n") + infoTable.Render() +} + +func PrintTableInfo(filteredTables publisher.PricingTableList, ethClient *ethclient.Client, registryContract common.Address) error { + table := tablewriter.NewWriter(os.Stdout) + + table.SetHeader([]string{"Id", "CPU", "RAM", "STORAGE", "BANDWIDTH EGRESS", "BANDWIDTH INGRESS", "CPU MODEL", "TEE TECHNOLOGY", "Providers"}) + for _, t := range filteredTables { + subscribers, err := publisher.GetPricingTableSubscribers(ethClient, registryContract, t.Id) + if err != nil { + return err + } + // if table has no subscribers skip printing it + if len(subscribers) == 0 { + continue + } + var subs string = "" + for _, subscriber := range subscribers { + subs = subs + subscriber.String() + "\n" + } + row := []string{t.Id.String(), t.CpuPrice.String(), t.RamPrice.String(), + t.StoragePrice.String(), t.BandwidthEgressPrice.String(), + t.BandwidthIngressPrice.String(), t.Cpumodel, t.TeeType, subs} + table.Append(row) + } + table.Render() + return nil +} + func formatRegions(regions []*pb.HostInfo_Region) string { result := "" for _, region := range regions { diff --git a/pkg/abi/IERC20.abi.go b/pkg/abi/IERC20.abi.go index ec9c872c..1ed492ae 100644 --- a/pkg/abi/IERC20.abi.go +++ b/pkg/abi/IERC20.abi.go @@ -31,7 +31,7 @@ var ( // IERC20MetaData contains all meta data concerning the IERC20 contract. var IERC20MetaData = &bind.MetaData{ - ABI: "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", + ABI: "[{\"type\":\"function\",\"name\":\"allowance\",\"inputs\":[{\"name\":\"owner\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"spender\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"approve\",\"inputs\":[{\"name\":\"spender\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"amount\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"balanceOf\",\"inputs\":[{\"name\":\"account\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"decimals\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint8\",\"internalType\":\"uint8\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"name\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"string\",\"internalType\":\"string\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"symbol\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"string\",\"internalType\":\"string\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"totalSupply\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"transfer\",\"inputs\":[{\"name\":\"to\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"amount\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"transferFrom\",\"inputs\":[{\"name\":\"from\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"to\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"amount\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"nonpayable\"},{\"type\":\"event\",\"name\":\"Approval\",\"inputs\":[{\"name\":\"owner\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"spender\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"Transfer\",\"inputs\":[{\"name\":\"from\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"to\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false}]", } // IERC20ABI is the input ABI used to generate the binding from. @@ -242,6 +242,99 @@ func (_IERC20 *IERC20CallerSession) BalanceOf(account common.Address) (*big.Int, return _IERC20.Contract.BalanceOf(&_IERC20.CallOpts, account) } +// Decimals is a free data retrieval call binding the contract method 0x313ce567. +// +// Solidity: function decimals() view returns(uint8) +func (_IERC20 *IERC20Caller) Decimals(opts *bind.CallOpts) (uint8, error) { + var out []interface{} + err := _IERC20.contract.Call(opts, &out, "decimals") + + if err != nil { + return *new(uint8), err + } + + out0 := *abi.ConvertType(out[0], new(uint8)).(*uint8) + + return out0, err + +} + +// Decimals is a free data retrieval call binding the contract method 0x313ce567. +// +// Solidity: function decimals() view returns(uint8) +func (_IERC20 *IERC20Session) Decimals() (uint8, error) { + return _IERC20.Contract.Decimals(&_IERC20.CallOpts) +} + +// Decimals is a free data retrieval call binding the contract method 0x313ce567. +// +// Solidity: function decimals() view returns(uint8) +func (_IERC20 *IERC20CallerSession) Decimals() (uint8, error) { + return _IERC20.Contract.Decimals(&_IERC20.CallOpts) +} + +// Name is a free data retrieval call binding the contract method 0x06fdde03. +// +// Solidity: function name() view returns(string) +func (_IERC20 *IERC20Caller) Name(opts *bind.CallOpts) (string, error) { + var out []interface{} + err := _IERC20.contract.Call(opts, &out, "name") + + if err != nil { + return *new(string), err + } + + out0 := *abi.ConvertType(out[0], new(string)).(*string) + + return out0, err + +} + +// Name is a free data retrieval call binding the contract method 0x06fdde03. +// +// Solidity: function name() view returns(string) +func (_IERC20 *IERC20Session) Name() (string, error) { + return _IERC20.Contract.Name(&_IERC20.CallOpts) +} + +// Name is a free data retrieval call binding the contract method 0x06fdde03. +// +// Solidity: function name() view returns(string) +func (_IERC20 *IERC20CallerSession) Name() (string, error) { + return _IERC20.Contract.Name(&_IERC20.CallOpts) +} + +// Symbol is a free data retrieval call binding the contract method 0x95d89b41. +// +// Solidity: function symbol() view returns(string) +func (_IERC20 *IERC20Caller) Symbol(opts *bind.CallOpts) (string, error) { + var out []interface{} + err := _IERC20.contract.Call(opts, &out, "symbol") + + if err != nil { + return *new(string), err + } + + out0 := *abi.ConvertType(out[0], new(string)).(*string) + + return out0, err + +} + +// Symbol is a free data retrieval call binding the contract method 0x95d89b41. +// +// Solidity: function symbol() view returns(string) +func (_IERC20 *IERC20Session) Symbol() (string, error) { + return _IERC20.Contract.Symbol(&_IERC20.CallOpts) +} + +// Symbol is a free data retrieval call binding the contract method 0x95d89b41. +// +// Solidity: function symbol() view returns(string) +func (_IERC20 *IERC20CallerSession) Symbol() (string, error) { + return _IERC20.Contract.Symbol(&_IERC20.CallOpts) +} + // TotalSupply is a free data retrieval call binding the contract method 0x18160ddd. // // Solidity: function totalSupply() view returns(uint256) @@ -275,65 +368,65 @@ func (_IERC20 *IERC20CallerSession) TotalSupply() (*big.Int, error) { // Approve is a paid mutator transaction binding the contract method 0x095ea7b3. // -// Solidity: function approve(address spender, uint256 value) returns(bool) -func (_IERC20 *IERC20Transactor) Approve(opts *bind.TransactOpts, spender common.Address, value *big.Int) (*types.Transaction, error) { - return _IERC20.contract.Transact(opts, "approve", spender, value) +// Solidity: function approve(address spender, uint256 amount) returns(bool) +func (_IERC20 *IERC20Transactor) Approve(opts *bind.TransactOpts, spender common.Address, amount *big.Int) (*types.Transaction, error) { + return _IERC20.contract.Transact(opts, "approve", spender, amount) } // Approve is a paid mutator transaction binding the contract method 0x095ea7b3. // -// Solidity: function approve(address spender, uint256 value) returns(bool) -func (_IERC20 *IERC20Session) Approve(spender common.Address, value *big.Int) (*types.Transaction, error) { - return _IERC20.Contract.Approve(&_IERC20.TransactOpts, spender, value) +// Solidity: function approve(address spender, uint256 amount) returns(bool) +func (_IERC20 *IERC20Session) Approve(spender common.Address, amount *big.Int) (*types.Transaction, error) { + return _IERC20.Contract.Approve(&_IERC20.TransactOpts, spender, amount) } // Approve is a paid mutator transaction binding the contract method 0x095ea7b3. // -// Solidity: function approve(address spender, uint256 value) returns(bool) -func (_IERC20 *IERC20TransactorSession) Approve(spender common.Address, value *big.Int) (*types.Transaction, error) { - return _IERC20.Contract.Approve(&_IERC20.TransactOpts, spender, value) +// Solidity: function approve(address spender, uint256 amount) returns(bool) +func (_IERC20 *IERC20TransactorSession) Approve(spender common.Address, amount *big.Int) (*types.Transaction, error) { + return _IERC20.Contract.Approve(&_IERC20.TransactOpts, spender, amount) } // Transfer is a paid mutator transaction binding the contract method 0xa9059cbb. // -// Solidity: function transfer(address to, uint256 value) returns(bool) -func (_IERC20 *IERC20Transactor) Transfer(opts *bind.TransactOpts, to common.Address, value *big.Int) (*types.Transaction, error) { - return _IERC20.contract.Transact(opts, "transfer", to, value) +// Solidity: function transfer(address to, uint256 amount) returns(bool) +func (_IERC20 *IERC20Transactor) Transfer(opts *bind.TransactOpts, to common.Address, amount *big.Int) (*types.Transaction, error) { + return _IERC20.contract.Transact(opts, "transfer", to, amount) } // Transfer is a paid mutator transaction binding the contract method 0xa9059cbb. // -// Solidity: function transfer(address to, uint256 value) returns(bool) -func (_IERC20 *IERC20Session) Transfer(to common.Address, value *big.Int) (*types.Transaction, error) { - return _IERC20.Contract.Transfer(&_IERC20.TransactOpts, to, value) +// Solidity: function transfer(address to, uint256 amount) returns(bool) +func (_IERC20 *IERC20Session) Transfer(to common.Address, amount *big.Int) (*types.Transaction, error) { + return _IERC20.Contract.Transfer(&_IERC20.TransactOpts, to, amount) } // Transfer is a paid mutator transaction binding the contract method 0xa9059cbb. // -// Solidity: function transfer(address to, uint256 value) returns(bool) -func (_IERC20 *IERC20TransactorSession) Transfer(to common.Address, value *big.Int) (*types.Transaction, error) { - return _IERC20.Contract.Transfer(&_IERC20.TransactOpts, to, value) +// Solidity: function transfer(address to, uint256 amount) returns(bool) +func (_IERC20 *IERC20TransactorSession) Transfer(to common.Address, amount *big.Int) (*types.Transaction, error) { + return _IERC20.Contract.Transfer(&_IERC20.TransactOpts, to, amount) } // TransferFrom is a paid mutator transaction binding the contract method 0x23b872dd. // -// Solidity: function transferFrom(address from, address to, uint256 value) returns(bool) -func (_IERC20 *IERC20Transactor) TransferFrom(opts *bind.TransactOpts, from common.Address, to common.Address, value *big.Int) (*types.Transaction, error) { - return _IERC20.contract.Transact(opts, "transferFrom", from, to, value) +// Solidity: function transferFrom(address from, address to, uint256 amount) returns(bool) +func (_IERC20 *IERC20Transactor) TransferFrom(opts *bind.TransactOpts, from common.Address, to common.Address, amount *big.Int) (*types.Transaction, error) { + return _IERC20.contract.Transact(opts, "transferFrom", from, to, amount) } // TransferFrom is a paid mutator transaction binding the contract method 0x23b872dd. // -// Solidity: function transferFrom(address from, address to, uint256 value) returns(bool) -func (_IERC20 *IERC20Session) TransferFrom(from common.Address, to common.Address, value *big.Int) (*types.Transaction, error) { - return _IERC20.Contract.TransferFrom(&_IERC20.TransactOpts, from, to, value) +// Solidity: function transferFrom(address from, address to, uint256 amount) returns(bool) +func (_IERC20 *IERC20Session) TransferFrom(from common.Address, to common.Address, amount *big.Int) (*types.Transaction, error) { + return _IERC20.Contract.TransferFrom(&_IERC20.TransactOpts, from, to, amount) } // TransferFrom is a paid mutator transaction binding the contract method 0x23b872dd. // -// Solidity: function transferFrom(address from, address to, uint256 value) returns(bool) -func (_IERC20 *IERC20TransactorSession) TransferFrom(from common.Address, to common.Address, value *big.Int) (*types.Transaction, error) { - return _IERC20.Contract.TransferFrom(&_IERC20.TransactOpts, from, to, value) +// Solidity: function transferFrom(address from, address to, uint256 amount) returns(bool) +func (_IERC20 *IERC20TransactorSession) TransferFrom(from common.Address, to common.Address, amount *big.Int) (*types.Transaction, error) { + return _IERC20.Contract.TransferFrom(&_IERC20.TransactOpts, from, to, amount) } // IERC20ApprovalIterator is returned from FilterApproval and is used to iterate over the raw logs and unpacked data for Approval events raised by the IERC20 contract. diff --git a/pkg/abi/MockToken.abi.go b/pkg/abi/MockToken.abi.go index dea57a4e..27ad7175 100644 --- a/pkg/abi/MockToken.abi.go +++ b/pkg/abi/MockToken.abi.go @@ -31,7 +31,7 @@ var ( // MockTokenMetaData contains all meta data concerning the MockToken contract. var MockTokenMetaData = &bind.MetaData{ - ABI: "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"allowance\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"needed\",\"type\":\"uint256\"}],\"name\":\"ERC20InsufficientAllowance\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"balance\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"needed\",\"type\":\"uint256\"}],\"name\":\"ERC20InsufficientBalance\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"approver\",\"type\":\"address\"}],\"name\":\"ERC20InvalidApprover\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"receiver\",\"type\":\"address\"}],\"name\":\"ERC20InvalidReceiver\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"}],\"name\":\"ERC20InvalidSender\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"}],\"name\":\"ERC20InvalidSpender\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"mint\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", + ABI: "[{\"type\":\"constructor\",\"inputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"allowance\",\"inputs\":[{\"name\":\"owner\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"spender\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"approve\",\"inputs\":[{\"name\":\"spender\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"balanceOf\",\"inputs\":[{\"name\":\"account\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"decimals\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint8\",\"internalType\":\"uint8\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"mint\",\"inputs\":[{\"name\":\"amount\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"name\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"string\",\"internalType\":\"string\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"symbol\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"string\",\"internalType\":\"string\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"totalSupply\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"transfer\",\"inputs\":[{\"name\":\"to\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"transferFrom\",\"inputs\":[{\"name\":\"from\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"to\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"nonpayable\"},{\"type\":\"event\",\"name\":\"Approval\",\"inputs\":[{\"name\":\"owner\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"spender\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"Transfer\",\"inputs\":[{\"name\":\"from\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"to\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"error\",\"name\":\"ERC20InsufficientAllowance\",\"inputs\":[{\"name\":\"spender\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"allowance\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"needed\",\"type\":\"uint256\",\"internalType\":\"uint256\"}]},{\"type\":\"error\",\"name\":\"ERC20InsufficientBalance\",\"inputs\":[{\"name\":\"sender\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"balance\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"needed\",\"type\":\"uint256\",\"internalType\":\"uint256\"}]},{\"type\":\"error\",\"name\":\"ERC20InvalidApprover\",\"inputs\":[{\"name\":\"approver\",\"type\":\"address\",\"internalType\":\"address\"}]},{\"type\":\"error\",\"name\":\"ERC20InvalidReceiver\",\"inputs\":[{\"name\":\"receiver\",\"type\":\"address\",\"internalType\":\"address\"}]},{\"type\":\"error\",\"name\":\"ERC20InvalidSender\",\"inputs\":[{\"name\":\"sender\",\"type\":\"address\",\"internalType\":\"address\"}]},{\"type\":\"error\",\"name\":\"ERC20InvalidSpender\",\"inputs\":[{\"name\":\"spender\",\"type\":\"address\",\"internalType\":\"address\"}]}]", } // MockTokenABI is the input ABI used to generate the binding from. diff --git a/pkg/abi/Payment.abi.go b/pkg/abi/Payment.abi.go index 6382fe24..58f4e3c2 100644 --- a/pkg/abi/Payment.abi.go +++ b/pkg/abi/Payment.abi.go @@ -31,7 +31,7 @@ var ( // PaymentMetaData contains all meta data concerning the Payment contract. var PaymentMetaData = &bind.MetaData{ - ABI: "[{\"inputs\":[{\"internalType\":\"contractIERC20\",\"name\":\"_token\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"target\",\"type\":\"address\"}],\"name\":\"AddressEmptyCode\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"AddressInsufficientBalance\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"AlreadyExists\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"AmountRequired\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"ChannelLocked\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"DoesNotExist\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"FailedInnerCall\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"InsufficientFunds\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"}],\"name\":\"SafeERC20FailedOperation\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"publisher\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"}],\"name\":\"ChannelClosed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"publisher\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"}],\"name\":\"ChannelCreated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"publisher\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"depositAmount\",\"type\":\"uint256\"}],\"name\":\"Deposited\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"publisher\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"unlockedAt\",\"type\":\"uint256\"}],\"name\":\"UnlockTimerStarted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"publisher\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"unlockedAmount\",\"type\":\"uint256\"}],\"name\":\"Unlocked\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"publisher\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"withdrawnAmount\",\"type\":\"uint256\"}],\"name\":\"Withdrawn\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"publisher\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"}],\"name\":\"available\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"channels\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"investedByPublisher\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"withdrawnByProvider\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"unlockTime\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"unlockedAt\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"}],\"name\":\"closeChannel\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"unlockTime\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"initialAmount\",\"type\":\"uint256\"}],\"name\":\"createChannel\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"deposit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"token\",\"outputs\":[{\"internalType\":\"contractIERC20\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"}],\"name\":\"unlock\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"publisher\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"transferAddress\",\"type\":\"address\"}],\"name\":\"withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"}],\"name\":\"withdrawUnlocked\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"publisher\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"totalWithdrawAmount\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"transferAddress\",\"type\":\"address\"}],\"name\":\"withdrawUpTo\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"publisher\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"podId\",\"type\":\"bytes32\"}],\"name\":\"withdrawn\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]", + ABI: "[{\"type\":\"constructor\",\"inputs\":[{\"name\":\"_token\",\"type\":\"address\",\"internalType\":\"contractIERC20\"}],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"available\",\"inputs\":[{\"name\":\"publisher\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"provider\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"channels\",\"inputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"investedByPublisher\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"withdrawnByProvider\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"unlockTime\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"unlockedAt\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"closeChannel\",\"inputs\":[{\"name\":\"provider\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"createChannel\",\"inputs\":[{\"name\":\"provider\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"unlockTime\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"initialAmount\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"deposit\",\"inputs\":[{\"name\":\"provider\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"amount\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"token\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"contractIERC20\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"unlock\",\"inputs\":[{\"name\":\"provider\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"withdraw\",\"inputs\":[{\"name\":\"publisher\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"amount\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"transferAddress\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"withdrawUnlocked\",\"inputs\":[{\"name\":\"provider\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"withdrawUpTo\",\"inputs\":[{\"name\":\"publisher\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"totalWithdrawAmount\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"transferAddress\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"withdrawn\",\"inputs\":[{\"name\":\"publisher\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"provider\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"event\",\"name\":\"ChannelClosed\",\"inputs\":[{\"name\":\"publisher\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"provider\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"indexed\":true,\"internalType\":\"bytes32\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"ChannelCreated\",\"inputs\":[{\"name\":\"publisher\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"provider\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"indexed\":true,\"internalType\":\"bytes32\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"Deposited\",\"inputs\":[{\"name\":\"publisher\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"provider\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"indexed\":true,\"internalType\":\"bytes32\"},{\"name\":\"depositAmount\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"UnlockTimerStarted\",\"inputs\":[{\"name\":\"publisher\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"provider\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"indexed\":true,\"internalType\":\"bytes32\"},{\"name\":\"unlockedAt\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"Unlocked\",\"inputs\":[{\"name\":\"publisher\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"provider\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"indexed\":true,\"internalType\":\"bytes32\"},{\"name\":\"unlockedAmount\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"Withdrawn\",\"inputs\":[{\"name\":\"publisher\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"provider\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"podId\",\"type\":\"bytes32\",\"indexed\":true,\"internalType\":\"bytes32\"},{\"name\":\"withdrawnAmount\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"error\",\"name\":\"AddressEmptyCode\",\"inputs\":[{\"name\":\"target\",\"type\":\"address\",\"internalType\":\"address\"}]},{\"type\":\"error\",\"name\":\"AlreadyExists\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"AmountRequired\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"ChannelLocked\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"DoesNotExist\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"FailedCall\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"InsufficientBalance\",\"inputs\":[{\"name\":\"balance\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"needed\",\"type\":\"uint256\",\"internalType\":\"uint256\"}]},{\"type\":\"error\",\"name\":\"InsufficientFunds\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"SafeERC20FailedOperation\",\"inputs\":[{\"name\":\"token\",\"type\":\"address\",\"internalType\":\"address\"}]}]", } // PaymentABI is the input ABI used to generate the binding from. diff --git a/pkg/abi/Registry.abi.go b/pkg/abi/Registry.abi.go index 59278aff..467f745c 100644 --- a/pkg/abi/Registry.abi.go +++ b/pkg/abi/Registry.abi.go @@ -31,7 +31,7 @@ var ( // RegistryMetaData contains all meta data concerning the Registry contract. var RegistryMetaData = &bind.MetaData{ - ABI: "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"Id\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"CpuPrice\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"RamPrice\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"StoragePrice\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"BandwidthEgressPrice\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"BandwidthIngressPrice\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"Cpumodel\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"TeeType\",\"type\":\"string\"}],\"name\":\"NewPricingTable\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"}],\"name\":\"Subscribed\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"provider\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tableId\",\"type\":\"uint256\"}],\"name\":\"isSubscribed\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pricingTableId\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"providers\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"},{\"internalType\":\"uint256[5]\",\"name\":\"Prices\",\"type\":\"uint256[5]\"},{\"internalType\":\"string\",\"name\":\"cpumodel\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"teeType\",\"type\":\"string\"}],\"name\":\"registerPricingTable\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"cid\",\"type\":\"string\"}],\"name\":\"registerProvider\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tableId\",\"type\":\"uint256\"}],\"name\":\"subscribe\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"subscription\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tableId\",\"type\":\"uint256\"}],\"name\":\"unsubscribe\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", + ABI: "[{\"type\":\"function\",\"name\":\"isSubscribed\",\"inputs\":[{\"name\":\"provider\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"tableId\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"pricingTableId\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"providers\",\"inputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[{\"name\":\"\",\"type\":\"string\",\"internalType\":\"string\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"registerPricingTable\",\"inputs\":[{\"name\":\"token\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"Prices\",\"type\":\"uint256[5]\",\"internalType\":\"uint256[5]\"},{\"name\":\"cpumodel\",\"type\":\"string\",\"internalType\":\"string\"},{\"name\":\"teeType\",\"type\":\"string\",\"internalType\":\"string\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"registerProvider\",\"inputs\":[{\"name\":\"cid\",\"type\":\"string\",\"internalType\":\"string\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"subscribe\",\"inputs\":[{\"name\":\"tableId\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"subscription\",\"inputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"unsubscribe\",\"inputs\":[{\"name\":\"tableId\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"event\",\"name\":\"NewPricingTable\",\"inputs\":[{\"name\":\"token\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"Id\",\"type\":\"uint256\",\"indexed\":true,\"internalType\":\"uint256\"},{\"name\":\"CpuPrice\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"},{\"name\":\"RamPrice\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"},{\"name\":\"StoragePrice\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"},{\"name\":\"BandwidthEgressPrice\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"},{\"name\":\"BandwidthIngressPrice\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"},{\"name\":\"Cpumodel\",\"type\":\"string\",\"indexed\":false,\"internalType\":\"string\"},{\"name\":\"TeeType\",\"type\":\"string\",\"indexed\":false,\"internalType\":\"string\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"Subscribed\",\"inputs\":[{\"name\":\"id\",\"type\":\"uint256\",\"indexed\":true,\"internalType\":\"uint256\"},{\"name\":\"provider\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"}],\"anonymous\":false}]", } // RegistryABI is the input ABI used to generate the binding from. diff --git a/pkg/publisher/registry.go b/pkg/publisher/registry.go index 50c1f0dd..9d44b9c1 100644 --- a/pkg/publisher/registry.go +++ b/pkg/publisher/registry.go @@ -46,7 +46,6 @@ func GetPricingTables(ethClient *ethclient.Client, registryContract common.Addre func FilterPricingTables(tables PricingTableList, filter *abi.RegistryNewPricingTable) PricingTableList { var filteredTables PricingTableList - for _, table := range tables { if matchPricingTable(table, filter) { filteredTables = append(filteredTables, table) diff --git a/test/e2e/common/config.yaml b/test/e2e/common/config.yaml new file mode 100644 index 00000000..9fca0437 --- /dev/null +++ b/test/e2e/common/config.yaml @@ -0,0 +1,35 @@ +pricing: + table: + format: yaml + # filename: pricing.yaml + contents: | + tables: + - paymentContractAddress: "5/FyXnc0ziiPg2fhuxQ+kLs/BRI=" + resources: + - resource: "cpu" + priceForReservation: 200000000000 + - resource: "ram" + priceForReservation: 500 + - resource: "storage" + priceForUsage: 500 + - resource: "bandwidth_ingress" + priceForUsage: 800 + - resource: "bandwidth_egress" + priceForUsage: 800 +cpu_model: "Intel Xeon Platinum 8452Y Processor" +tee_type: "Secure Enclaves" +withdraw: + address: "0x90F79bf6EB2c4f870365E785982E1f101E93b906" + time: 15 +info: + format: yaml + contents: | + regions: + - name: "bul" + zone: "east" + num: 1 + - name: "alg" + zone: "west" + num: 2 + multiaddrs: + - "https://kubo.business/" diff --git a/test/e2e/common/manifest-guestbook-nostorage.yaml b/test/e2e/common/manifest-guestbook-nostorage.yaml deleted file mode 100644 index 77c805aa..00000000 --- a/test/e2e/common/manifest-guestbook-nostorage.yaml +++ /dev/null @@ -1,41 +0,0 @@ -containers: -- name: php-redis - image: - url: gcr.io/google-samples/gb-frontend:v4 - env: - GET_HOSTS_FROM: env - REDIS_MASTER_SERVICE_HOST: redis - REDIS_SLAVE_SERVICE_HOST: redis - volumes: - - mountPath: /var/www/html/test.html - name: test-html - ports: - - containerPort: '80' - hostHttpHost: guestbook.localhost - name: internal - resourceRequests: - - amountMillis: '100' - resource: cpu - - amount: '100000000' - resource: memory -- name: redis - image: - url: docker.io/library/redis:alpine - volumes: - - mountPath: /data - name: db-data - resourceRequests: - - amountMillis: '10' - resource: cpu - - amount: '100000000' - resource: memory -volumes: -- name: db-data - type: VOLUME_EMPTY -- name: test-html - secret: - file: "test.html" - type: VOLUME_SECRET -replicas: - max: 1 - diff --git a/test/e2e/common/manifest-guestbook.yaml b/test/e2e/common/manifest-guestbook.yaml index 03695fd5..914b428e 100644 --- a/test/e2e/common/manifest-guestbook.yaml +++ b/test/e2e/common/manifest-guestbook.yaml @@ -1,7 +1,7 @@ containers: - - name: redis-master + - name: php-redis image: - url: registry.k8s.io/redis:e2e + url: gcr.io/google-samples/gb-frontend@sha256:cbc8ef4b0a2d0b95965e0e7dc8938c270ea98e34ec9d60ea64b2d5f2df2dfbbf env: GET_HOSTS_FROM: env REDIS_MASTER_SERVICE_HOST: redis @@ -41,5 +41,4 @@ volumes: file: 'test.html' type: VOLUME_SECRET replicas: - min: 1 max: 1 diff --git a/test/e2e/common/manifest-hello-world.yaml b/test/e2e/common/manifest-hello-world.yaml index b23b758c..c16258ae 100644 --- a/test/e2e/common/manifest-hello-world.yaml +++ b/test/e2e/common/manifest-hello-world.yaml @@ -12,4 +12,5 @@ containers: - amount: '1000000' resource: memory replicas: + min: 1 max: 1 diff --git a/test/e2e/common/manifest-logger.json b/test/e2e/common/manifest-logger.json new file mode 100644 index 00000000..fdb2908b --- /dev/null +++ b/test/e2e/common/manifest-logger.json @@ -0,0 +1,24 @@ +{ + "containers": [ + { + "name": "logger", + "image": { + "url": "chentex/random-logger:latest" + }, + "resourceRequests": [ + { + "resource": "cpu", + "amountMillis": 100 + }, + { + "resource": "memory", + "amount": 100000000 + } + ] + } + ], + "replicas": { + "min": 1, + "max": 2 + } +} diff --git a/test/e2e/common/manifest-nginx.yaml b/test/e2e/common/manifest-nginx.yaml index 2254038c..7c60516b 100644 --- a/test/e2e/common/manifest-nginx.yaml +++ b/test/e2e/common/manifest-nginx.yaml @@ -1,15 +1,16 @@ containers: -- name: test-container - image: - url: docker.io/nginxdemos/nginx-hello:latest - ports: - - containerPort: '8080' - hostHttpHost: example.local - resourceRequests: - - amountMillis: '10' - resource: cpu - - amount: '100000000' - resource: memory + - name: test-container + image: + url: docker.io/nginxdemos/nginx-hello:latest + ports: + - containerPort: '8080' + hostHttpHost: example.local + name: internal + resourceRequests: + - amountMillis: '10' + resource: cpu + - amount: '100000000' + resource: memory replicas: + min: 1 max: 1 - diff --git a/test/e2e/common/manifest-redis-guestbook.yaml b/test/e2e/common/manifest-redis-guestbook.yaml new file mode 100644 index 00000000..49a0ead5 --- /dev/null +++ b/test/e2e/common/manifest-redis-guestbook.yaml @@ -0,0 +1,55 @@ +containers: + - name: redis-master + image: + url: registry.k8s.io/redis:e2e + volumes: + - mountPath: /var/www/html/test.html + name: test-html + ports: + - containerPort: '6379' + name: internal + resourceRequests: + - amountMillis: '100' + resource: cpu + - amount: '100000000' + resource: memory + - name: redis-replica + image: + url: gcr.io/google_samples/gb-redisslave:v1 + env: + GET_HOSTS_FROM: dns + ports: + - containerPort: '6379' + name: internal + resourceRequests: + - amountMillis: '10' + resource: cpu + - amount: '100000000' + resource: memory + - name: frontend + image: + url: gcr.io/google-samples/gb-frontend:v4 + resourceRequests: + - amountMillis: '100' + resource: cpu + - amount: '100000000' + resource: memory + env: + GET_HOSTS_FROM: dns + ports: + - containerPort: '80' + hostHttpHost: guestbook.localhost + name: internal +volumes: + - filesystem: + resourceRequests: + - amount: '1000000000' + resource: storage + type: VOLUME_EMPTY + - name: test-html + secret: + file: 'test.html' + type: VOLUME_SECRET +replicas: + min: 1 + max: 1 diff --git a/test/e2e/common/manifest-redmine-nostorage.yaml b/test/e2e/common/manifest-redmine-nostorage.yaml new file mode 100644 index 00000000..9e1d9623 --- /dev/null +++ b/test/e2e/common/manifest-redmine-nostorage.yaml @@ -0,0 +1,26 @@ +containers: + - name: redmine + image: + url: redmine + volumes: + - mountPath: /var/www/html/test.html + name: test-html + ports: + - containerPort: '8080' + hostHttpHost: guestbook.localhost + name: internal + resourceRequests: + - amountMillis: '100' + resource: cpu + - amount: '100000000' + resource: memory +volumes: + - name: db-data + type: VOLUME_EMPTY + - name: test-html + secret: + file: 'test.html' + type: VOLUME_SECRET +replicas: + min: 1 + max: 1 diff --git a/test/e2e/constellation/miniconstellation/run-test.sh b/test/e2e/constellation/miniconstellation/run-test.sh index 489347c2..82f3f50c 100755 --- a/test/e2e/constellation/miniconstellation/run-test.sh +++ b/test/e2e/constellation/miniconstellation/run-test.sh @@ -98,6 +98,16 @@ echo "$SWARM_ADDRESSES" | jq -r '.[] + "/p2p/'"$PROVIDER_IPFS"'"' | xargs -n 1 i sleep 1 +## 1.3: Register the provider + +go run ../../../cmd/tpodserver/ registry register \ + --config ../common/config.yaml \ + --ipfs /ip4/127.0.0.1/tcp/5001 \ + --ethereum-rpc http://127.0.0.1:8545 \ + --ethereum-key 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d \ + --token-contract 0x5FbDB2315678afecb367f032d93F642f64180aa3 \ + --registry-contract 0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0 \ + ## 2: Deploy example manifest to cluster ## DEPLOYER_ETH=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 #TODO= anvil.accounts[0] diff --git a/test/e2e/constellation/miniconstellation/trustedpods/tpodserver.yml b/test/e2e/constellation/miniconstellation/trustedpods/tpodserver.yml index 64e0ea66..de212781 100644 --- a/test/e2e/constellation/miniconstellation/trustedpods/tpodserver.yml +++ b/test/e2e/constellation/miniconstellation/trustedpods/tpodserver.yml @@ -53,42 +53,6 @@ data: multiaddrs: - "/dns4/kubo.business" # tokenAddress=$(echo e7f1725E7734CE288F8367e1Bb143E90bb3F0512 | xxd -p -r | base64) - ---- -apiVersion: batch/v1 -kind: Job -metadata: - name: tpodregister - namespace: trustedpods -spec: - ttlSecondsAfterFinished: 60 # delete the job after 1 min - template: - spec: - containers: - - name: register - image: ghcr.io/comrade-coop/apocryph/server:master - command: [ - "tpodserver", "registry", "register", - "--config", "config.yaml", - "--ipfs", "/dns4/ipfs-rpc.ipfs.svc.cluster.local/tcp/5001", - "--ethereum-rpc", "http://eth-rpc.eth.svc.cluster.local:8545", - "--ethereum-key", "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d", # TODO= anvil.accounts[1] prvkey - "--token-contract", "0x5FbDB2315678afecb367f032d93F642f64180aa3", # TODO= result of forge create - "--registry-contract", "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", # TODO= result of forge create - ] - volumeMounts: - - name: configs - mountPath: /config.yaml - subPath: config.yaml - restartPolicy: Never - volumes: - - name: configs - configMap: - name: trustedpods-configs - items: - - key: config.yaml - path: config.yaml - backoffLimit: 4 --- apiVersion: apps/v1 kind: Deployment @@ -119,11 +83,16 @@ spec: ] ports: - containerPort: 8080 + securityContext: + allowPrivilegeEscalation: false + runAsUser: 0 volumeMounts: - name: configs mountPath: /config.yaml subPath: config.yaml readOnly: true + - name: containerd-socket + mountPath: /run/containerd/containerd.sock - name: tpodmonitor image: ghcr.io/comrade-coop/apocryph/server:master command: [ @@ -147,4 +116,7 @@ spec: items: - key: config.yaml path: config.yaml + - name: containerd-socket + hostPath: + path: /run/containerd/containerd.sock serviceAccountName: tpodserver-serviceaccount diff --git a/test/e2e/constellation/qemu/build.sh b/test/e2e/constellation/qemu/build.sh index 6fd20200..65b3bd9c 100755 --- a/test/e2e/constellation/qemu/build.sh +++ b/test/e2e/constellation/qemu/build.sh @@ -2,9 +2,10 @@ set -e set -v CHART_PATH="$1" +SUFFIX=$RANDOM CONSTELLATION_PATH="../../../../constellation" -# sometimes if the cluster did no terminate correctly, try modifying this -WORKSPACE_PATH="$HOME/.apocryph/constellation" +WORKSPACE_PATH="$HOME/.apocryph/constellation-$SUFFIX" +echo "WORKSPACE_PATH:: $WORKSPACE_PATH" CURRENT_DIR=$(pwd) if [ -n "$2" ]; then @@ -38,7 +39,10 @@ cd "$CONSTELLATION_PATH" bazel build //image/system:qemu_stable -## 2: create,configure, run workspace +## 2: create & configure constellation workspace +set -e +set -v + cd "$CURRENT_DIR" cd "$CONSTELLATION_PATH" # Get the new image measurements @@ -55,7 +59,7 @@ echo "PCR9: $PCR9" echo "PCR11: $PCR11" if [ -d "$WORKSPACE_PATH" ]; then - cd "$WORKSPACE_PATH" && constellation terminate + cd "$WORKSPACE_PATH" && constellation terminate 2>/dev/null sudo rm -r "$WORKSPACE_PATH" fi @@ -77,6 +81,8 @@ version=$(echo "$output" | grep -oP 'Version:\s+\K\S+' | head -n 1) # Copy the image & rename it to the current constellation version to bypass downloading upstream image cp $link/constellation.raw "$version.raw" +export KUBECONFIG="$HOME/.apocryph/constellation-$SUFFIX/constellation-admin.conf" + diff --git a/test/e2e/constellation/qemu/run-test.sh b/test/e2e/constellation/qemu/run-test.sh index 098d1bc5..893363bc 100755 --- a/test/e2e/constellation/qemu/run-test.sh +++ b/test/e2e/constellation/qemu/run-test.sh @@ -1,10 +1,11 @@ #!/bin/bash set -e set -v -# sometimes if the cluster did no terminate correctly, try modifying this -WORKSPACE_PATH="$HOME/.apocryph/constellation/" + +WORKSPACE_PATH="$HOME/.apocryph/constellation-" CURRENT_DIR=$(pwd) -export KUBECONFIG="$HOME/.apocryph/constellation/constellation-admin.conf" + +trap 'pkill -f "kubectl port-forward" && kill $(jobs -p) &>/dev/null' EXIT # based on https://stackoverflow.com/a/31269848 / https://bobcopeland.com/blog/2012/10/goto-in-bash/ if [ -n "$1" ]; then @@ -17,16 +18,19 @@ echo -e "\e[1;32m---" echo "Note: To skip steps, use '$0 '" echo -e "---\e[0m" -## 0: Build build custom os image & run the cluster +## 0: Build build custom OS image & run the cluster # use the miniconstellation chart -./build.sh ../miniconstellation +. ./build.sh ../miniconstellation ## 1: Start the constellation cluster -cd "$WORKSPACE_PATH" +cd "$WORKSPACE_PATH"* constellation apply -y -## 1.1: wait for server +## 1.1: wait for the setup +cd $WORKSPACE_PATH* +CONF_DIR=$(pwd) +export KUBECONFIG="$CONF_DIR/constellation-admin.conf" cd $CURRENT_DIR kubectl wait --namespace keda --for=condition=available deployment/ingress-nginx-controller kubectl wait --namespace prometheus --for=condition=available deployment/prometheus-kube-state-metrics @@ -42,11 +46,25 @@ kubectl wait --namespace trustedpods --for=condition=available deployment/tpodse DEPLOYER_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 #TODO= anvil.accounts[0] -sleep 2 +TOKEN_CONTRACT=0x5fbdb2315678afecb367f032d93f642f64180aa3 # TODO= result of forge create + +forge create --root ../../../../contracts MockToken --private-key $DEPLOYER_KEY +forge create --root ../../../../contracts Payment --private-key $DEPLOYER_KEY --constructor-args $TOKEN_CONTRACT +forge create --root ../../../../contracts Registry --private-key $DEPLOYER_KEY -( cd ../../../../contracts; forge script script/Deploy.s.sol --private-key "$DEPLOYER_KEY" --rpc-url http://localhost:8545 --broadcast) -## 2.1: Configure provider/in-cluster IPFS and publisher IPFS ## +## 2.1: Register the provider +[ "$PORT_5004" == "" ] && { PORT_5004="yes" ; kubectl port-forward --namespace ipfs svc/ipfs-rpc 5004:5001 & sleep 0.5; } + +go run ../../../../cmd/tpodserver registry register \ + --config ../../common/config.yaml \ + --ipfs /ip4/127.0.0.1/tcp/5004 \ + --ethereum-rpc http://127.0.0.1:8545 \ + --ethereum-key 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d \ + --token-contract 0x5FbDB2315678afecb367f032d93F642f64180aa3 \ + --registry-contract 0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0 \ + +## 3: Configure provider/in-cluster IPFS and publisher IPFS ## { while ! kubectl get -n ipfs endpoints ipfs-rpc -o json | jq '.subsets[].addresses[].ip' &>/dev/null; do sleep 1; done; } @@ -74,7 +92,7 @@ echo "$SWARM_ADDRESSES" | jq -r '.[] + "/p2p/'"$PROVIDER_IPFS"'"' | xargs -n 1 i sleep 1 -## 3: Deploy example manifest to cluster ## +# Deploy example manifest to cluster ## DEPLOYER_ETH=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 #TODO= anvil.accounts[0] PROVIDER_ETH=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 #TODO= anvil.accounts[1] @@ -89,30 +107,30 @@ REGISTRY_CONTRACT=0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0 # TODO= result of f # REGISTRY_CONTRACT=$(cat ../../../../contracts/broadcast/Deploy.s.sol/31337/run-latest.json | jq -r '.returns.registry.value') FUNDS=10000000000000000000000 + [ "$PORT_8545" == "" ] && { PORT_8545="yes" ; kubectl port-forward --namespace eth svc/eth-rpc 8545:8545 & } -[ "$PORT_5004" == "" ] && { PORT_5004="yes" ; kubectl port-forward --namespace ipfs svc/ipfs-rpc 5004:5001 & sleep 0.5; } -[ -n "$PROVIDER_IPFS" ] || { PROVIDER_IPFS=$(curl -X POST "http://127.0.0.1:5004/api/v0/id" -s | jq '.ID' -r); echo $PROVIDER_IPFS; } [ -n "$IPFS_DAEMON" ] || { IPFS_DAEMON=yes; ipfs daemon & { while ! [ -f ${IPFS_PATH:-~/.ipfs}/api ]; do sleep 0.1; done; } 2>/dev/null; } set +v set -x -go run ../../../../cmd/trustedpods/ pod deploy ../../common/manifest-guestbook-nostorage.yaml \ + +sudo chmod o+rw /run/containerd/containerd.sock + + +go run ../../../../cmd/trustedpods/ pod deploy ../../common/manifest-redmine-nostorage.yaml \ --ethereum-key "$PUBLISHER_KEY" \ --payment-contract "$PAYMENT_CONTRACT" \ --registry-contract "$REGISTRY_CONTRACT" \ --funds "$FUNDS" \ - --upload-images=false \ + --upload-images=true \ --mint-funds -set +x -set -v - ## 4: Connect and measure balances ## DEPLOYER_ETH=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 #TODO= anvil.accounts[0] WITHDRAW_ETH=0x90F79bf6EB2c4f870365E785982E1f101E93b906 # From trustedpods/tpodserver.yml -TOKEN_CONTRACT=$(cat ../../../../contracts/broadcast/Deploy.s.sol/31337/run-latest.json | jq -r '.returns.token.value') +TOKEN_CONTRACT=$(cat ../../../contracts/broadcast/Deploy.s.sol/31337/run-latest.json | jq -r '.returns.token.value') NODE_ADDRESS=$(kubectl get no -o json | jq -r '.items[].status.addresses[] | select(.type == "InternalIP") | .address' | head -n 1) INGRESS_PORT=$(kubectl get svc -n keda ingress-nginx-controller -o json | jq -r '.spec.ports[] | select(.name == "http") | .nodePort' | head -n 1) INGRESS_URL="http://$NODE_ADDRESS:$INGRESS_PORT"; echo $INGRESS_URL @@ -125,7 +143,7 @@ echo "Provider balance before:" $(cast call "$TOKEN_CONTRACT" "balanceOf(address set -x while ! curl --connect-timeout 40 -H "Host: $MANIFEST_HOST" $INGRESS_URL --fail-with-body; do sleep 10; done -curl -H "Host: $MANIFEST_HOST" $INGRESS_URL/test.html --fail-with-body +curl -H "Host: $MANIFEST_HOST" $INGRESS_URL --fail-with-body set +x @@ -133,7 +151,7 @@ sleep 45 echo "Provider balance after:" $(cast call "$TOKEN_CONTRACT" "balanceOf(address)" "$WITHDRAW_ETH" | cast to-fixed-point 18) -## 5: In conclusion.. ## +## 4: In conclusion.. ## set +v diff --git a/test/e2e/minikube/run-test.sh b/test/e2e/minikube/run-test.sh index e84b1039..bf5eb62b 100755 --- a/test/e2e/minikube/run-test.sh +++ b/test/e2e/minikube/run-test.sh @@ -120,6 +120,17 @@ echo "$SWARM_ADDRESSES" | jq -r '.[] + "/p2p/'"$PROVIDER_IPFS"'"' | xargs -n 1 i sleep 1 +## 1.3: Register the provider in the marketplace + +gp run ../../../cmd/tpodserver/ registry register \ + --config ../common/config.yaml \ + --ipfs /ip4/127.0.0.1/tcp/5001 \ + --ethereum-rpc http://127.0.0.1:8545 \ + --ethereum-key 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d \ + --token-contract 0x5FbDB2315678afecb367f032d93F642f64180aa3 \ + --registry-contract 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 \ + + ## 2: Deploy example manifest to cluster ## PROVIDER_ETH=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 #TODO= anvil.accounts[1] diff --git a/test/e2e/minikube/trustedpods/tpodserver.yml b/test/e2e/minikube/trustedpods/tpodserver.yml index 25558fbf..06966754 100644 --- a/test/e2e/minikube/trustedpods/tpodserver.yml +++ b/test/e2e/minikube/trustedpods/tpodserver.yml @@ -53,41 +53,6 @@ data: multiaddrs: - "/dns4/kubo.business" # tokenAddress=$(echo e7f1725E7734CE288F8367e1Bb143E90bb3F0512 | xxd -p -r | base64) - ---- -apiVersion: batch/v1 -kind: Job -metadata: - name: tpodregister -spec: - ttlSecondsAfterFinished: 60 # delete the job after 1 min - template: - spec: - containers: - - name: register - image: host.minikube.internal:5000/comradecoop/apocryph/server - command: [ - "tpodserver", "registry", "register", - "--config", "config.yaml", - "--ipfs", "/dns4/ipfs-rpc.ipfs.svc.cluster.local/tcp/5001", - "--ethereum-rpc", "http://eth-rpc.eth.svc.cluster.local:8545", - "--ethereum-key", "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d", # TODO= anvil.accounts[1] prvkey - "--token-contract", "0x5FbDB2315678afecb367f032d93F642f64180aa3", # TODO= result of forge create - "--registry-contract", "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", # TODO= result of forge create - ] - volumeMounts: - - name: configs - mountPath: /config.yaml - subPath: config.yaml - restartPolicy: Never - volumes: - - name: configs - configMap: - name: trustedpods-configs - items: - - key: config.yaml - path: config.yaml - backoffLimit: 4 --- apiVersion: apps/v1 kind: Deployment diff --git a/test/integration/lifecycle/devserver/devserver.yml b/test/integration/lifecycle/devserver/devserver.yml index 58d91c0e..a4886d63 100644 --- a/test/integration/lifecycle/devserver/devserver.yml +++ b/test/integration/lifecycle/devserver/devserver.yml @@ -148,6 +148,8 @@ spec: - name: configs mountPath: /config.yaml subPath: config.yaml + - name: containerd-socket + mountPath: /run/containerd/containerd.sock volumes: - name: configs configMap: @@ -157,6 +159,12 @@ spec: path: config.yaml ports: - containerPort: 8090 + securityContext: + allowPrivilegeEscalation: false + runAsUser: 0 + - name: containerd-socket + hostPath: + path: /run/containerd/containerd.sock serviceAccountName: devserver-serviceaccount --- apiVersion: apps/v1 diff --git a/test/integration/registry/run-test.sh b/test/integration/registry/run-test.sh index 5e3475fa..d2d304d4 100755 --- a/test/integration/registry/run-test.sh +++ b/test/integration/registry/run-test.sh @@ -1,18 +1,21 @@ -#!/bin/sh +#!/bin/bash # SPDX-License-Identifier: GPL-3.0 +set -e cd "$(dirname "$0")" -anvil > anvil_output.txt & -ipfs daemon >/dev/null 2>&1 & +trap 'kill $(jobs -p) &>/dev/null' EXIT + +anvil >/dev/null & +ipfs daemon >/dev/null & sleep 2 -PROVIDER_KEY=$(awk '/Private Keys/ {flag=1; next} flag && /^\(0\)/ {print $2; exit}' anvil_output.txt) -COMPETITOR_KEY=$(awk '/Private Keys/ {flag=1; next} flag && /^\(1\)/ {print $2; exit}' anvil_output.txt) -PUBLISHER_KEY=$(awk '/Private Keys/ {flag=1; next} flag && /^\(1\)/ {print $3; exit}' anvil_output.txt) +PROVIDER_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +COMPETITOR_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d +PUBLISHER_KEY=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a -forge create --root ../../../contracts Registry --private-key $PROVIDER_KEY >/dev/null -forge create --root ../../../contracts MockToken --private-key $PROVIDER_KEY >/dev/null +forge create --root ../../../contracts Registry --private-key $PROVIDER_KEY +forge create --root ../../../contracts MockToken --private-key $PROVIDER_KEY REGISTRY_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3 TOKEN_ADDRESS=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 @@ -21,8 +24,17 @@ REGION="bul-east-1" echo -e "Registering 2 providers, 2 pricing tables:\n" -go run ../../../cmd/tpodserver registry register --config config.yaml --ethereum-key "$PROVIDER_KEY" --registry-contract "$REGISTRY_ADDRESS" --token-contract "$TOKEN_ADDRESS" >/dev/null -go run ../../../cmd/tpodserver registry register --config competitor.yaml --ethereum-key "$COMPETITOR_KEY" --registry-contract "$REGISTRY_ADDRESS" --token-contract "$TOKEN_ADDRESS" >/dev/null +go run ../../../cmd/tpodserver registry register \ + --config config.yaml \ + --ethereum-key "$PROVIDER_KEY" \ + --registry-contract "$REGISTRY_ADDRESS" \ + --token-contract "$TOKEN_ADDRESS" \ + +go run ../../../cmd/tpodserver registry register \ + --config competitor.yaml \ + --ethereum-key "$COMPETITOR_KEY" \ + --registry-contract "$REGISTRY_ADDRESS" \ + --token-contract "$TOKEN_ADDRESS" \ echo -e "\nPrint tables:\n" go run ../../../cmd/trustedpods registry get --config config.yaml --ethereum-key "$PUBLISHER_KEY" --registry-contract "$REGISTRY_ADDRESS" --token-contract "$TOKEN_ADDRESS" @@ -33,6 +45,3 @@ go run ../../../cmd/tpodserver registry unsubscribe 1 --ethereum-key "$PROVIDER_ go run ../../../cmd/tpodserver registry subscribe 2 --ethereum-key "$PROVIDER_KEY" --registry-contract "$REGISTRY_ADDRESS" --config config.yaml go run ../../../cmd/trustedpods registry get --config config.yaml --ethereum-key "$PUBLISHER_KEY" --registry-contract "$REGISTRY_ADDRESS" --token-contract "$TOKEN_ADDRESS" --region "$REGION" -pkill anvil -ipfs shutdown -rm anvil_output.txt