This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { app } from "@arkecosystem/core-container"; | |
const blockchain = app.resolvePlugin("blockchain"); | |
async function callBlockchainMethods() { | |
// Check if the blockchain is fully synced | |
blockchain.isSynced(); | |
// Get the last block we've received | |
blockchain.getLastBlock(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { app } from "@arkecosystem/core-container"; | |
const database = app.resolvePlugin("database"); | |
async function callDatabaseMethods() { | |
// Get a block from the database by its id | |
await database.getBlock("some block id"); | |
// Skip the first 100 blocks, grab the next 100 | |
await database.getBlocks(100, 100); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { app } from "@arkecosystem/core-container"; | |
import { EventEmitter, Logger } from "@arkecosystem/core-interfaces"; | |
const logger = app.resolvePlugin<Logger.ILogger>("logger"); | |
const emitter = app.resolvePlugin<EventEmitter.EventEmitter>("event-emitter"); | |
emitter.on("forger.missing", delegate => { | |
// This will be a wallet object that contains information like the address, username, public key, votes, etc. | |
logger.warn(`${delegate.username} just missed a block.`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createServer, mountServer } from "@arkecosystem/core-http-utils"; | |
export async function startServer(config) { | |
const server = await createServer({ | |
host: config.host, | |
port: config.port | |
}); | |
server.route({ | |
method: "GET", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
dynamicFeeManager, | |
transactionBuilder, | |
formatArktoshi, | |
} = require('@arkecosystem/crypto') | |
const transaction = transactionBuilder | |
.transfer() | |
.recipientId('D9YiyRYMBS2ofzqkufjrkB9nHofWgJLM7f') | |
.sign('secret passphrase') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Determine if transaction matches the accepted fee by delegate or max fee set by sender | |
* @param {Transaction} Transaction - transaction to check | |
* @return {Boolean} matches T/F | |
*/ | |
module.exports = (transaction) => { | |
const transactionFee = transaction.fee.toNumber() | |
const staticFee = feeManager.getForTransaction(transaction) | |
const blockchain = container.resolvePlugin('blockchain') | |
const feeConstants = config.getConstants(blockchain.getLastBlock().data.height).fees |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Found in networks config folder in crypto/lib/networks | |
"dynamicOffsets": { | |
"transfer": 100, | |
"secondSignature": 250, | |
"delegateRegistration": 500, | |
"vote": 100, | |
"multiSignature": 500, | |
"ipfs": 250, | |
"timelockTransfer": 500, | |
"multiPayment": 500, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Calculates delegate fee for processing and forging if transaction | |
* @param {Number} Fee price per byte in ARKTOSHI as set by forger/delegate in delegate.json setting feeMultiplier | |
* @param {Transaction} Transaction for which we calculate dynamic fee | |
* @returns {Number} Calculated dynamic fee in ARKTOSHI | |
*/ | |
calculateFee (feeMultiplier, transaction) { | |
if (feeMultiplier <= 0) { | |
feeMultiplier = 1 | |
} | |
// We get the transactions offset for a transaction type and |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// serialised transaction Transfer | |
// serialised.length = 160 | |
{"serialized": | |
{ | |
"type":"Buffer", | |
"data":[255,1,30,0,22,116,215,2,3,215,223,228,78,119,16,57,51,79,71,18,251,149,173,53,82,84,246,116,200,245,210,134,80,49,153,21,123,123,247,195,87,14,1,0,0,0,0,0,0,6,84,73,68,58,32,48,0,194,235,11,0,0,0,0,15,0,0,0,30,72,161,107,90,67,151,232,118,184,105,194,229,52,233,123,39,157,230,102,177,48,68,2,32,69,177,255,192,154,14,176,62,80,182,75,185,130,144,48,143,68,177,152,153,1,75,93,101,109,175,41,10,149,220,23,79,2,32,15,59,8,76,121,202,240,45,147,56,172,137,149,29,183,136,156,137,156,69,81,149,205,254,98,22,126,19,61,71,244,227] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dynamic transaction payload | |
{ | |
"verified":true, | |
"id":"afaa18bfc29762b7b5172fa1f71ea7471c0d9e6dcf2992638865ecb4b3d1f26b", | |
"version":1, | |
"timestamp":47674390, | |
"senderPublicKey":"03d7dfe44e771039334f4712fb95ad355254f674c8f5d286503199157b7bf7c357", | |
"recipientId":"DBm8ZgZvaDhgba9jyFNVwDGD8ysbN3w8Tv", | |
"type":0, | |
"vendorFieldHex":"5449443a2030", |