-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
477 lines (393 loc) · 17.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
const kanban = require('./services/kanban');
var secret = require('./services/secret.json');
const config = require('./services/config');
const exaddr = require('./services/exaddr');
const main = async function() {
const mnemonic = "dune stem onion cliff equip seek kiwi salute area elegant atom injury";
let {
privateKey, address,
privateKeyBTC, addressBTC,
privateKeyETH, addressETH,
privateKeyTRX, addressTRX,
privateKeyLTC, addressLTC,
privateKeyDOGE, addressDOGE,
privateKeyBCH, addressBCH
} = kanban.getWalletIdentity(mnemonic);
/*
const body = {
currency: "USDT",
items: [
{
title: "apple",
giveAwayRate: 12,
taxRate: 13,
lockedDays: 366,
price: 10,
quantity: 2
},
{
title: "balance",
giveAwayRate: 12,
taxRate: 13,
lockedDays: 90,
price: 5,
quantity: 3
}],
store: "620bc00f2670171289caee54",
totalSale: 35,
totalTax: 4.55,
totalShipping: 20
};
const order = await kanban.createOrder(body);
//创建订单
console.log('order=', order);
const orderTemplate = await kanban.createOrderTemplate(body);
//创建订单模版
const qrcode1 = kanban.generateQrcodeByOrder(order._id);
//生成订单二维码
const qrcode3 = kanban.generateQrcodeByOrderTemplate(orderTemplate._id);
//生成订单模版二维码
const qrcode2 = kanban.generateQrcodeByStore("620bc00f2670171289caee54");
//生成商店二维码
console.log('qrcode1===', qrcode1);
console.log('qrcode2===', qrcode2);
console.log('qrcode3===', qrcode3);
//const orderid = order._id;
const orderid = '620d871b2d08661afbfcaa65';
const pay1 = await kanban.payOrder(privateKey, address, orderid);
//支付订单
console.log('pay1=', pay1);
const pay3 = await kanban.payOrderTemplate(privateKey, address, orderTemplate._id);
console.log('pay3===', pay3);
/*
const pay2 = await kanban.payStore(privateKey, address, "620bc00f2670171289caee54", 'USDT', 1000, 'pay for tutorfee');
//向商店付款
console.log('pay2=', pay2);
const order2 = await kanban.getOrder(order._id);
//paymentStatus: Number, //0: waiting for pay, 1: paid already, 2: finished, 3: cancelled, 4: frozened, 5: request refund, 6: refunded
console.log('order2=', order2);
*/
/*
const info = await kanban.get7StarInfo(address);
console.log('info===', info);
//address = '186UP7dhSaLo833xNVP8UU14KLXzeWQjUU';
const isValid = await kanban.isValidMember(address);
console.log('isValid====', isValid);
*/
/*
const balances = await kanban.getWalletBalances( //钱包数量和价格
address, addressBTC, addressETH, addressTRX, addressLTC, addressDOGE, addressBCH
);
console.log('balances33333=', balances);
*/
/*
let ret = await kanban.deposit('TRX', null, 6, privateKeyTRX, addressTRX, privateKey, address, 0.1214, {});
console.log('ret===', ret);
*/
/*
const balances = await kanban.getWalletBalances( //钱包数量和价格
address, addressBTC, addressETH, addressTRX, addressLTC, addressDOGE, addressBCH
);
console.log('balances33333=', balances);
*/
/*
address = '1Lvf95PtnGD8n91arhqxJk53L7v3iLLGoJ';
const pageSize = 10;
const pageNum = 2;
let ret = await kanban.getLockerDetails(address, pageSize, pageNum); //获取锁仓明细
console.log('ret===', ret);
*/
/*
const smartContractAddr = '0x340c50c2602dbefdc4009fe99b21e7c30e3ff0cf';
const orderId = '0x3554402a9786447e93d134ef615c64365ddda6bf26035ec61c5f9824526c4c5e';
const respMerchant = await kanban.getMerchantBySmartContractAddress(smartContractAddr);
console.log('respMerchant===', respMerchant);
console.log('address=', address);
*/
/*
const refundResp = await kanban.refund(privateKey, smartContractAddr, orderId); // by merchant
console.log('refundResp====', refundResp);
*/
/*
const transactionHistory = await kanban.getTransactionHistoryEvents( //钱包转七星和七星转钱包明细
address, addressBTC, addressETH, addressTRX, addressLTC, addressDOGE, addressBCH
);
console.log('transactionHistory=', transactionHistory);
const pageSize = 10;
const pageNum = 1;
const dateCreated = '2021-12-18';
let transactions = await kanban.get7StarTransactions(address, pageSize, pageNum, dateCreated); //收入和支出: from=address为支出, merchantRecipient=address为收入
console.log('transactions=', transactions);
transactions = await kanban.get7StarTransactions(address, pageSize, pageNum);
console.log('transactions=', transactions);
let ret = await kanban.getLightningRemitTransactions(address, pageSize, pageNum); //获取闪汇明细 (待完成)
ret = await kanban.getLightningRemitTransactions(address, pageSize, pageNum, dateCreated); //获取闪汇明细 (待完成)
ret = await kanban.getLockerDetails(address, pageSize, pageNum); //获取锁仓明细
ret = await kanban.getLockerDetails(address, pageSize, pageNum, dateCreated); //获取锁仓明细
*/
/*
console.log('address==', address);
console.log('addressBTC==', addressBTC);
console.log('addressETH==', addressETH);
console.log('addressTRX==', addressTRX);
console.log('addressLTC==', addressLTC);
console.log('addressDOGE==', addressDOGE);
console.log('addressBCH==', addressBCH);
console.log('privateKey==', privateKey);
console.log('privateKeyBTC==', privateKeyBTC);
console.log('privateKeyETH==', privateKeyETH);
console.log('privateKeyTRX==', privateKeyTRX);
console.log('privateKeyLTC==', privateKeyLTC);
console.log('privateKeyDOGE==', privateKeyDOGE);
console.log('privateKeyBCH==', privateKeyBCH);
/*
const balances = await kanban.getWalletBalances( //钱包数量和价格
address, addressBTC, addressETH, addressTRX, addressLTC, addressDOGE, addressBCH
);
*/
//let feeChargerSmartContractAddress = store.feeChargerSmartContractAddress;
/*
const feeChargerSmartContractAddress = '0x340c50c2602dbefdc4009fe99b21e7c30e3ff0cf';
const totalAmount = 179.4;
const taxAmount = 41.4;
//const orderId = '0x' + kanban.makeid(64);
const orderId = '0x541779c2165a4ffbbccb4dd05a968aa7d99ff5db108640775f132c84eda389c3';
console.log('orderId=', orderId);
const coinNew = 'USDT';
//let ret = await kanban.deposit('ETH', config.addresses.smartcontract.USDT.ETH, 6, privateKeyETH, addressETH, privateKey, address, 1, {});
///console.log('ret===', ret);
//const chargeFundResp = await kanban.chargeFund(privateKey, feeChargerSmartContractAddress, orderId, coinNew, totalAmount, taxAmount);
//console.log('chargeFundResp===', chargeFundResp);
let ret = await kanban.deposit('ETH', config.addresses.smartcontract.USDT.ETH, 6, privateKeyETH, addressETH, privateKey, address, 2.056, {});
//console.log('balances===', balances);
*/
/*
const respMerchant = await kanban.getMerchantBySmartContractAddress(feeChargerSmartContractAddress);
//通过智能合约获取商户信息
console.log('respMerchant===', respMerchant);
const qrcodeString = kanban.generateQrcode(feeChargerSmartContractAddress, orderId, coinNew, totalAmount, taxAmount);
//生成支付二维码
console.log('qrcodeString===', qrcodeString);
const chargeFunFromQrcode = await kanban.chargeFundFromQrcode(privateKey, qrcodeString);
//扫描二维码支付
console.log('chargeFunFromQrcode===', chargeFunFromQrcode);
*/
/*
let ret = await kanban.sendTransaction('BTC', null, 8, privateKeyBTC, addressBTC, 'mzUQnX1Bgoy2SrMjfBM33F64g5Mub7avX9', 0.001, {}, true);
ret = await kanban.sendTransaction('FAB', null, 8, privateKey, address, 'mjxXkdgZxyQJ8B9i8Xow7jEmEQyQGzp97r', 10, {}, true);
ret = await kanban.sendTransaction('LTC', null, 8, privateKeyLTC, addressLTC, 'n3VDXYPaz9e3RyYvBbn8XzTLpxPwpwWj6Y', 10, {}, true);
ret = await kanban.sendTransaction('ETH', null, 18, privateKeyETH, addressETH,
'0x9b3897652a033916b733b2c39aa98a79cf64470e', 0.01,
{
gasPrice: 100,
gasLimit: 21000
}, true);
ret = await kanban.sendTransaction('ETH', // USDT-ERC20
config.addresses.smartcontract.USDT.ETH,
6, privateKeyETH, addressETH,
'0x9b3897652a033916b733b2c39aa98a79cf64470e', 0.01,
{
gasPrice: 100,
gasLimit: 70000
}, true);
ret = await kanban.sendTransaction( // EXG
'FAB',
config.addresses.smartcontract.EXG.FAB,
18, privateKey, address,
'mw1H8n3QqTFCT4cdikkB8stsoeids8yaeC', 20,
{
satoshisPerBytes: 100,
bytesPerInput: 152,
gasPrice: 40,
gasLimit: 100000
}, true);
ret = await kanban.sendTransaction('TRX', null, 6, privateKeyTRX, addressTRX, 'TSGTqL78E6x1PGqrv6Cw7R4yXYRiXU1kwR', 1, {}, true);
//console.log('ret===', ret);
// USDT-TRC20
ret = await kanban.sendTransaction('TRX', config.addresses.smartcontract.USDT.TRX, 6, privateKeyTRX, addressTRX, 'TSGTqL78E6x1PGqrv6Cw7R4yXYRiXU1kwR', 1, {}, true);
*/
//let ret = await kanban.deposit('FAB', null, 8, privateKey, address, privateKey, address, 13, {}); //存款
//let ret = await kanban.deposit('BTC', null, 8, privateKeyBTC, addressBTC, privateKey, address, 0.002, {});
//let ret = await kanban.deposit('ETH', null, 18, privateKeyETH, addressETH, privateKey, address, 0.056, {});
//let ret = await kanban.deposit('ETH', config.addresses.smartcontract.USDT.ETH, 6, privateKeyETH, addressETH, privateKey, address, 2.056, {});
//let ret = await kanban.deposit('FAB', config.addresses.smartcontract.EXG.FAB, 18, privateKey, address, privateKey, address, 2.056, {});
//let ret = await kanban.deposit('TRX', null, 6, privateKeyTRX, addressTRX, privateKey, address, 1, {});
//let ret = await kanban.deposit('TRX', config.addresses.smartcontract.USDT.TRX, 6, privateKeyTRX, addressTRX, privateKey, address, 0.1, {});
//ret = await kanban.getTransactionFee('TRX', null, 6, addressTRX, 1);
//ret = await kanban.getTransactionFee('TRX', config.addresses.smartcontract.USDT.TRX, 6, addressTRX, 1);
//ret = await kanban.getTransactionFee('BTC', null, 8, addressBTC, 0.01);
//ret = await kanban.getTransactionFee('FAB', null, 8, address, 0.01);
//ret = await kanban.getTransactionFee('FAB', config.addresses.smartcontract.EXG.FAB, 8, address, 0.01);
//ret = await kanban.getTransactionFee('ETH', null, 18, address, 0.01);
//ret = await kanban.getTransactionFee('ETH', config.addresses.smartcontract.USDT.ETH, 6, address, 0.01);
//console.log('rettt=', ret);
/*
const redepositList = await kanban.getRedepositList(address); //获取确认存款列表
console.log('redepositList=', redepositList);
for(let i = 0; i < redepositList.length; i++) {
console.log('i===', i);
const redepositItem = redepositList[i];
const coinType = redepositItem.coinType;
const transactionID = redepositItem.transactionID;
const amount = redepositItem.amount;
const signature = {r: redepositItem.r, s: redepositItem.s, v: redepositItem.v};
await kanban.redeposit(coinType, amount, transactionID, privateKey, address, signature); //确认存款
}
*/
/*
let ret = await kanban.withdraw('FAB', null, privateKey, address, 'n1eXG5oe6wJ6h43akutyGfphqQsY1UfAUR', 1);
console.log('ret====', ret);
*/
//let ret = await kanban.withdraw('BTC', null, privateKey, address, 'muQDw5hVmFgD1GrrWvUt6kjrzauC4Msaki', 0.02);
//let ret = await kanban.withdraw('FAB', config.addresses.smartcontract.EXG.FAB, privateKey, address, 'n1eXG5oe6wJ6h43akutyGfphqQsY1UfAUR', 100);
//let ret = await kanban.withdraw('ETH', null, privateKey, address, '0x02c55515e62a0b25d2447c6d70369186b8f10359', 0.2);
//console.log('ret====', ret);
/*
let ret = await kanban.addGas(privateKey, address, 0.1, {}); //购买gas
console.log('ret===', ret);
*/
//const pageSize = 10;
//const pageNum = 1;
/*
let ret = await kanban.getLockerDetails(address, pageSize, pageNum); //获取锁仓明细
console.log('ret in getLockerDetails====', ret);
*/
/*
const lightningRemitAddress = await kanban.getLightningRemitAddress(address); //获取闪汇地址
console.log('lightningRemitAddress===', lightningRemitAddress);
const tokenName = 'USDT';
//const ret = await kanban.lightningRemit(privateKey, address, 'oMJwh4siohFoPui4ED9D4EKukS1B7YjeJP', tokenName, 1.1); //闪汇转账
const ret = await kanban.getLightningRemitTransactions(address, pageSize, pageNum); //获取闪汇明细
console.log('ret===', ret);
*/
/*
const addressHex = kanban.fabToExgAddress(address);
console.log('addressHex==', addressHex);
const nonce = await kanban.getTransactionCount(addressHex);
console.log('nonce=', nonce);
*/
const name = 'store';
const nameChinese = '中文店铺';
const addr = '888 sss ave';
const addrChinese = '中文地址';
const contactName = 'mr. zhang';
const contactNameChinese = '张先生';
const phone = '666775544';
const fax = '566665443';
const email = '[email protected]';
const website = 'store';
const openTime = '9:00 am';
const closeTime = '6:00 pm';
const businessContents = 'online store for nutrition';
const businessContentsChinese = '主营业务,在线电子商务';
const coin = 'USDT';
const giveAwayRate = 15;
const taxRate = 13;
const refAddress = '14h3WSyJva6itCpZ7pirXwLpK52Ek3qHGz';
const image = '';
const hideOnStore = true;
const fabAddress = 'mzUQnX1Bgoy2SrMjfBM33F64g5Mub7avX9';
const toKbAddress = exaddr.toKbpayAddress(fabAddress);
const amount = 0.1;
const resBinPay = await kanban.bindPay(privateKey, address, toKbAddress, coin, amount);
console.log('resBinPay=', resBinPay);
/*
const store = await kanban.getStore(address);
const resp = await kanban.updateStore( // 修改商店
privateKey,
store._id,
name,
nameChinese,
addr,
addrChinese,
contactName,
contactNameChinese,
phone,
fax,
email,
website,
openTime,
closeTime,
businessContents,
businessContentsChinese,
coin,
giveAwayRate,
taxRate,
image,
hideOnStore
);
//console.log('resppp=', resp);
*/
/*
const notify_url = "https://7star.xiaomustang.com//api/notice/store_check";
// data: store对象
const resp = await kanban.createStore( // 生成商店
privateKey,
name,
nameChinese,
addr,
addrChinese,
contactName,
contactNameChinese,
phone,
fax,
email,
website,
openTime,
closeTime,
businessContents,
businessContentsChinese,
coin,
giveAwayRate,
taxRate,
refAddress,
image,
hideOnStore,
notify_url
);
console.log('resp==', resp);
if(resp && resp.ok) {
const store = resp._body;
console.log('new store=', store);
} else {
console.log('resp===', resp);
}
*/
//const storeId = '61cbeb9e56c2fb67f608194b';
//const deleted = await kanban.deleteStore(privateKey, storeId);
//console.log('deleted===', deleted);
/*
const status = await kanban.getStoreStatus(address);
//address: store owner的钱包地址
// -1: store不存在, 0: 待审核 1:审核通过
let feeChargerSmartContractAddress = store.feeChargerSmartContractAddress;
*/
/*
feeChargerSmartContractAddress = '0x1e89b7d555fe1b68c048b68eb28724950e1051f2';
const totalAmount = 10;
const taxAmount = 1.3;
const orderId = '0x' + kanban.makeid(64);
const chargeFundResp = await kanban.chargeFund(privateKey, feeChargerSmartContractAddress, orderId, coin, totalAmount, taxAmount);
//支付
console.log('chargeFundResp===', chargeFundResp);
*/
/*
const requestRefundResp = await kanban.requestRefund(privateKey, feeChargerSmartContractAddress, orderId); // by customer
//请求退款
const cancelRefundRequestResp = await kanban.cancelRefundRequest(privateKey, feeChargerSmartContractAddress, orderId); // by customer
//撤销退款请求
const refundResp = await kanban.refund(privateKey, feeChargerSmartContractAddress, orderId); // by merchant
//批准退款
const gas = await kanban.getGas(address); //获取燃料余额
//console.log('gas=', gas);
const pageSize = 10;
const pageNum = 1;
address = 'n1eXG5oe6wJ6h43akutyGfphqQsY1UfAUR';
const transactions = await kanban.get7StarTransactions(address, pageSize, pageNum); //收入和支出: from=address为支出, merchantRecipient=address为收入
console.log('transactions===', transactions);
const balances = await kanban.get7StarBalance(address); //当前余额
console.log('balances==', balances);
*/
}
main();
// 分页,主动查询审核状态,异步通知