diff --git a/cmd/sequencer/clients/contracts/ioID.json b/cmd/sequencer/clients/contracts/ioID.json new file mode 100644 index 0000000..ce63bf1 --- /dev/null +++ b/cmd/sequencer/clients/contracts/ioID.json @@ -0,0 +1,781 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "approved", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "indexed": false, + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "ApprovalForAll", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "wallet", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "did", + "type": "string" + } + ], + "name": "CreateIoID", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "wallet", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "did", + "type": "string" + } + ], + "name": "RemoveDIDWallet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "minter", + "type": "address" + } + ], + "name": "SetMinter", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "resolver", + "type": "address" + } + ], + "name": "SetResolver", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "deviceProject", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_device", + "type": "address" + } + ], + "name": "did", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getApproved", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_minter", + "type": "address" + }, + { + "internalType": "address", + "name": "_walletRegistry", + "type": "address" + }, + { + "internalType": "address", + "name": "_walletImplementation", + "type": "address" + }, + { + "internalType": "string", + "name": "_name", + "type": "string" + }, + { + "internalType": "string", + "name": "_symbol", + "type": "string" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "isApprovedForAll", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_projectId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_device", + "type": "address" + }, + { + "internalType": "address", + "name": "_owner", + "type": "address" + } + ], + "name": "mint", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "minter", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "ownerOf", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "projectDeviceCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_projectId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_start", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_pageSize", + "type": "uint256" + } + ], + "name": "projectIDs", + "outputs": [ + { + "internalType": "address[]", + "name": "array", + "type": "address[]" + }, + { + "internalType": "address", + "name": "next", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_device", + "type": "address" + } + ], + "name": "removeDID", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_id", + "type": "uint256" + } + ], + "name": "resolver", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "setApprovalForAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_minter", + "type": "address" + } + ], + "name": "setMinter", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_id", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_resolver", + "type": "address" + } + ], + "name": "setResolver", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "interfaceId", + "type": "bytes4" + } + ], + "name": "supportsInterface", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "tokenByIndex", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "tokenOfOwnerByIndex", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "tokenURI", + "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": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_id", + "type": "uint256" + } + ], + "name": "wallet", + "outputs": [ + { + "internalType": "address", + "name": "wallet_", + "type": "address" + }, + { + "internalType": "string", + "name": "did_", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_did", + "type": "string" + } + ], + "name": "wallet", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "walletImplementation", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "walletRegistry", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/cmd/sequencer/clients/manager.go b/cmd/sequencer/clients/manager.go index 35861f5..2b66108 100644 --- a/cmd/sequencer/clients/manager.go +++ b/cmd/sequencer/clients/manager.go @@ -26,12 +26,15 @@ var ( abiProjectClient []byte //go:embed contracts/W3bstreamProject.json abiW3bstreamProject []byte + //go:embed contracts/ioID.json + abiIoID []byte ) func NewManager( projectClientContractAddress string, ioIDRegisterContractAddress string, w3bstreamProjectContractAddress string, + ioIDContractAddress string, ioIDRegistryServiceEndpoint string, chainEndpoint string, ) (*Manager, error) { @@ -68,6 +71,15 @@ func NewManager( manager.w3bsteramProjectInstance = instance } + { + name := "ioID" + instance, err := contract.NewInstanceByABI(name, ioIDContractAddress, chainEndpoint, abiIoID) + if err != nil { + return nil, errors.Wrapf(err, "failed to new contract instance: %s", name) + } + manager.ioIDInstance = instance + } + return manager, nil } @@ -77,6 +89,7 @@ type Manager struct { ioIDRegistryInstance contract.Instance projectClientInstance contract.Instance w3bsteramProjectInstance contract.Instance + ioIDInstance contract.Instance ioIDRegistryEndpoint string } @@ -111,11 +124,19 @@ func (mgr *Manager) fetchFromContract(id string) (*Client, error) { var ( address = common.HexToAddress(strings.TrimPrefix(id, "did:io:")) uri string + ioID big.Int + owner common.Address ) if err := mgr.ioIDRegistryInstance.ReadResult("documentURI", &uri, address); err != nil { return nil, errors.Wrapf(err, "failed to read client document uri: %s %s", id, address.String()) } + if err := mgr.ioIDRegistryInstance.ReadResult("deviceTokenId", &ioID, address); err != nil { + return nil, errors.Wrapf(err, "failed to read client device token id: %s %s", id, address.String()) + } + if err := mgr.ioIDRegistryInstance.ReadResult("ownerOf", &owner, ioID); err != nil { + return nil, errors.Wrapf(err, "failed to read client ioID owner: %s %s", id, ioID.String()) + } url := fmt.Sprintf("https://%s/cid/%s", mgr.ioIDRegistryEndpoint, uri) rsp, err := http.Get(url) @@ -132,7 +153,10 @@ func (mgr *Manager) fetchFromContract(id string) (*Client, error) { if err != nil { return nil, errors.Wrap(err, "failed to parse did doc") } - return &Client{jwk: jwk}, nil + return &Client{ + owner: owner, + jwk: jwk, + }, nil } func (mgr *Manager) HasProjectPermission(clientID string, projectID uint64) (bool, error) { diff --git a/cmd/sequencer/main.go b/cmd/sequencer/main.go index d60d6d5..e17feb6 100644 --- a/cmd/sequencer/main.go +++ b/cmd/sequencer/main.go @@ -52,6 +52,7 @@ var ( IoIDRegistryContractAddress string ProjectClientContractAddress string W3bstreamProjectContractAddress string + IoIDContractAddress string ChainEndpoint string IoIDProjectID uint64 }{ @@ -75,6 +76,7 @@ var ( IoIDRegistryContractAddress: "0x0A7e595C7889dF3652A19aF52C18377bF17e027D", ProjectClientContractAddress: "0xF4d6282C5dDD474663eF9e70c927c0d4926d1CEb", W3bstreamProjectContractAddress: "0x6AfCB0EB71B7246A68Bb9c0bFbe5cD7c11c4839f", + IoIDContractAddress: "0x45Ce3E6f526e597628c73B731a3e9Af7Fc32f5b7", ChainEndpoint: "https://babel-api.testnet.iotex.io", // WhiteList: contexts.WhiteList{"103381234567407"}, } @@ -130,7 +132,7 @@ func runHTTP(ctx context.Context) { if err != nil { panic(errors.Wrap(err, "failed to new jwk from secrets")) } - clientMgr, err := clients.NewManager(config.ProjectClientContractAddress, config.IoIDRegistryContractAddress, config.W3bstreamProjectContractAddress, config.IoIDRegistryEndpoint, config.ChainEndpoint) + clientMgr, err := clients.NewManager(config.ProjectClientContractAddress, config.IoIDRegistryContractAddress, config.W3bstreamProjectContractAddress, config.IoIDContractAddress, config.IoIDRegistryEndpoint, config.ChainEndpoint) if err != nil { panic(errors.Wrap(err, "failed to new clients manager")) }