挂单
首先通过buildOfferCreateTx方法返回一个Transaction对象,然后通过setSecret传入密钥,最后通过submit方法提交挂单。
创建挂单对象
方法:buildOfferCreateTx({});
参数:
参数 | 类型 | 说明 | |
type | String | 挂单类型,固定的两个值:Buy、Sell | |
account | String | 挂单方账号 | |
platform | String | 平台标识账号,可选 | |
taker_gets | Object | 对方得到的,即挂单方支付的 | |
value | String | 数量 | |
currency | String | 货币种类 | |
issuer | String | 货币发行方 | |
taker_pays | Object | 对方支付的,即挂单方获得的 | |
value | String | 数量 | |
currency | String | 货币种类 | |
issuer | String | 货币发行方 |
返回:Transaction对象
传入密钥
方法:setSecret(secret);
参数:
参数 | 类型 | 说明 |
---|---|---|
secret | String | 井通钱包私钥 |
提交挂单
方法:submit(callback);
参数:无
挂单完整例子
var jlib = require('jingtum-lib');
var Remote = jlib.Remote;
var remote = new Remote({server: 'ws://xxx:port', local_sign:true});
remote.connect(function(err, result) {
if (err) {
return console.log('err:',err);
}
var options = {
type: 'Sell',
account: 'jwGvKK2ucU655SoisjozB6h7fwgEhgrjzo',
taker_gets: {
value: '2',
currency: 'TES',
issuer: 'jap88hkJo5fa6ZSDSS1BqFKCcgMq6XmCGV'
},
taker_pays: {
value: '10',
currency: 'SWT',
issuer: ''
}
};
var tx = remote.buildOfferCreateTx(options);
tx.setSecret('sh...qXV');
tx.submit(function(err, result) {
if(err) {console.log('err:',err);}
else if(result){
console.log('res:', result);
}
});
});
返回结果:
{
engine_result: 'tesSUCCESS',
engine_result_code: 0,
engine_result_message: 'The transaction was applied. Only final in a validated ledger.',
tx_blob: '1200072200080000240000000264400000000098968065D4871AFD498D00000000000000000000000000005445530000000000372F41F07B72D8675DE118EC19F4ED9CD9A3AE9D684000000000002710732103D73F562D98E7669259C96A20336AE9252986EFE5398614603C04C76327CBE253744630440220116E1B5D2917518BD494223761ED1206B4AF3B34A7D47F9FD7179B57C47DF74E022052649D3E8ADA84E457D30022E472BFDC76D29F7AE53C157E0F46C4217F366E48811465BBE098859BF1021204025A48C6CB08264639D8',
tx_json:
{ Account: 'jwGvKK2ucU655SoisjozB6h7fwgEhgrjzo',
Fee: '10000',
Flags: 524288,
Sequence: 2,
SigningPubKey: '03D73F562D98E7669259C96A20336AE9252986EFE5398614603C04C76327CBE253',
TakerGets:
{ currency: 'TES',
issuer: 'jap88hkJo5fa6ZSDSS1BqFKCcgMq6XmCGV',
value: '2' },
TakerPays: '10000000',
TransactionType: 'OfferCreate',
TxnSignature: '30440220116E1B5D2917518BD494223761ED1206B4AF3B34A7D47F9FD7179B57C47DF74E022052649D3E8ADA84E457D30022E472BFDC76D29F7AE53C157E0F46C4217F366E48',
hash: '0FEC5DCBABFF035FF7A1A01985863A29D9F30F749140EB3330AFA2A604FB9B7F' }
}
返回结果说明:
参数 | 类型 | 说明 | ||
engine_result | String | 请求结果 | ||
engine_result_code | Integer | 请求结果编码 | ||
engine_result_message | String | 请求结果message信息 | ||
tx_blob | String | 16进制签名后的交易 | ||
tx_json | Object | 交易内容 | ||
Account | String | 账号地址 | ||
Fee | String | 燃料费 | ||
Platform | String | 平台标记账号,设置了才有 | ||
Flags | Integer | 交易标记 | ||
Sequence | Integer | 单子序列号 | ||
SigningPubkey | String | 签名公钥 | ||
TakerGets | Object/String | 对家得到的,基本币种为字符串类型 | ||
value | String | 数量 | ||
currency | String | 货币种类 | ||
issuer | String | 货币发行方 | ||
TakerPays | Object/String | 对家支付的,基本币种为字符串类型 | ||
value | String | 数量 | ||
currency | String | 货币种类 | ||
issuer | String | 货币发行方 | ||
Timestamp | Integer | 时间戳,签名方式没有该字段 | ||
TransactionType | String | 交易类型:OfferCreate表示挂单类型 | ||
TxnSignature | String | 交易签名 | ||
hash | String | 交易hash |