atn-lib
v0.3.0-alpha
Published
a light client lib for Dbot
Readme
atn-lib v0.3.0-alpha
A light client lib for consumer to call ATN AI services.
Installation
Using npm:
$ npm i --save atn-lib
$ npm i --save [email protected]In Node.js:
var AtnLib = require('atn-lib');
const lib = new AtnLib(
"yourPrivateKey", // private key
"rpcProvider" // host and port Parity/Geth serves RPC requests on
);Note: Your account should be existed in Kovan.
Usage
µraiden
Step 1:
Getting all AI info
lib.getAiList()
Step 2:
Choosing an AI to use
lib.getAiInfo(aiId)
Step 3:
Opening a transfer channel
lib.openChannel(aiInfo.dbot_receiver, deposit)
Step 4:
Getting the price of the AI
lib.getPrice(aiInfo.dbot_url, aiInfo.name)
Step 5: Calling the AI
lib.callAI(
aiInfo.dbot_url,
aiInfo.name,
input,
aiInfo.dbot_receiver,
block,
balance,
fee
);smart contract
Step 1:
Getting all AI info
lib.getAiList()
Step 2:
Choosing an AI to use
lib.getAiInfo(aiId)
Step 3:
Calling the AI
lib.directlyCallAI(aiInfo.name, aiInfo.bill_kovan_addr, input)
Example
see in simple.js
API in Detail
getAiList
lib.getAiList()
Parameters
none
Returns
Array: The list of all AI:
AI Objectid-Number: The id of AItype-String: The type of AIname-String: The name of AIbill_type-String: The bill type of AI'0': free'1': times'2': interval
bill_kovan_addr-String: The address of billing contract in Kovandbot_url-String: Host and port dbot serves requests ondbot_receiver-String: The address of dbot providerparams-String: The AI's parametersname-String: The key of parametertype-String: The type of parameterrequired-Number: The parameter is required or not1: required0: options
getAiInfo
lib.getAiInfo(id)
Parameters
id-Number: The id of AI
Returns
openChannel
lib.openChannel(receiver, deposit)
Parameters
receiver-
String: The address of dbot providerdeposit-Number: Deposit value(number of ATN)
Returns
Result: The opened channel info
0: The key of channel1: The balance of deposit value2: Settle block number of closing requests3: Closing balance of closing requests4: Opening block number5: The address of receiver6: The address of sender
topUpChannel
lib.topUpChannel(receiver, block, deposit)
Parameters
- receiver-
String: The address of dbot provider - block-
Number: Opening block number deposit-Number: Topup value(number of ATN)
Returns
Result: The topup channel info
getChannels
lib.getChannels(dbot_url, block, status)
Parameters
- dbot_url-
String: Host and port dbot serves requests on - block(options)-
Number: Opening block number status(options)-String:
all: all status channelsopen/opened(default): opened channelsclosed: closed channels
Returns
channel info:
- receiver: The address of dbot provider
sender: The address of senderdeposit: Deposit value(number of ATN) of the channel- open_block_number: Opening block number
balance: The number of ATN which the channel used
closeChannel
lib.closeChannel(dbot_url, receiver, block, balance)
Parameters
- dbot_url-
String: Host and port dbot serves requests on - receiver-
String: The address of dbot provider - block-
Number: Opening block number balance-Number: The number of ATN which the channel used
Returns
receipt: The receipt of close channel
getPrice
lib.getPrice(dbot_url, ai_name)
Parameters
Returns
fee: The cost of calling AI
callAI
lib.callAI(dbot_url, ai_name, input, receiver, block, balance, price)
Parameters
- dbot_url-
String: Host and port dbot serves requests on - ai_name-
String: The name of AI - input-
Object: An object build with ai parameters - receiver-
String: The address of dbot provider - block-
Number: Opening block number - balance-
Number: The number of ATN which the channel used - price-
Number: The cost of calling AI
Returns
Result: The result of calling AI
directlyGetPrice
lib.directlyGetPrice(ai_name)
Parameters
- ai_name-
String: The name of AI
Returns
fee: The cost of calling AI
directlyCallAI
lib.directlyCallAI(ai_name, bill_addr, input)
Note: In this way, you should use ws interface to init the lib
Parameters
- ai_name-
String: The name of AI - bill_addr-
String: The address of billing contract in Kovan - input-
Number: An object build with ai parameters
Returns
Result: The result of calling AI
