Created
May 15, 2019 22:06
-
-
Save xterr/0578a856a5f74638e9d1f14d392ddf89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async _sendTransaction(fromAddresses, toAddresses) { | |
const oTransaction = await this._oTransactionsManager._createTransaction( | |
fromAddresses, | |
toAddresses, | |
undefined, // nonce | |
undefined, // timeLock | |
undefined, // version @FIXME This is not calculated if validateVersion === false, | |
undefined, // txId | |
false, false, true, true, true, false, | |
); | |
const fee = this._oTransactionsManager.wizard.calculateFeeWizzard(oTransaction.serializeTransaction(true)); | |
// @TODO find a way to distribute the fee for multi inputs | |
oTransaction.from.addresses[0].amount += fee; | |
oTransaction.from.addresses = await Promise.all(oTransaction.from.addresses.map(async (aFromAddress) => { | |
const aFromAddressResult = aFromAddress; | |
aFromAddressResult.signature = await this._oWallet.getAddress(aFromAddress.address).signTransaction(oTransaction, aFromAddress.password); | |
delete aFromAddressResult.password; | |
return aFromAddressResult; | |
})); | |
// This is needed because the fromAmount is changing | |
oTransaction.serializeTransaction(true); | |
try { | |
oTransaction.isTransactionOK(); | |
} catch (e) { | |
throw new Error(`Validation for the transaction failed. Error: ${e.message}`); | |
} | |
await this._oTransactionsManager.pendingQueue.includePendingTransaction(oTransaction, undefined, true); | |
return oTransaction.txId.toString('hex'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment