Files

51 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2021-02-15 12:16:14 +01:00
const FloweeServices = require('../');
var Flowee = new FloweeServices();
2019-12-08 21:22:24 +01:00
2019-12-08 23:20:41 +01:00
/*
* This example uses the simplified search.
* It fetches a transaction by ID and the matching block-header for that transaction.
*
* The search() method gets a simple array with "jobs".
*/
2019-12-08 21:22:24 +01:00
2019-12-26 22:05:59 +01:00
if (process.argv.length <= 2) {
console.log("Fetch transaction\nUsage node transaction.js [txid]");
console.log("Example address: b39fa6c39b99683ac8f456721b270786c627ecb246700888315991877024b983\n");
process.exit();
}
2019-12-08 21:22:24 +01:00
function detailTx(txid) {
return Flowee.search([
{
2019-12-08 23:20:41 +01:00
// this job takes a txid and fetches it.
2019-12-08 21:22:24 +01:00
type: Flowee.Job.FetchTx,
2019-12-08 23:20:41 +01:00
value: txid,
2019-12-08 21:22:24 +01:00
txFilter: [ Flowee.IncludeInputs, Flowee.IncludeOutputs ]
},
{
2019-12-08 23:20:41 +01:00
// this job fetches the block header.
// This job type needs a block height as a value.
// Instead of passing it in, the Flowee search method will realize it can reuse the
// blockheight that the previous (the FetchTx above) job returns anyway.
2019-12-08 21:22:24 +01:00
type: Flowee.Job.FetchBlockHeader
}
]);
}
Flowee.connect().then(async function() {
try {
2019-12-26 22:05:59 +01:00
for (arg in process.argv) {
if (arg > 1) { // nodejs, skip first two args.
let result = await detailTx(process.argv[arg])
console.log("Fetched transaction");
console.log(result.transactions[0]);
console.log("BlockHeader:");
console.log(result[`block${result.transactions[0].blockHeight}`]);
}
}
2019-12-08 21:22:24 +01:00
} catch (error) {
console.log("Failure: " + error);
}
process.exit();
});