Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
textDecoder: new TextDecoder
});
const trx_id_arr = hexToUint8Array(trx_id);
sb_action.pushName(action.act.account);
sb_action.pushName(action.act.name);
sb_action.pushBytes(action.act.data);
if (this.amq) {
// this.logger.info(`Queueing action for ${action.act.account}::${action.act.name}`);
const block_buffer = new Int64(block_num).toBuffer();
const timestamp_buffer = this.int32ToBuffer(block_timestamp.getTime() / 1000);
const trx_id_buffer = Buffer.from(trx_id_arr);
const recv_buffer = new Int64(action.receipt[1].recv_sequence).toBuffer();
const global_buffer = new Int64(action.receipt[1].global_sequence).toBuffer();
const action_buffer = Buffer.from(sb_action.array);
// this.logger.info(`Publishing action`)
this.amq.send('action', Buffer.concat([block_buffer, timestamp_buffer, trx_id_buffer, recv_buffer, global_buffer, action_buffer]))
} else {
console.error(`No queue when processing action for ${action.act.account}::${action.act.name} in ${trx_id}`, {action});
}
}
if (action.inline_traces && action.inline_traces.length) {
for (let itc of action.inline_traces) {
// this.logger.info("inline trace\n", itc);
if (itc[0] === 'action_trace_v0') {
this.queueAction(block_num, itc[1], trx_id, block_timestamp);
}
}
async processContractRow(job) {
const sb = new Serialize.SerialBuffer({
textEncoder: new TextEncoder,
textDecoder: new TextDecoder,
array: new Uint8Array(job.content)
});
const block_num = new Int64(sb.getUint8Array(8)).toString();
const present = sb.get();
const block_timestamp_arr = sb.getUint8Array(4);
// const block_timestamp_int = sb.getUint32();
let buffer = Buffer.from(block_timestamp_arr);
var block_timestamp_int = buffer.readUInt32BE(0);
const block_timestamp = new Date(block_timestamp_int * 1000);
sb.get(); // version
const code = sb.getName();
const scope = sb.getName();
const table = sb.getName();
const primary_key = new Int64(sb.getUint8Array(8)).toString();
const payer = sb.getName();
const data_raw = sb.getBytes();
try {
const table_type = await this.delta_handler.getTableType(code, table);
return new Promise((resolve, reject) => {
const ts = Math.floor(block_timestamp.getTime() / 1000);
// this.logger.info('ts', ts);
const timestamp_buffer = this.int32ToBuffer(ts);
const block_buffer = new Int64(block_num).toBuffer();
const present_buffer = Buffer.from([row.present]);
// this.logger.info(`Publishing ${name}`)
this.amq.send(name, Buffer.concat([block_buffer, present_buffer, timestamp_buffer, Buffer.from(row.data)]))
.then(resolve)
.catch(reject)
})
async processBlockRange(job) {
this.job = job;
//await this.amq.ack(job)
const start_buffer = job.content.slice(0, 8);
const end_buffer = job.content.slice(8);
const start_block = new Int64BE(start_buffer).toString();
const end_block = new Int64BE(end_buffer).toString();
this.logger.info(`processBlockRange pid : ${process.pid} ${start_block} to ${end_block}`);
const dac_directory = new DacDirectory({config: this.config, db:this.db});
await dac_directory.reload();
const action_handler = new ActionHandler({queue: this.amq, config: this.config, dac_directory, logger:this.logger});
const block_handler = new TraceHandler({queue: this.amq, action_handler, config: this.config, logger:this.logger});
const delta_handler = new DeltaHandler({queue: this.amq, config: this.config, dac_directory, logger:this.logger});
this.br = new StateReceiver({startBlock: start_block, endBlock: end_block, mode: 1, config: this.config});
this.br.registerDeltaHandler(delta_handler);
this.br.registerTraceHandler(block_handler);
this.br.registerDoneHandler(() => {
// this.logger.info(`StateReceiver completed`, job)
data.forEach(function(row) {
r = {}
r.rowkey = row.row.toString('utf8')
for (var key in row.columns) {
if (includeFamilies) {
r[key] = row.columns[key].value.toString('utf8')
} else {
parts = key.split(':')
if (parts[0] === 'inc') {
r[parts[1]] = int64BE(row.columns[key].value).toString()
} else {
r[parts[1]] = row.columns[key].value.toString('utf8')
}
}
}
rows.push(r)
})
public readInt64(bigEndian: boolean = false): Int64LE | Int64BE {
if (this.canReadBytes(8) === false) {
throw new Error('Data buffer is too small')
}
const res: Int64LE | Int64BE = bigEndian ?
new Int64BE(this.packetData, this.curOffset) :
new Int64LE(this.packetData, this.curOffset)
this.curOffset += 8
return res
}
encryptedPin: function (pin, pinToken, sessionId, privateKey, iterator) {
if (!pinToken) {
pinToken = this.api.account.pinToken();
}
if (!sessionId) {
sessionId = this.api.account.sessionId();
}
if (!privateKey) {
privateKey = this.api.account.privateKey();
}
if (iterator == undefined || iterator === "") {
iterator = Date.now() * 1000000;
}
const blockSize = 16;
let Uint64LE = LittleEndian.Int64BE;
pinToken = new Buffer(pinToken, 'base64');
privateKey = forge.pki.privateKeyFromPem(privateKey);
let pinKey = privateKey.decrypt(pinToken, 'RSA-OAEP', {
md: forge.md.sha256.create(),
label: sessionId
});
let time = new Uint64LE(moment.utc().unix());
time = [...time.toBuffer()].reverse();
iterator = new Uint64LE(iterator);
iterator = [...iterator.toBuffer()].reverse();
pin = Buffer.from(pin, 'utf8');
let buf = Buffer.concat([pin, Buffer.from(time), Buffer.from(iterator)]);
let padding = blockSize - buf.length % blockSize;
let paddingArray = [];
for (let i=0; i
Reader.prototype.getInt64 = function(){
var i = Int64(this.buffer, this.pos).toNumber();
this.pos += 8;
return i;
};
} else if (this.database !== EMPTY) {
buffer.writeIntBE(Number(this.database), 0, 4);
}
if (this.documentCollection !== EMPTY) {
buffer.writeIntBE(Number(this.documentCollection), 4, 4);
} else if (this.user !== EMPTY) {
buffer.writeIntBE(Number(this.user), 4, 4);
}
let big: Int64BE;
if (this.storedProcedure !== EMPTY) {
big = new Int64BE(this.storedProcedure);
big.toBuffer().copy(buffer, 8, 0, 8);
} else if (this.trigger !== EMPTY) {
big = new Int64BE(this.trigger);
big.toBuffer().copy(buffer, 8, 0, 8);
} else if (this.userDefinedFunction !== EMPTY) {
big = new Int64BE(this.userDefinedFunction);
big.toBuffer().copy(buffer, 8, 0, 8);
} else if (this.conflict !== EMPTY) {
big = new Int64BE(this.conflict);
big.toBuffer().copy(buffer, 8, 0, 8);
} else if (this.document !== EMPTY) {
big = new Int64BE(this.document);
big.toBuffer().copy(buffer, 8, 0, 8);
} else if (this.permission !== EMPTY) {
big = new Int64BE(this.permission);
big.toBuffer().copy(buffer, 8, 0, 8);
} else if (this.partitionKeyRange !== EMPTY) {
big = new Int64BE(this.partitionKeyRange);
big.toBuffer().copy(buffer, 8, 0, 8);
if (this.offer !== EMPTY) {
buffer.writeIntLE(Number(this.offer), 0, this.offerIdLength);
} else if (this.database !== EMPTY) {
buffer.writeIntBE(Number(this.database), 0, 4);
}
if (this.documentCollection !== EMPTY) {
buffer.writeIntBE(Number(this.documentCollection), 4, 4);
} else if (this.user !== EMPTY) {
buffer.writeIntBE(Number(this.user), 4, 4);
}
let big: Int64BE;
if (this.storedProcedure !== EMPTY) {
big = new Int64BE(this.storedProcedure);
big.toBuffer().copy(buffer, 8, 0, 8);
} else if (this.trigger !== EMPTY) {
big = new Int64BE(this.trigger);
big.toBuffer().copy(buffer, 8, 0, 8);
} else if (this.userDefinedFunction !== EMPTY) {
big = new Int64BE(this.userDefinedFunction);
big.toBuffer().copy(buffer, 8, 0, 8);
} else if (this.conflict !== EMPTY) {
big = new Int64BE(this.conflict);
big.toBuffer().copy(buffer, 8, 0, 8);
} else if (this.document !== EMPTY) {
big = new Int64BE(this.document);
big.toBuffer().copy(buffer, 8, 0, 8);
} else if (this.permission !== EMPTY) {
big = new Int64BE(this.permission);
big.toBuffer().copy(buffer, 8, 0, 8);