@0xcert/ethereum-generic-provider
Advanced tools
Comparing version 2.0.0-alpha2 to 2.0.0-alpha3
@@ -5,4 +5,4 @@ { | ||
{ | ||
"version": "2.0.0-alpha2", | ||
"tag": "@0xcert/ethereum-generic-provider_v2.0.0-alpha2", | ||
"version": "2.0.0-alpha3", | ||
"tag": "@0xcert/ethereum-generic-provider_v2.0.0-alpha3", | ||
"date": "Wed, 19 Jun 2019 10:31:05 GMT", | ||
@@ -9,0 +9,0 @@ "comments": {} |
@@ -5,3 +5,3 @@ # Change Log - @0xcert/ethereum-generic-provider | ||
## 2.0.0-alpha2 | ||
## 2.0.0-alpha3 | ||
Wed, 19 Jun 2019 10:31:05 GMT | ||
@@ -8,0 +8,0 @@ |
@@ -41,5 +41,7 @@ /// <reference types="node" /> | ||
off(event: MutationEvent): any; | ||
complete(): Promise<this>; | ||
complete(): Promise<any>; | ||
forget(): this; | ||
protected loopUntilResolved(): Promise<any>; | ||
resolve(): Promise<any>; | ||
protected resolveCurrentState(): Promise<any>; | ||
protected loopUntilCompleted(): Promise<void>; | ||
protected getTransactionObject(): Promise<any>; | ||
@@ -46,0 +48,0 @@ protected getTransactionReceipt(): Promise<any>; |
@@ -84,3 +84,3 @@ "use strict"; | ||
if (this.isCompleted()) { | ||
return this; | ||
return this.resolveCurrentState(); | ||
} | ||
@@ -100,3 +100,3 @@ else if (!this.isPending()) { | ||
if (start) { | ||
this.loopUntilResolved(); | ||
this.loopUntilCompleted(); | ||
} | ||
@@ -114,4 +114,9 @@ }); | ||
} | ||
loopUntilResolved() { | ||
resolve() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.resolveCurrentState(); | ||
}); | ||
} | ||
resolveCurrentState() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const tx = yield this.getTransactionObject(); | ||
@@ -136,4 +141,9 @@ if (tx && (!tx.to || tx.to === '0x0')) { | ||
} | ||
}); | ||
} | ||
loopUntilCompleted() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.resolveCurrentState(); | ||
if (this._provider.mutationTimeout === -1 || Date.now() - this._started < this._provider.mutationTimeout) { | ||
this._timer = setTimeout(this.loopUntilResolved.bind(this), this._speed); | ||
this._timer = setTimeout(this.loopUntilCompleted.bind(this), this._speed); | ||
} | ||
@@ -140,0 +150,0 @@ else { |
@@ -32,3 +32,3 @@ "use strict"; | ||
})); | ||
spec.test('resolves mutation', (ctx) => __awaiter(this, void 0, void 0, function* () { | ||
spec.test('completes mutation', (ctx) => __awaiter(this, void 0, void 0, function* () { | ||
const provider = ctx.get('provider'); | ||
@@ -53,4 +53,8 @@ const coinbase = ctx.get('coinbase'); | ||
ctx.is(mutation.receiverId, bob); | ||
yield ctx.web3.eth.sendTransaction({ from: coinbase, to: bob, value: 0 }); | ||
yield mutation.complete(); | ||
ctx.true(mutation.isCompleted()); | ||
ctx.is(mutation.confirmations, 2); | ||
})); | ||
spec.test('resolves mutation in sandbox mode', (ctx) => __awaiter(this, void 0, void 0, function* () { | ||
spec.test('completes mutation in sandbox mode', (ctx) => __awaiter(this, void 0, void 0, function* () { | ||
const provider = ctx.get('provider'); | ||
@@ -57,0 +61,0 @@ provider.sandbox = true; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const spec = new spec_1.Spec(); | ||
spec.only('exposes objects', (ctx) => { | ||
spec.test('exposes objects', (ctx) => { | ||
ctx.true(!!view.GenericProvider); | ||
@@ -9,0 +9,0 @@ ctx.true(!!view.SignMethod); |
{ | ||
"files": {}, | ||
"arguments": "npm run lint && npx nyc npx specron test " | ||
"arguments": "npm run clean && npx tsc " | ||
} |
{ | ||
"name": "@0xcert/ethereum-generic-provider", | ||
"version": "2.0.0-alpha2", | ||
"version": "2.0.0-alpha3", | ||
"description": "Basic implementation of communication provider for the Ethereum blockchain.", | ||
@@ -70,3 +70,3 @@ "main": "./dist/index.js", | ||
"devDependencies": { | ||
"@0xcert/ethereum-sandbox": "2.0.0-alpha2", | ||
"@0xcert/ethereum-sandbox": "2.0.0-alpha3", | ||
"@types/node": "^10.12.24", | ||
@@ -84,6 +84,6 @@ "@specron/cli": "^0.5.6", | ||
"dependencies": { | ||
"@0xcert/ethereum-utils": "2.0.0-alpha2", | ||
"@0xcert/scaffold": "2.0.0-alpha2", | ||
"@0xcert/ethereum-utils": "2.0.0-alpha3", | ||
"@0xcert/scaffold": "2.0.0-alpha3", | ||
"events": "^3.0.0" | ||
} | ||
} |
@@ -202,3 +202,3 @@ import { normalizeAddress } from '@0xcert/ethereum-utils/dist/lib/normalize-address'; | ||
if (this.isCompleted()) { | ||
return this; | ||
return this.resolveCurrentState(); | ||
} else if (!this.isPending()) { | ||
@@ -217,3 +217,3 @@ this._status = MutationStatus.PENDING; | ||
if (start) { | ||
this.loopUntilResolved(); | ||
this.loopUntilCompleted(); | ||
} | ||
@@ -238,9 +238,12 @@ }); | ||
/** | ||
* Helper methods for waiting to resolve mutation. | ||
* IMPORTANT: After submiting a transaction to the Ethereum network, the | ||
* transaction can not be found for some seconds. This happens because the | ||
* Ethereum nodes in a cluster are not in sync and we must wait some time for | ||
* this to happen. | ||
* Resolves mutation with its current data. | ||
*/ | ||
protected async loopUntilResolved() { | ||
public async resolve() { | ||
return this.resolveCurrentState(); | ||
} | ||
/** | ||
* Helper method that resolves current mutation status. | ||
*/ | ||
protected async resolveCurrentState() { | ||
const tx = await this.getTransactionObject(); | ||
@@ -265,4 +268,15 @@ if (tx && (!tx.to || tx.to === '0x0')) { | ||
} | ||
} | ||
/** | ||
* Helper methods for waiting until mutation is completed. | ||
* IMPORTANT: After submiting a transaction to the Ethereum network, the | ||
* transaction can not be found for some seconds. This happens because the | ||
* Ethereum nodes in a cluster are not in sync and we must wait some time for | ||
* this to happen. | ||
*/ | ||
protected async loopUntilCompleted() { | ||
await this.resolveCurrentState(); | ||
if (this._provider.mutationTimeout === -1 || Date.now() - this._started < this._provider.mutationTimeout) { | ||
this._timer = setTimeout(this.loopUntilResolved.bind(this), this._speed); | ||
this._timer = setTimeout(this.loopUntilCompleted.bind(this), this._speed); | ||
} else { | ||
@@ -269,0 +283,0 @@ this.emit(MutationEvent.ERROR, new Error('Mutation has timed out')); |
@@ -34,3 +34,3 @@ import { Protocol } from '@0xcert/ethereum-sandbox'; | ||
spec.test('resolves mutation', async (ctx) => { | ||
spec.test('completes mutation', async (ctx) => { | ||
const provider = ctx.get('provider'); | ||
@@ -58,5 +58,11 @@ const coinbase = ctx.get('coinbase'); | ||
ctx.is(mutation.receiverId, bob); | ||
await ctx.web3.eth.sendTransaction({ from: coinbase, to: bob, value: 0 }); // simulate new block | ||
await mutation.complete(); | ||
ctx.true(mutation.isCompleted()); | ||
ctx.is(mutation.confirmations, 2); | ||
}); | ||
spec.test('resolves mutation in sandbox mode', async (ctx) => { | ||
spec.test('completes mutation in sandbox mode', async (ctx) => { | ||
const provider = ctx.get('provider'); | ||
@@ -63,0 +69,0 @@ provider.sandbox = true; |
@@ -6,3 +6,3 @@ import { Spec } from '@specron/spec'; | ||
spec.only('exposes objects', (ctx) => { | ||
spec.test('exposes objects', (ctx) => { | ||
ctx.true(!!view.GenericProvider); | ||
@@ -9,0 +9,0 @@ ctx.true(!!view.SignMethod); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
89
2730
132544
+ Added@0xcert/ethereum-utils@2.0.0-alpha3(transitive)
+ Added@0xcert/scaffold@2.0.0-alpha3(transitive)
- Removed@0xcert/ethereum-utils@2.0.0-alpha2(transitive)
- Removed@0xcert/scaffold@2.0.0-alpha2(transitive)