btcOperator v1.0.11
- Added createSignedTx: creates a signed tx (same as sendTx, but doesnt broadcast) - Added transactionID: returns the txid of the tx_hex (or tx-object)
This commit is contained in:
parent
c38b7257cf
commit
87f0260fe4
@ -1,4 +1,4 @@
|
|||||||
(function (EXPORTS) { //btcOperator v1.0.10b
|
(function (EXPORTS) { //btcOperator v1.0.11
|
||||||
/* BTC Crypto and API Operator */
|
/* BTC Crypto and API Operator */
|
||||||
const btcOperator = EXPORTS;
|
const btcOperator = EXPORTS;
|
||||||
|
|
||||||
@ -39,7 +39,7 @@
|
|||||||
"tx_hex": rawTxHex
|
"tx_hex": rawTxHex
|
||||||
},
|
},
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
error: e => reject(e.responseJSON),
|
error: e => reject((e.responseJSON && e.responseJSON.status === "fail") ? null : e.responseJSON),
|
||||||
success: r => r.status === "success" ? resolve(r.data.txid) : reject(r)
|
success: r => r.status === "success" ? resolve(r.data.txid) : reject(r)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -451,6 +451,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
btcOperator.sendTx = function (senders, privkeys, receivers, amounts, fee, change_addr = null) {
|
btcOperator.sendTx = function (senders, privkeys, receivers, amounts, fee, change_addr = null) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
createSignedTx(senders, privkeys, receivers, amounts, fee, change_addr).then(result => {
|
||||||
|
debugger;
|
||||||
|
broadcastTx(result.transaction.serialize())
|
||||||
|
.then(txid => resolve(txid))
|
||||||
|
.catch(error => reject(error));
|
||||||
|
}).catch(error => reject(error))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const createSignedTx = btcOperator.createSignedTx = function (senders, privkeys, receivers, amounts, fee, change_addr = null) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
({
|
({
|
||||||
@ -484,10 +495,7 @@
|
|||||||
console.debug("Unsigned:", tx.serialize());
|
console.debug("Unsigned:", tx.serialize());
|
||||||
new Set(wif_keys).forEach(key => console.debug("Signing key:", key, tx.sign(key, 1 /*sighashtype*/))); //Sign the tx using private key WIF
|
new Set(wif_keys).forEach(key => console.debug("Signing key:", key, tx.sign(key, 1 /*sighashtype*/))); //Sign the tx using private key WIF
|
||||||
console.debug("Signed:", tx.serialize());
|
console.debug("Signed:", tx.serialize());
|
||||||
debugger;
|
resolve(result);
|
||||||
broadcastTx(tx.serialize())
|
|
||||||
.then(txid => resolve(txid))
|
|
||||||
.catch(error => reject(error));
|
|
||||||
}).catch(error => reject(error));
|
}).catch(error => reject(error));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -664,6 +672,15 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btcOperator.transactionID = function (tx) {
|
||||||
|
tx = deserializeTx(tx);
|
||||||
|
let clone = coinjs.clone(tx);
|
||||||
|
clone.witness = null;
|
||||||
|
let raw_bytes = Crypto.util.hexToBytes(clone.serialize());
|
||||||
|
let txid = Crypto.SHA256(Crypto.SHA256(raw_bytes, { asBytes: true }), { asBytes: true }).reverse();
|
||||||
|
return Crypto.util.bytesToHex(txid);
|
||||||
|
}
|
||||||
|
|
||||||
btcOperator.getTx = txid => new Promise((resolve, reject) => {
|
btcOperator.getTx = txid => new Promise((resolve, reject) => {
|
||||||
fetch_api(`tx/BTC/${txid}`)
|
fetch_api(`tx/BTC/${txid}`)
|
||||||
.then(result => resolve(result.data))
|
.then(result => resolve(result.data))
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
</script>
|
</script>
|
||||||
<script src="lib.js"></script>
|
<script src="lib.js"></script>
|
||||||
<script src="floCrypto.js"></script>
|
<script src="floCrypto.js"></script>
|
||||||
|
<script src="btcOperator.js"></script>
|
||||||
<script src="floBlockchainAPI.js"></script>
|
<script src="floBlockchainAPI.js"></script>
|
||||||
<script src="floTokenAPI.js"></script>
|
<script src="floTokenAPI.js"></script>
|
||||||
<script src="compactIDB.js"></script>
|
<script src="compactIDB.js"></script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user