Comparing version 1.0.23 to 1.0.24
49
index.js
@@ -384,16 +384,31 @@ var CryptoJS = require('crypto-js') | ||
sendTransaction: (tx, cb) => { | ||
avalon.sendRawTransaction(tx, function(error, headBlock) { | ||
if (error) | ||
cb(error) | ||
// sends a transaction to a node | ||
// waits for the transaction to be included in a block | ||
// 200 with head block number if confirmed | ||
// 408 if timeout | ||
// 500 with error if transaction is invalid | ||
fetch(avalon.randomNode()+'/transactWaitConfirm', { | ||
method: 'post', | ||
headers: { | ||
'Accept': 'application/json, text/plain, */*', | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(tx) | ||
}).then(function(res) { | ||
if (res.status === 500 || res.status === 408) | ||
res.json().then(function(err) { | ||
cb(err) | ||
}) | ||
else if (res.status === 404) | ||
cb({error: 'Avalon API is down'}) | ||
else | ||
setTimeout(function() { | ||
avalon.verifyTransaction(tx, headBlock, 5, function(error, block) { | ||
if (error) console.log(error) | ||
else cb(null, block) | ||
}) | ||
}, 1500) | ||
res.text().then(function(headBlock) { | ||
cb(null, parseInt(headBlock)) | ||
}) | ||
}) | ||
}, | ||
sendRawTransaction: (tx, cb) => { | ||
// sends the transaction to a node | ||
// 200 with head block number if transaction is valid and node added it to mempool | ||
// 500 with error if transaction is invalid | ||
fetch(avalon.randomNode()+'/transact', { | ||
@@ -417,2 +432,16 @@ method: 'post', | ||
}, | ||
sendTransactionDeprecated: (tx, cb) => { | ||
// old and bad way of checking if a transaction is confirmed in a block | ||
avalon.sendRawTransaction(tx, function(error, headBlock) { | ||
if (error) | ||
cb(error) | ||
else | ||
setTimeout(function() { | ||
avalon.verifyTransaction(tx, headBlock, 5, function(error, block) { | ||
if (error) console.log(error) | ||
else cb(null, block) | ||
}) | ||
}, 1500) | ||
}) | ||
}, | ||
verifyTransaction: (tx, headBlock, retries, cb) => { | ||
@@ -419,0 +448,0 @@ var nextBlock = headBlock+1 |
{ | ||
"name": "javalon", | ||
"version": "1.0.23", | ||
"version": "1.0.24", | ||
"description": "javascript api for the avalon blockchain", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
512443
637
25