Atn

Atn

Atn class contains all the method

Constructor

new Atn(private_key, rpc_provider, env)

Source:
Parameters:
Name Type Description
private_key string

账户私钥

rpc_provider string

'https://rpc-test.atnio.net' - 连接节点默认为https://rpc-test.atnio.net

env string

= 'prod' - 环境变量默认 prod

Members

(constant) PRODUCT_ENV :string

Default Value:
  • {string} prod
Source:
Type:
  • string

Methods

(async) asyncSleep(timeout) → {Promise.<*>}

设置当前现成休眠时间

Source:
Parameters:
Name Type Description
timeout number

设置等待时间

Returns:
Type:
Promise.<*>

(async) callAPI(dbotAddress, domain, uri, method, option, balance, blockNumber) → {Promise.<void>}

callAPI

Source:
Parameters:
Name Type Description
dbotAddress string

DBot地址

domain string

DBot域名

uri string

EndPoint相对路径

method string

EndPoint请求类型

option object

调用指定DBot需要的请求配置

balance string | number

要签名的Balance

blockNumber string

创建channel所在的块号

Returns:
Type:
Promise.<void>

(async) callDBotAI(dbotAddress, uri, method, option) → {Promise.<(*|void)>}

Source:
Parameters:
Name Type Description
dbotAddress string

DBot地址

uri string

DBot下的指定API相对路径

method string

DBot下的API请求方法类型

option object

option

Returns:
Type:
Promise.<(*|void)>

(async) closeChannel(receiverAddress, balance) → {Promise.<*>}

Source:
Parameters:
Name Type Description
receiverAddress string

DBot地址

balance string | BigNumber

关闭调用通道所需的Balance

Returns:
Type:
Promise.<*>
  • json

(async) createAccount() → {Promise.<Account>}

创建账户

Source:
Returns:
Type:
Promise.<Account>

(async) createChannel(receiverAddress, deposit) → {Promise.<PromiEvent.<TransactionReceipt>>}

创建账户和DBotServer之间的调用通道

Source:
Parameters:
Name Type Description
receiverAddress string

AI Market上DBot地址

deposit string

创建调用通道所需的总次数(1e18的倍数)

Returns:
Type:
Promise.<PromiEvent.<TransactionReceipt>>
  • json example :
     {
         "blockHash": "0x60a779ef28803a01bf825fb0d378e9e40edd9c33ef5d8379274d0fdfe4b1b451",
          "blockNumber": 400442,
          "contractAddress": null,
          "cumulativeGasUsed": 66603,
          "from": "0xa474a12b81b443854414c3c3928b0ec44adfde06",
          "gasUsed": 66603,
          "logs": [
              {
                  "address": "0x0000000000000000000000000000000000000012",
                  "topics": [
                      "0xa55ac5ebdb9bee5da90c5d4a6f104e5e2c116f97967ae2eb73f5fdfbdbb75bcb",
                      "0x000000000000000000000000a474a12b81b443854414c3c3928b0ec44adfde06",
                      "0x0000000000000000000000000aa602cb3a0919a95cb066b9d3ed99d391c395d5"
                  ],
                  "data": "0x00000000000000000000000000000000000000000000000029a2241af62c0000",
                  "blockNumber": 400442,
                  "transactionHash": "0x54168dfed7d0d1b3e5bac787b76ea490fd0c1b5e80674acdea4e241869462220",
                  "transactionIndex": 0,
                  "blockHash": "0x60a779ef28803a01bf825fb0d378e9e40edd9c33ef5d8379274d0fdfe4b1b451",
                  "logIndex": 0,
                  "removed": false,
                  "id": "log_a4ba0d17"
              }
          ],
          "logsBloom": "0x00000000000000000000020000000000000000000000000000000000000010000000000000000000000000000000000000020000000000000000000000000400000000088000000000000000000000000000000000100000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000400",
          "status": true,
          "to": "0x0000000000000000000000000000000000000012",
          "transactionHash": "0x54168dfed7d0d1b3e5bac787b76ea490fd0c1b5e80674acdea4e241869462220",
          "transactionIndex": 0
      }

(async) generateKeyFile(private_key, dirNameFile) → {Promise.<void>}

生成私钥文件

Source:
Parameters:
Name Type Description
private_key

账户私钥

dirNameFile

所在项目根目录下的文件名 eg. '/mypath/key.json'

Returns:
Type:
Promise.<void>

getBalanceProofData(receiverAddress, balance) → {Array.<object>}

获取Balance签名Scheme

Source:
Parameters:
Name Type Description
receiverAddress string

DBot地址

balance string | BigNumber

要签名的Balance

Returns:
Type:
Array.<object>
  • 返回Scheme数组

(async) getChannelDetail(receiverAddress) → {Promise.<*>}

Source:
Parameters:
Name Type Description
receiverAddress string

DBot地址

Returns:
Type:
Promise.<*>
  • json example :
     {
      "status": 1,
      "data": {
          "receiver": "0xE4640e4005903e147EbB54dd9DDf17e85Ce53303",
          "sender": "0xA474A12B81B443854414C3C3928B0eC44AdFdE06",
          "open_block_number": "353401",
          "deposit": "15000000000000000000",
          "balance": "12000000000000000000",
          "state": "OPEN",
          "settle_block_number": "-1",
          "confirmed": true,
          "unconfirmed_topups": {},
          "domain": "https://dbot02.atnio.net"
       }
     }

(async) getChannelInfo(receiverAddress) → {Promise.<{key: any, deposit: *, blockNumber: *}>}

获取账户和DBotServer之间通道信息

Source:
Parameters:
Name Type Description
receiverAddress string

DBot地址

Returns:
Type:
Promise.<{key: any, deposit: *, blockNumber: *}>

(async) getDBotDomain(dbotAddress) → {Promise.<string>}

获取DBot域名

Source:
Parameters:
Name Type Description
dbotAddress string

DBot地址

Returns:
Type:
Promise.<string>

(async) getDBotName(dbotAddress) → {Promise.<string>}

获取DBot名称

Source:
Parameters:
Name Type Description
dbotAddress string

DBot地址

Returns:
Type:
Promise.<string>
  • 返回DBot名称

(async) getPrice(dbotAddress, uri, method) → {Promise.<void>}

获取DBot下的API的价格

Source:
Parameters:
Name Type Description
dbotAddress string

DBot地址

uri string

DBot下的指定API相对路径

method string

DBot下的API请求方法类型

Returns:
Type:
Promise.<void>

handlerDBotDomain(domain, hyperProtocolType) → {string}

Source:
Parameters:
Name Type Description
domain string

DBot域名

hyperProtocolType

默认协议类型http或https

Returns:
Type:
string
  • 返回适配之后的URL前缀

(async) initAccount(private_keyopt) → {Promise.<*>}

Source:
Parameters:
Name Type Attributes Description
private_key string <optional>

账户私钥

Returns:
Type:
Promise.<*>
  • example json :
     {
          "address": "0xd73f8f3882CF279FC556eDBd96acFa9143868745",
          "privateKey": "01adc971225be058c7031b536375b79115ed58993c86a4ec4288f36fc9eb51b7"
      }

(async) initConfig(dirNameFile, dbotAddress, private_key, defaultTopup) → {Promise.<*>}

初始化调用通道

Source:
Parameters:
Name Type Description
dirNameFile string

私钥所在项目根路径名称(默认为JSON文件)

dbotAddress string

DBot地址

private_key string

账户私钥

defaultTopup string

设置默认增加账户值,不传:10e18

Returns:
Type:
Promise.<*>

(async) privateKeyToAccount(private_key) → {Promise.<Account>}

通过私钥获取账户信息

Source:
Parameters:
Name Type Description
private_key string

账户私钥

Returns:
Type:
Promise.<Account>

(async) requestCloseSignature(receiverAddress, balance) → {Promise.<*>}

Source:
Parameters:
Name Type Description
receiverAddress string

DBot地址

balance string | BigNumber

需要签名的Balance

Returns:
Type:
Promise.<*>

(async) setDefaultAccount(private_key) → {Promise.<void>}

设置默认账户

Source:
Parameters:
Name Type Description
private_key string

账户私钥

Returns:
Type:
Promise.<void>

signBalanceProof(receiverAddress, balance) → {String}

获取Balance的签名

Source:
Parameters:
Name Type Description
receiverAddress string

DBot地址

balance string

需要签名的Balance

Returns:
Type:
String

signMessage(hash) → {String}

签名Hash算法

Source:
Parameters:
Name Type Description
hash string

需要签名的hash

Returns:
Type:
String

(async) topUpChannel(receiverAddress, value) → {Promise.<*>}

增加通道调用次数

Source:
Parameters:
Name Type Description
receiverAddress string

DBot地址

value string | BigNumber

增加Channel账户余额

Returns:
Type:
Promise.<*>
  • json example :
     {
          "blockHash": "0xbda32b2468966071cd59e7595b280b3c4eaf3e35125ed9a9ea41b793863a1dd9",
          "blockNumber": 559929,
          "contractAddress": null,
          "cumulativeGasUsed": 32501,
          "from": "0xa474a12b81b443854414c3c3928b0ec44adfde06",
          "gasUsed": 32501,
          "logs": [
              {
                  "address": "0x0000000000000000000000000000000000000012",
                  "topics": [
                      "0x19034e235e9fae58965e705631a9e662529152bc990b7db2aca8aeb6389f006f",
                      "0x000000000000000000000000a474a12b81b443854414c3c3928b0ec44adfde06",
                      "0x000000000000000000000000e4640e4005903e147ebb54dd9ddf17e85ce53303",
                      "0x000000000000000000000000000000000000000000000000000000000006be88"
                  ],
                  "data": "0x00000000000000000000000000000000000000000000000029a2241af62c0000",
                  "blockNumber": 559929,
                  "transactionHash": "0x1eff8db75a957a8ce80ac6f33cea0342365ef74d275c55eecde349bb47b837f1",
                  "transactionIndex": 0,
                  "blockHash": "0xbda32b2468966071cd59e7595b280b3c4eaf3e35125ed9a9ea41b793863a1dd9",
                  "logIndex": 0,
                  "removed": false,
                  "id": "log_0782a4ac"
              }
          ],
          "logsBloom": "0x00000000000000000000020000000000000000000000000000000000000010000000000000000000000100000000000000000000000000000000000000000400000000008000000000000000000000000000000000001000200000000201000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000100000000000000008000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000",
          "status": true,
          "to": "0x0000000000000000000000000000000000000012",
          "transactionHash": "0x1eff8db75a957a8ce80ac6f33cea0342365ef74d275c55eecde349bb47b837f1",
          "transactionIndex": 0
      }

(async) waitTx(txHash, timeout, confirmations) → {Promise.<{status: string, msg: string}>|Promise.<TransactionReceipt>}

轮询查询交易信息,设置超时时间和确认块数

Source:
Parameters:
Name Type Description
txHash string

交易hash值

timeout number

每个块交易确认时间

confirmations number

要确认的交易的块数

Returns:
Type:
Promise.<{status: string, msg: string}> | Promise.<TransactionReceipt>
  • json example :
     {
       status:0,
       msg:"timeout"
     }
     {
          "blockHash": "0x60a779ef28803a01bf825fb0d378e9e40edd9c33ef5d8379274d0fdfe4b1b451",
          "blockNumber": 400442,
          "contractAddress": null,
          "cumulativeGasUsed": 66603,
          "from": "0xa474a12b81b443854414c3c3928b0ec44adfde06",
          "gasUsed": 66603,
          "logs": [
              {
                  "address": "0x0000000000000000000000000000000000000012",
                  "topics": [
                      "0xa55ac5ebdb9bee5da90c5d4a6f104e5e2c116f97967ae2eb73f5fdfbdbb75bcb",
                      "0x000000000000000000000000a474a12b81b443854414c3c3928b0ec44adfde06",
                      "0x0000000000000000000000000aa602cb3a0919a95cb066b9d3ed99d391c395d5"
                  ],
                  "data": "0x00000000000000000000000000000000000000000000000029a2241af62c0000",
                  "blockNumber": 400442,
                  "transactionHash": "0x54168dfed7d0d1b3e5bac787b76ea490fd0c1b5e80674acdea4e241869462220",
                  "transactionIndex": 0,
                  "blockHash": "0x60a779ef28803a01bf825fb0d378e9e40edd9c33ef5d8379274d0fdfe4b1b451",
                  "logIndex": 0,
                  "removed": false,
                  "id": "log_a4ba0d17"
              }
          ],
          "logsBloom": "0x00000000000000000000020000000000000000000000000000000000000010000000000000000000000000000000000000020000000000000000000000000400000000088000000000000000000000000000000000100000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000400",
          "status": true,
          "to": "0x0000000000000000000000000000000000000012",
          "transactionHash": "0x54168dfed7d0d1b3e5bac787b76ea490fd0c1b5e80674acdea4e241869462220",
          "transactionIndex": 0
      }