Skip to content

Commit

Permalink
resceive block
Browse files Browse the repository at this point in the history
  • Loading branch information
lovelycs committed Oct 29, 2018
1 parent 2f588ee commit 1a6fec0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/Vite/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class Ledger extends basicStruct {

return new Promise((res, rej) => {
this.provider.batch(requests).then((data)=>{
console.log(data);
if (!data || data.length < 2 ||
(pledgeType && (data.length < 3 || !data[2].result))) {
return rej('Batch Error');
Expand Down
34 changes: 20 additions & 14 deletions src/Wallet/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,20 @@ class Account {
}

receiveTx(address, privKey) {
let dealAccountBlock = (accountBlock, res, rej) => {
if (!accountBlock) {
return res();
}

let signTX = (accountBlock) => {
let { hash, signature, pubKey } = this.Vite.Account.signTX(accountBlock, privKey);
accountBlock.hash = hash;
accountBlock.publicKey = Buffer.from(pubKey).toString('base64');
accountBlock.signature = Buffer.from(signature).toString('base64');
return accountBlock;
};

let sendRawTx = (accountBlock, res, rej) => {
if (!accountBlock) {
return res();
}

accountBlock = signTX(accountBlock);
this.Vite['tx_sendRawTx'](accountBlock).then((data)=>{
return res(data);
}).catch((err)=>{
Expand All @@ -69,16 +73,18 @@ class Account {

return new Promise((res, rej) => {
this.Vite.Ledger.getReceiveBlock(address, false).then((accountBlock)=>{
dealAccountBlock(accountBlock, res, rej);
sendRawTx(accountBlock, res, (err) => {
if (err && err.error && err.error.code && err.error.code === -35002) {
this.Vite.Ledger.getReceiveBlock(address, true).then((accountBlock)=>{
sendRawTx(accountBlock, res, rej);
}).catch((err)=>{
return rej(err);
});
return;
}
return rej(err);
});
}).catch((err)=>{
if (err && err.error && err.error.code && err.error.code === -35002) {
this.Vite.Ledger.getReceiveBlock(address).then((accountBlock)=>{
dealAccountBlock(accountBlock, res, rej);
}).catch((err)=>{
rej(err);
});
return;
}
return rej(err);
});
});
Expand Down

0 comments on commit 1a6fec0

Please sign in to comment.