Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
replace get_block with get_block_header_state
Browse files Browse the repository at this point in the history
  • Loading branch information
UMU618 committed Aug 14, 2019
1 parent 9487f32 commit d62b6c8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/eosjs-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,17 @@ export class Api {
};
}

private reverseHex(h: string) {
return h.substr(6, 2) + h.substr(4, 2) + h.substr(2, 2) + h.substr(0, 2);
}

private transactionHeader(refBlock: any, expireSeconds: number) {
return {
expiration: ser.timePointSecToDate(ser.dateToTimePointSec(refBlock.header.timestamp) + expireSeconds),
ref_block_num: refBlock.block_num & 0xffff,
ref_block_prefix: parseInt(this.reverseHex(refBlock.id.substr(16, 8)), 16),
};
}
/**
* Create and optionally broadcast a transaction.
*
Expand All @@ -241,8 +252,8 @@ export class Api {
if (!info) {
info = await this.rpc.get_info();
}
const refBlock = await this.rpc.get_block(info.head_block_num - blocksBehind);
transaction = { ...ser.transactionHeader(refBlock, expireSeconds), ...transaction };
const refBlock = await this.rpc.get_block_header_state(info.head_block_num - blocksBehind);
transaction = { ...this.transactionHeader(refBlock, expireSeconds), ...transaction };
}

if (!this.hasRequiredTaposFields(transaction)) {
Expand Down

0 comments on commit d62b6c8

Please sign in to comment.