Skip to content

Instantly share code, notes, and snippets.

const {
BaseTransaction,
TransactionError,
utils
} = require('@liskhq/lisk-transactions');
class MultiRecipient extends BaseTransaction {
static get TYPE() {
return 20;
const {
BaseTransaction,
TransactionError,
utils
} = require('@liskhq/lisk-transactions');
class MultiRecipient extends BaseTransaction {
static get TYPE() {
return 20;
@corbifex
corbifex / BaseProposal.ts
Last active July 22, 2020 10:46
Base Proposal transaction LCU Dao
const {proposal, errors} = await this.applyProposalAsset(store);
errors.map(err => {
errs.push(err);
});
proposal.publicKey = this.getProposalPublicKey();
proposal.asset = {
...proposal.asset,
options: proposal.asset.options || {},
@corbifex
corbifex / AddMemberProposal.ts
Created July 22, 2020 10:48
Add Member proposal custom apply phase
public async applyProposalAsset(store: StateStore): Promise<ApplyProposal> {
const errors: TransactionError[] = [];
const proposal = await store.account.getOrDefault(this.getProposalAddress()) as ProposalAccount;
const addressBook = await store.account.getOrDefault(getAddressFromPublicKey(this.asset.addressBook)) as AddressBookAccount;
const proposedMember = await store.account.getOrDefault(getAddressFromPublicKey(this.asset.options.member)) as Account;
if (!this.asset.options.member) {
errors.push(
new TransactionError(
'`.asset.options.member` should contain the proposal.',
@corbifex
corbifex / request.ts
Created August 2, 2020 11:56
Get available payment units
// slotTypes = [minutes, hours, days, months] in seconds
export const getPastSlots = (
start,
now,
type,
length,
unit
) => {
const slot = slotTypes[type] * length;
return Math.floor((now - start) / slot) - unit;
@corbifex
corbifex / Fund.js
Created August 2, 2020 11:58
Fund transaction on frontend with dynamic fees and signing
const tx = new FundContractTransaction({
nonce: nonce.toString(),
senderPublicKey: publicKey,
asset: {
...data
}
});
tx.fee = (tx.minFee + BigInt(65000)).toString();
tx.sign(config.networkIdentifier, passphrase);
@corbifex
corbifex / voteTransaction.ts
Created August 31, 2020 09:22
Calculate vote stake
public calculateVoteStake(investments: Array<Investment>): bigint {
let voteStake = BigInt(0);
investments.map(investment => {
if (investment.address === this.senderId) {
voteStake += BigInt(investment.amount);
}
});
return voteStake;
}
@corbifex
corbifex / voteTransaction.ts
Created August 31, 2020 09:25
vote weight no calculation
const voteWeightNo = votes
.filter(v => v.vote === 0)
.map(v => v.stake)
.reduce((accumulator, currentValue) => accumulator + currentValue);
@corbifex
corbifex / claimTransaction.ts
Created August 31, 2020 09:29
Verify if a claim for a period is allowed
public allowedToClaim(currentTime: number, startTime: number, payments: Array<Payment>): boolean {
const currentPeriod = this.calculateCurrentPeriod(currentTime, startTime);
if (payments.find(p =>
p.type === 0 &&
p.period === this.asset.period)) {
return false;
}
return currentPeriod >= this.asset.period && (this.asset.period * PERIOD) + startTime < currentTime;
}
@corbifex
corbifex / dynamicFees.ts
Last active August 31, 2020 09:56
Get the minimal fee for a transactions
const tx = {
senderPublicKey: wallet.account.publicKey,
networkIdentifier,
nonce: wallet.account.nonce.toString(),
passphrase: passphrase,
asset: {
fundraiser: fundraiser,
amount: convertLSKToBeddows(amount.toString()),
message
}