@appliedblockchain/helpers
Advanced tools
Comparing version 3.1.1 to 3.2.0
# Changelog | ||
## [v3.2.0](../../compare/v3.1.1...v3.2.0) (2019-11-28) | ||
* Updating speculative nonce tests to work on real addresses. | ||
* Updating speculative nonce to work on checksum addresses. | ||
* Adding checksum-address-of-address helper. | ||
* Adding tests around speculative nonce. | ||
* Lowering speculative nonce timeout from 1m to 12s. | ||
* Updating changelog. | ||
## [v3.1.1](../../compare/v3.1.0...v3.1.1) (2019-11-06) | ||
@@ -4,0 +13,0 @@ |
{ | ||
"name": "@appliedblockchain/helpers", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "No dependency, single file helpers.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
// @flow | ||
const { inspect } = require('util') | ||
const assert = require('assert') | ||
const { inspect } = require('util') | ||
const rejectTimeout = require('./reject-timeout') | ||
const checksumAddressOfAddress_ = require('./checksum-address-of-address') | ||
const Err = require('./err') | ||
const logOf = require('./log-of') | ||
const rejectTimeout = require('./reject-timeout') | ||
@@ -20,5 +21,13 @@ /*:: | ||
/** Expire cached nonces after 1 minute. */ | ||
const defaultTimeout = 60 * 1000 | ||
/** Expire cached nonces after 12 seconds. */ | ||
const defaultTimeout = 12 * 1000 | ||
function checksumAddressOfAddress(address) { | ||
const checksumAddress = checksumAddressOfAddress_(address) | ||
if (checksumAddress !== address) { | ||
log.warn(`Invalid checksum address ${address}.`, (new Error).stack) | ||
} | ||
return checksumAddress | ||
} | ||
class SpeculativeNonce { | ||
@@ -43,3 +52,3 @@ | ||
this.nonceOfAddress = (address /*: string */) => { | ||
return rejectTimeout(nonceOfAddress(address), defaultTimeout - 1000) | ||
return rejectTimeout(nonceOfAddress(checksumAddressOfAddress(address)), defaultTimeout - 1000) | ||
} | ||
@@ -52,4 +61,6 @@ | ||
next(address /*: string */) /*: Promise<number> */ { | ||
next(address_ /*: string */) /*: Promise<number> */ { | ||
const address = checksumAddressOfAddress(address_) | ||
// If there's nonce available, use sync code path to retrieve it. | ||
@@ -66,3 +77,6 @@ const nonce = this.nonces.get(address) | ||
addExecutor(address /*: string */, executor /*: Executor */) { | ||
addExecutor(address_ /*: string */, executor /*: Executor */) { | ||
const address = checksumAddressOfAddress(address_) | ||
const { nonceOfAddress } = this | ||
@@ -80,3 +94,4 @@ const executors = this.executors.get(address) | ||
resolveNonce(address /*: string */, nonce_ /*: number */) { | ||
resolveNonce(address_ /*: string */, nonce_ /*: number */) { | ||
const address = checksumAddressOfAddress(address_) | ||
let nonce = nonce_ | ||
@@ -112,3 +127,4 @@ assert(!this.nonces.has(address), `Expected nonce for ${inspect(address)} to be undefined.`) | ||
rejectNonce(address /*: string */, err /*: Error */) { | ||
rejectNonce(address_ /*: string */, err /*: Error */) { | ||
const address = checksumAddressOfAddress(address_) | ||
const executors = this.executors.get(address) | ||
@@ -115,0 +131,0 @@ if (!executors) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
128559
115
3404