Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Updated forkedBlockchain block discovery logic with regex (#553)
Browse files Browse the repository at this point in the history
* Updated forkedBlockchain block discovery logic with regex

* use exec instead of match for xcode9.2 support

* Parse blocknumber

* regex use group

* Attempt xcode friendly regex

* Update code base on davidmurdoch review
  • Loading branch information
Thomas authored Apr 8, 2020
1 parent d1cb531 commit 25de0e2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/utils/forkedblockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ inherits(ForkedBlockchain, BlockchainDouble);
const httpReg = /^https?:/i;
const protocolReg = /^[A-Za-z][A-Za-z0-9+\-.]*:/;
const validProtocolReg = /^(?:http|ws)s?:/i;
const blockNumberReg = /@([0-9]+)$/;

function ForkedBlockchain(options) {
this.options = options || {};
Expand All @@ -29,10 +30,11 @@ function ForkedBlockchain(options) {
this.forkVersion = null;

if (typeof options.fork === "string") {
if (options.fork.indexOf("@") >= 0) {
const split = options.fork.split("@", 2);
options.fork = split[0];
options.fork_block_number = parseInt(split[1]);
const blockNumber = blockNumberReg.exec(options.fork);

if (blockNumber) {
options.fork = options.fork.slice(0, blockNumber.index);
options.fork_block_number = parseInt(blockNumber[1], 10);
}

let fork;
Expand Down

0 comments on commit 25de0e2

Please sign in to comment.