Consult the blockchain and gather information for use in a new signed transaction. For Transaction as Proof of Stake (TaPOS), 32 bits of a recent block Id is included. Because all transactions use TaPOS, this solves the nothing at stake attack. This is usually called for every transaction or
(api, expireInSeconds = 60, callback)
| 38 | @example eos.createTransaction(60, (error, headers) => {}) |
| 39 | */ |
| 40 | function createTransaction(api, expireInSeconds = 60, callback) { |
| 41 | if(!callback) { |
| 42 | throw new TypeError('callback parameter is required') |
| 43 | } |
| 44 | api.getInfo(checkError(callback, info => { |
| 45 | const chainDate = new Date(info.head_block_time + 'Z') |
| 46 | |
| 47 | api.getBlock(info.last_irreversible_block_num, checkError(callback, block => { |
| 48 | const expiration = new Date(chainDate.getTime() + expireInSeconds * 1000) |
| 49 | |
| 50 | const ref_block_num = info.last_irreversible_block_num & 0xFFFF |
| 51 | |
| 52 | const headers = { |
| 53 | expiration: expiration.toISOString().split('.')[0], |
| 54 | ref_block_num, |
| 55 | ref_block_prefix: block.ref_block_prefix, |
| 56 | max_net_usage_words: 0, |
| 57 | max_cpu_usage_ms: 0, |
| 58 | delay_sec: 0, |
| 59 | context_free_actions: [], |
| 60 | actions: [], |
| 61 | signatures: [], |
| 62 | transaction_extensions: [] |
| 63 | } |
| 64 | callback(null, headers) |
| 65 | })) |
| 66 | })) |
| 67 | } |
| 68 | |
| 69 | const checkError = (parentErr, parrentRes) => (error, result) => { |
| 70 | if (error) { |
nothing calls this directly
no test coverage detected