Issue
This Content is from Stack Overflow. Question asked by theredtexan
My Meteor project has the DASH SDK installed as an NPM package. The goal is to call the “funds” function in methods.js from fixtures.js whenever a transaction is received. The address and amount are console logging from fixtures.js correctly, but I am receiving an error regarding bindEnvironment due to fibers. It does not console log from methods.js.
fixtures.js
import { Meteor } from 'meteor/meteor';
Meteor.startup(() => {
const Dash = require("dash");
const mnemonic = 'fake fake fake fake fake fake fake fake fake fake fake fake';
const client = new Dash.Client({ network: "testnet", wallet: { mnemonic } });
async function listenUnconfirmedTransaction() {
const account = await client.wallet.getAccount();
console.log(account);
account.on('FETCHED/CONFIRMED_TRANSACTION', (data) => {
console.dir(data);
var amount = data.payload.transaction.outputs[0]._satoshis;
var address = data.payload.transaction.outputs[0].script.toAddress("testnet").toString();
console.log("Amount: " + amount + ", Address: " + address);
if (address) {
Meteor.call('funds', address, amount, (error) => { if (error) { console.log(error); }});
};
});
};
listenUnconfirmedTransaction();
}
methods.js
import { Meteor } from 'meteor/meteor';
Meteor.methods({
'funds': function (address, received) {
console.log("Address: " + address + ", Received: " + received);
}
});
I have looked into the bindEnvironment and wrapAsync for Meteor, but I am not understanding how I can use them in this situation. Please advise
Solution
Ok, if you run Meteor up to version 2.7.3 you need to wrap that(details further down).
2.8 is now in preparation and it makes the move from Fibers (still compatible with NodeJS 14 but not with Node 16) to async. I think async now works server side, just keep an eye on this: https://forums.meteor.com/t/eta-of-2-8-release/58720
Wrapping for Fibers. This is basically running async code as if it was synchronous.
const bound = Meteor.bindEnvironment(callback => callback())
bound(() => {
...your code goes here.
})
This Question was asked in StackOverflow by theredtexan and Answered by Paul Paulincai It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.