Skip to content

Instantly share code, notes, and snippets.

Michiel Mulders michielmulders

Block or report user

Report or block michielmulders

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@michielmulders
michielmulders / index.js
Created Jun 27, 2019
Lisk Core Startup Registration
View index.js
const { Application, genesisBlockDevnet, configDevnet } = require('lisk-sdk');
const { InvoiceTransaction, PaymentTransaction } = require('../transactions');
const app = new Application(genesisBlockDevnet, configDevnet);
app.registerTransaction(13, InvoiceTransaction);
app.registerTransaction(14, PaymentTransaction);
app
.run()
@michielmulders
michielmulders / invoice-tx.js
Last active Jun 27, 2019
Payment Transaction Undo Asset
View invoice-tx.js
undoAsset(store) {
super.undoAsset(store);
return [];
}
@michielmulders
michielmulders / invoice-tx.js
Created Jun 27, 2019
Payment Transaction Apply Asset
View invoice-tx.js
applyAsset(store) {
super.applyAsset(store);
const errors = [];
const transaction = store.transaction.find(
transaction => transaction.id === this.asset.data
); // Find related invoice in transactions for invoiceID
if (transaction) {
if (this.amount.lt(transaction.asset.requestedAmount)) {
errors.push(
@michielmulders
michielmulders / invoice-tx.js
Created Jun 27, 2019
Payment Transaction Prepare
View invoice-tx.js
async prepare(store) {
super.prepare(store)
await store.transaction.cache([
{
id: this.asset.data,
},
]);
}
@michielmulders
michielmulders / invoice-tx.js
Created Jun 27, 2019
Payment Transaction extension
View invoice-tx.js
class PaymentTransaction extends TransferTransaction {
static get TYPE () {
return 14;
}
...
}
@michielmulders
michielmulders / invoice-tx.js
Created Jun 27, 2019
Invoice Transaction Undo Asset
View invoice-tx.js
undoAsset(store) {
const sender = store.account.get(this.senderId);
// Using JSON.stringify/parse to recursively clones the object
const originalSender = JSON.parse(JSON.stringify(sender));
// Rollback invoice count and IDs
originalSender.asset.invoiceCount = originalSender.asset.invoiceCount === 1 ? undefined : originalSender.asset.invoiceCount--;
originalSender.asset.invoicesSent = originalSender.asset.invoicesSent.splice(
originalSender.asset.invoicesSent.indexOf(this.id),
@michielmulders
michielmulders / invoice-tx.js
Created Jun 27, 2019
Invoice Transaction Apply Asset
View invoice-tx.js
applyAsset(store) {
const sender = store.account.get(this.senderId);
// Using JSON.stringify/parse to recursively clones the object
const updatedSender = JSON.parse(JSON.stringify(sender));
// Save invoice count and IDs
updatedSender.asset.invoiceCount = updatedSender.asset.invoiceCount === undefined ? 1 : updatedSender.asset.invoiceCount++;
updatedSender.asset.invoicesSent = updatedSender.asset.invoicesSent === undefined ? [this.id] : [...updatedSender.asset.invoicesSent, this.id];
store.account.set(sender.address, updatedSender);
@michielmulders
michielmulders / invoice-tx.js
Created Jun 27, 2019
InvoiceTransaction validate asset
View invoice-tx.js
validateAsset() {
const errors = [];
if (!this.asset.client || typeof this.asset.client !== 'string') {
errors.push(
new TransactionError(
'Invalid "asset.client" defined on transaction',
this.id,
'.asset.client',
this.asset.client,
'A string value',
@michielmulders
michielmulders / invoice-tx.js
Created Jun 27, 2019
InvoiceTransaction prepare function
View invoice-tx.js
async prepare(store) {
await store.account.cache([
{
address: this.senderId,
},
]);
}
@michielmulders
michielmulders / invoice-tx.js
Created Jun 27, 2019
InvoiceTransaction class extension and type
View invoice-tx.js
class InvoiceTransaction extends BaseTransaction {
static get TYPE () {
return 13;
}
...
}
You can’t perform that action at this time.