Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Enums } from "@arkecosystem/crypto";
const { MultiPayment } = Enums.TransactionTypes;
export {};
declare global {
namespace jest {
// tslint:disable-next-line:interface-name
interface Matchers {
toBeMultiPaymentType(): R;
}
}
}
expect.extend({
toBeMultiPaymentType: received => {
return {
message: () => "Expected value to be a valid MultiPayment transaction.",
private calculateTransactionExpiration(
transaction: Interfaces.ITransaction,
context: {
blockTime: number,
currentHeight: number,
now: number,
}
): number {
if (transaction.type === Enums.TransactionTypes.TimelockTransfer) {
// tslint:disable-next-line:no-null-keyword
return null;
}
// We ignore data.expiration in v1 transactions because it is not signed
// by the transaction creator.
if (transaction.data.version >= 2 && transaction.data.expiration > 0) {
return transaction.data.expiration;
}
// Since the user did not specify an expiration we set one by calculating
// approximately the height of the chain as of the time the transaction was
// created and adding maxTransactionAge to that.
// Both now and transaction.data.timestamp use [number of seconds since the genesis block].
const createdSecondsAgo: number = context.now - transaction.data.timestamp;
import { Enums } from "@arkecosystem/crypto";
const { SecondSignature } = Enums.TransactionTypes;
export {};
declare global {
namespace jest {
// tslint:disable-next-line:interface-name
interface Matchers {
toBeSecondSignatureType(): R;
}
}
}
expect.extend({
toBeSecondSignatureType: received => {
return {
message: () => "Expected value to be a valid SecondSignature transaction.",
import { Enums } from "@arkecosystem/crypto";
const { MultiSignature } = Enums.TransactionTypes;
export {};
declare global {
namespace jest {
// tslint:disable-next-line:interface-name
interface Matchers {
toBeMultiSignatureType(): R;
}
}
}
expect.extend({
toBeMultiSignatureType: received => {
return {
message: () => "Expected value to be a valid MultiSignature transaction.",
import { Enums } from "@arkecosystem/crypto";
const { Vote } = Enums.TransactionTypes;
export {};
declare global {
namespace jest {
// tslint:disable-next-line:interface-name
interface Matchers {
toBeVoteType(): R;
}
}
}
expect.extend({
toBeVoteType: received => {
return {
message: () => "Expected value to be a valid VOTE transaction.",
import { Enums } from "@arkecosystem/crypto";
const { Transfer } = Enums.TransactionTypes;
export {};
declare global {
namespace jest {
// tslint:disable-next-line:interface-name
interface Matchers {
toBeTransferType(): R;
}
}
}
expect.extend({
toBeTransferType: received => {
return {
message: () => "Expected value to be a valid Transfer transaction.",
if (transaction.type === Enums.TransactionTypes.SecondSignature) {
audit.push({ "Second public key": this.secondPublicKey });
}
if (transaction.type === Enums.TransactionTypes.DelegateRegistration) {
const username = transaction.asset.delegate.username;
audit.push({ "Current username": this.username });
audit.push({ "New username": username });
}
if (transaction.type === Enums.TransactionTypes.Vote) {
audit.push({ "Current vote": this.vote });
audit.push({ "New vote": transaction.asset.votes[0] });
}
if (transaction.type === Enums.TransactionTypes.MultiSignature) {
const keysgroup = transaction.asset.multisignature.keysgroup;
audit.push({ "Multisignature not yet registered": !this.multisignature });
audit.push({
"Multisignature enough keys": keysgroup.length >= transaction.asset.multiSignature.min,
});
audit.push({
"Multisignature all keys signed": keysgroup.length === transaction.signatures.length,
});
audit.push({
"Multisignature verification": this.verifySignatures(transaction, transaction.asset.multiSignature),
});
}
if (transaction.type === Enums.TransactionTypes.Ipfs) {
audit.push({ IPFS: true });
}
export const calculateMinimumFee = (satoshiPerByte: number, transaction: Interfaces.ITransaction): Utils.BigNumber => {
if (satoshiPerByte <= 0) {
satoshiPerByte = 1;
}
const key: string = camelCase(
transaction.type in Enums.TransactionTypes
? Enums.TransactionTypes[transaction.type]
: transaction.constructor.name.replace("Transaction", ""),
);
const addonBytes: number = app.resolveOptions("transaction-pool").dynamicFees.addonBytes[key];
const transactionSizeInBytes: number = transaction.serialized.length / 2;
return Utils.BigNumber.make(addonBytes + transactionSizeInBytes).times(satoshiPerByte);
};
private async processGenesisBlock(): Promise {
const genesisBlock: Interfaces.IBlock = Blocks.BlockFactory.fromJson(
Managers.configManager.get("genesisBlock"),
);
const { transactions }: Interfaces.IBlock = genesisBlock;
for (const transaction of transactions) {
if (transaction.type === Enums.TransactionTypes.Transfer) {
const recipient: State.IWallet = this.walletManager.findByAddress(transaction.data.recipientId);
recipient.balance = new Utils.BigNumber(transaction.data.amount);
}
}
for (const transaction of transactions) {
const sender: State.IWallet = this.walletManager.findByPublicKey(transaction.data.senderPublicKey);
sender.balance = sender.balance.minus(transaction.data.amount).minus(transaction.data.fee);
if (transaction.type === Enums.TransactionTypes.DelegateRegistration) {
sender.username = transaction.data.asset.delegate.username;
this.walletManager.reindex(sender);
} else if (transaction.type === Enums.TransactionTypes.Vote) {
const vote = transaction.data.asset.votes[0];
sender.vote = vote.slice(1);
}
Managers.configManager.get("genesisBlock"),
);
const { transactions }: Interfaces.IBlock = genesisBlock;
for (const transaction of transactions) {
if (transaction.type === Enums.TransactionTypes.Transfer) {
const recipient: State.IWallet = this.walletManager.findByAddress(transaction.data.recipientId);
recipient.balance = new Utils.BigNumber(transaction.data.amount);
}
}
for (const transaction of transactions) {
const sender: State.IWallet = this.walletManager.findByPublicKey(transaction.data.senderPublicKey);
sender.balance = sender.balance.minus(transaction.data.amount).minus(transaction.data.fee);
if (transaction.type === Enums.TransactionTypes.DelegateRegistration) {
sender.username = transaction.data.asset.delegate.username;
this.walletManager.reindex(sender);
} else if (transaction.type === Enums.TransactionTypes.Vote) {
const vote = transaction.data.asset.votes[0];
sender.vote = vote.slice(1);
}
}
this.walletManager.buildVoteBalances();
this.state.setLastBlock(genesisBlock);
const roundInfo: Shared.IRoundInfo = roundCalculator.calculateRound(1);
const delegates: State.IDelegateWallet[] = this.walletManager.loadActiveDelegateList(roundInfo);
(this.localDatabase as any).forgingDelegates = await this.localDatabase.getActiveDelegates(