Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public setLastBlock(block: Interfaces.IBlock): void {
// Only keep blocks which are below the new block height (i.e. rollback)
if (this.lastBlocks.last() && this.lastBlocks.last().data.height !== block.data.height - 1) {
assert(block.data.height - 1 <= this.lastBlocks.last().data.height);
this.lastBlocks = this.lastBlocks.filter(b => b.data.height < block.data.height);
}
this.lastBlocks = this.lastBlocks.set(block.data.height, block);
Managers.configManager.setHeight(block.data.height);
if (Managers.configManager.isNewMilestone()) {
app.resolvePlugin("event-emitter").emit("internal.milestone.changed");
}
Transactions.TransactionRegistry.updateStaticFees(block.data.height);
// Delete oldest block if size exceeds the maximum
if (this.lastBlocks.size > app.resolveOptions("state").storage.maxLastBlocks) {
this.lastBlocks = this.lastBlocks.delete(this.lastBlocks.first().data.height);
}
}
export const injectMilestone = (index: number, milestone: Record): void => {
(Managers.configManager as any).milestones.splice(
index,
0,
Object.assign(cloneDeep(Managers.configManager.getMilestone()), milestone),
);
};
public async run(): Promise {
const { flags } = this.makeOffline(BlockCommand);
const genesisBlock = Managers.configManager.get("genesisBlock");
const genesisWallets = genesisBlock.transactions.map(t => t.recipientId).filter(a => !!a);
let previousBlock = flags.previousBlock ? JSON.parse(flags.previousBlock) : genesisBlock;
const blocks: Interfaces.IBlockJson[] = [];
for (let i = 0; i < flags.number; i++) {
const milestone = Managers.configManager.getMilestone(previousBlock.height);
const delegate = new Delegate(flags.passphrase, Managers.configManager.get("network.pubKeyHash"));
const transactions = [];
for (let i = 0; i < flags.transactions; i++) {
transactions.push(
this.signer.makeTransfer({
...flags,
...{
beforeEach(() => {
Managers.configManager.getMilestone().aip11 = true
transaction = Transactions.BuilderFactory
.multiSignature()
.multiSignatureAsset({
min: 1,
publicKeys: [
Identities.PublicKey.fromPassphrase(passphrase)
]
})
.sign('passphrase')
.fee(1)
})
public async createTransaction() {
Managers.configManager.setConfig(Managers.NetworkManager.findByName("testnet"));
const transaction = TransactionFactory.transfer("AZFEPTWnn2Sn8wDZgCRF8ohwKkrmk2AZi1", 100000000, "test")
.withPassphrase("clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire")
.createOne()
await httpie.post("http://127.0.0.1:4003/api/transactions", {
body: {
transactions: [transaction],
},
headers: { "Content-Type": "application/json" },
});
return transaction;
}
}
public canEnterTransactionPool(
data: Interfaces.ITransactionData,
pool: TransactionPool.IConnection,
processor: TransactionPool.IProcessor,
): boolean {
if (!isRecipientOnActiveNetwork(data)) {
processor.pushError(
data,
"ERR_INVALID_RECIPIENT",
`Recipient ${data.recipientId} is not on the same network: ${Managers.configManager.get(
"network.pubKeyHash",
)}`,
);
return false;
}
return true;
}
public async configurationCrypto() {
try {
return {
data: Managers.configManager.getPreset(this.config.get("network").name),
};
} catch (error) {
return Boom.badImplementation(error);
}
}
public async forgeNewBlock(
delegate: Delegate,
round: P2P.ICurrentRound,
networkState: P2P.INetworkState,
): Promise {
Managers.configManager.setHeight(networkState.nodeHeight);
const transactions: Interfaces.ITransactionData[] = await this.getTransactionsForForging();
const block: Interfaces.IBlock = delegate.forge(transactions, {
previousBlock: {
id: networkState.lastBlockId,
idHex: Managers.configManager.getMilestone().block.idFullSha256
? networkState.lastBlockId
: Blocks.Block.toBytesHex(networkState.lastBlockId),
height: networkState.nodeHeight,
},
timestamp: round.timestamp,
reward: round.reward,
});
const minimumMs: number = 2000;
export function isRecipientOnActiveNetwork(transaction: Interfaces.ITransactionData): boolean {
const recipientPrefix = bs58check.decode(transaction.recipientId).readUInt8(0);
if (recipientPrefix === Managers.configManager.get("network.pubKeyHash")) {
return true;
}
app.resolvePlugin("logger").error(
`Recipient ${transaction.recipientId} is not on the same network: ${Managers.configManager.get(
"network.pubKeyHash",
)}`,
);
return false;
}
private configureCrypto(value: any): void {
Managers.configManager.setConfig(value);
this.config.network = Managers.configManager.get("network");
this.config.exceptions = Managers.configManager.get("exceptions");
this.config.milestones = Managers.configManager.get("milestones");
this.config.genesisBlock = Managers.configManager.get("genesisBlock");
}