OSDN Git Service

feat: protocol
[bytom/Byone.git] / src / background / transaction.js
1 import bytom from "./bytom";
2
3 function transaction(bytom) {
4   this.bytom = bytom;
5 }
6
7 transaction.prototype.list = function(guid, address, start, limit) {
8   return this.bytom.transaction.list(guid, address, start, limit);
9 };
10
11 transaction.prototype.build = function(guid, to, asset, amount, fee){
12     let retPromise = new Promise((resolve, reject) => {
13         this.bytom.transaction.buildPayment(guid, to, asset, Number(amount*100000000)).then(res => {
14             resolve(res);
15         }).catch(error => {
16             reject(error);
17         });
18     })
19     return retPromise;
20 }
21 transaction.prototype.transfer = function(guid, transaction, password){
22     let retPromise = new Promise((resolve, reject) => {
23         this.bytom.transaction.signTransaction(guid, JSON.stringify(transaction), password).then(ret => {
24             this.bytom.transaction.submitPayment(guid, ret.raw_transaction, ret.signatures).then(res3 => {
25                 resolve(res3);
26             }).catch(error => {
27                 reject(error);
28             });
29         }).catch(error => {
30             reject(error);
31         });
32     })
33
34     return retPromise
35 }
36
37 export default transaction;