Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const RegisterPacketTransaction = require('../transactions/register-packet');
const transactions = require('@liskhq/lisk-transactions');
const { EPOCH_TIME } = require('@liskhq/lisk-constants');
const accounts = require('./accounts.json');
const getTimestamp = () => {
// check config file or curl localhost:4000/api/node/constants to verify your epoc time (OK when using /transport/node/index.js)
const millisSinceEpoc = Date.now() - Date.parse(EPOCH_TIME);
const inSeconds = ((millisSinceEpoc) / 1000).toFixed(0);
return parseInt(inSeconds);
};
let tx = new RegisterPacketTransaction({
asset: {
packetId: accounts.packet.address,
postage: `${transactions.utils.convertLSKToBeddows('5')}`,
security: `${transactions.utils.convertLSKToBeddows('100')}`,
minTrust: 0,
},
fee: '0',
recipientId: accounts.recipient.address,
timestamp: getTimestamp()
});
tx.sign(accounts.sender.passphrase); // 16313739661670634666L
console.log(tx.stringify());
process.exit(0);
const packetCredentials = { address: '5420762878027534930L',
passphrase:
'range axis twin quote rate rifle cute math quantum talk must round',
publicKey:
'1529b602ea69497ff5e38c3d1db5e90f9dfb6ee2f0e83534c89f18579a24653b',
privateKey:
'f3058da026f8b1a93643dc6864fc5ef7830b7614dd09292bc5f2ca3d4b115f9e1529b602ea69497ff5e38c3d1db5e90f9dfb6ee2f0e83534c89f18579a24653b'
}; // insert here the packetCredentials-object created in create_and_initialize_packet_account.js
let tx = new RegisterPacketTransaction({
asset: {
packetId: packetCredentials.address,
senderLocation: "def alley, 456 someCity",
receipientLocation: "abc street, 123 someCity",
porto: `${transactions.utils.convertLSKToBeddows('5')}`,
security: `${transactions.utils.convertLSKToBeddows('100')}`,
minTrust: 25,
estTravelTime: "18000", // 18,000 seconds = 5 hrs
},
fee: "0",
recipientId: "10881167371402274308L",
timestamp: getTimestamp()
});
tx.sign('wagon stock borrow episode laundry kitten salute link globe zero feed marble');
console.log(tx.stringify());
process.exit(0);
const packetCredentials = { address: '5420762878027534930L',
passphrase:
'range axis twin quote rate rifle cute math quantum talk must round',
publicKey:
'1529b602ea69497ff5e38c3d1db5e90f9dfb6ee2f0e83534c89f18579a24653b',
privateKey:
'f3058da026f8b1a93643dc6864fc5ef7830b7614dd09292bc5f2ca3d4b115f9e1529b602ea69497ff5e38c3d1db5e90f9dfb6ee2f0e83534c89f18579a24653b'
}; // insert here the packetCredentials-object created in create_and_initialize_packet_account.js
let tx = new RegisterPacketTransaction({
asset: {
packetId: packetCredentials.address,
senderLocation: "def alley, 456 someCity",
receipientLocation: "abc street, 123 someCity",
porto: `${transactions.utils.convertLSKToBeddows('5')}`,
security: `${transactions.utils.convertLSKToBeddows('100')}`,
minTrust: 25,
estTravelTime: "18000", // 18,000 seconds = 5 hrs
},
fee: "0",
recipientId: "10881167371402274308L",
timestamp: getTimestamp()
});
tx.sign('wagon stock borrow episode laundry kitten salute link globe zero feed marble');
console.log(tx.stringify());
process.exit(0);
const transactions = require('@liskhq/lisk-transactions');
const cryptography = require('@liskhq/lisk-cryptography');
const { APIClient } = require('@liskhq/lisk-api-client');
const { Mnemonic } = require('@liskhq/lisk-passphrase');
const accounts = require('./accounts.json');
const api = new APIClient(['http://localhost:4000']);
let tx = new transactions.TransferTransaction({
amount: `${transactions.utils.convertLSKToBeddows('2000')}`,
recipientId: accounts.carrier.address,
});
tx.sign('wagon stock borrow episode laundry kitten salute link globe zero feed marble'); // Genesis account with address: 16313739661670634666L
api.transactions.broadcast(tx.toJSON()).then(res => {
console.log("++++++++++++++++ API Response +++++++++++++++++");
console.log(res.data);
console.log("++++++++++++++++ Transaction Payload +++++++++++++++++");
console.log(tx.stringify());
console.log("++++++++++++++++ End Script +++++++++++++++++");
}).catch(err => {
console.log(JSON.stringify(err.errors, null, 2));
});
const recipientId = '16313739661670634666L'; // Address of user that send the invoice to me
const passphrase = 'robust swift grocery peasant forget share enable convince deputy road keep cheap'; // Passphrase of person who wants to fulfill invoice (associated address: 8273455169423958419L)
const paymentJSON = createPaymentJSON({
recipientId,
amount: '11', // Requested amount: 10.5 (want to give bit extra)
invoiceId: '6068542855269194380', // Look up the ID of the invoice you have created (use: http://localhost:4000/api/transactions?type=13)
}, passphrase);
console.log('------------- Payment Tx - Type 14 -----------------');
console.log(paymentJSON);
console.log('------------- Fund Account Tx - Type 0 -----------------');
// ------- Payment JSON to fund account ------- //
const transaction = transactions.utils.signRawTransaction({
transaction: {
type: 0,
amount: '10000000000', // 100 LSK
recipientId: '8273455169423958419L',
fee: '10000000',
asset: {},
},
passphrase: 'wagon stock borrow episode laundry kitten salute link globe zero feed marble',
});
console.log(JSON.stringify(transaction));
app.post('/faucet', function (req, res) {
const address = req.body.address;
const amount = req.body.amount;
const fundTransaction = new transactions.TransferTransaction({
amount: transactions.utils.convertLSKToBeddows(amount),
recipientId: address,
});
fundTransaction.sign(accounts.sender.passphrase); // Genesis account
api.transactions.broadcast(fundTransaction.toJSON()).then(response => {
res.app.locals.payload = {
res: response.data,
tx: fundTransaction.toJSON(),
};
console.log("++++++++++++++++ API Response +++++++++++++++++");
console.log(response.data);
console.log("++++++++++++++++ Transaction Payload +++++++++++++++++");
console.log(fundTransaction.stringify());
console.log("++++++++++++++++ End Script +++++++++++++++++");
res.redirect('/payload');
}).catch(err => {
let chainModuleAlias = chainOptions.moduleAlias;
let txn = {
type: 0,
amount: transactionData.amount.toString(),
recipientId: transactionData.recipientId,
fee: liskTransactions.constants.TRANSFER_FEE.toString(),
asset: {},
timestamp: transactionData.timestamp,
senderPublicKey: liskCryptography.getAddressAndPublicKeyFromPassphrase(chainOptions.sharedPassphrase).publicKey
};
if (message != null) {
txn.asset.data = message;
}
let preparedTxn = liskTransactions.utils.prepareTransaction(txn, chainOptions.sharedPassphrase);
let {signature, signSignature, ...transactionToHash} = preparedTxn;
let txnHash = liskCryptography.hash(liskTransactions.utils.getTransactionBytes(transactionToHash));
let multisigTxnSignature = liskCryptography.signData(txnHash, chainOptions.passphrase);
let publicKey = liskCryptography.getAddressAndPublicKeyFromPassphrase(chainOptions.passphrase).publicKey;
preparedTxn.signatures = [multisigTxnSignature];
let processedSignatureSet = new Set();
processedSignatureSet.add(multisigTxnSignature);
// If the pendingTransfers map already has a transaction with the specified id, delete the existing entry so
// that when it is re-inserted, it will be added at the end of the queue.
// To perform expiry using an iterator, it's essential that the insertion order is maintained.
if (this.pendingTransfers.has(preparedTxn.id)) {
this.pendingTransfers.delete(preparedTxn.id);
}
this.pendingTransfers.set(preparedTxn.id, {
transaction: preparedTxn,
targetChain,
app.post('/post-register-packet', function (req, res) {
const packetId = req.body.packetid;
const postage = req.body.postage;
const security = req.body.security;
const minTrust = +req.body.mintrust;
const recipientId = req.body.recipient;
const passphrase = req.body.passphrase;
const registerPackageTransaction = new RegisterPacketTransaction({
asset: {
security: transactions.utils.convertLSKToBeddows(security),
minTrust,
postage: transactions.utils.convertLSKToBeddows(postage),
packetId,
},
recipientId,
timestamp: dateToLiskEpochTimestamp(new Date()),
});
registerPackageTransaction.sign(passphrase);
api.transactions.broadcast(registerPackageTransaction.toJSON()).then(response => {
res.app.locals.payload = {
res: response.data,
tx: registerPackageTransaction.toJSON(),
};
console.log("++++++++++++++++ API Response +++++++++++++++++");
const createPaymentJSON = ({
recipientId, amount, invoiceId,
}, passphrase) => {
const paymentTx = new PaymentTransaction({
asset: {
data: invoiceId,
},
amount: transactions.utils.convertLSKToBeddows(amount),
recipientId,
timestamp: dateToLiskEpochTimestamp(new Date()),
fee: PaymentTransaction.FEE,
});
paymentTx.sign(passphrase);
return paymentTx.toJSON();
};
export const sendPayment = ({
recipientId, amount, invoiceID,
}, passphrase) => {
const paymentTx = new PaymentTransaction({
asset: {
data: invoiceID,
},
amount: transactions.utils.convertLSKToBeddows(amount),
recipientId,
timestamp: dateToLiskEpochTimestamp(new Date()),
});
paymentTx.sign(passphrase);
return getApiClient().transactions.broadcast(paymentTx.toJSON());
};