New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@0xcert/ethereum-generic-provider

Package Overview
Dependencies
Maintainers
2
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0xcert/ethereum-generic-provider - npm Package Compare versions

Comparing version 0.0.0-alpha4 to 0.0.0-alpha5

9

dist/core/mutation.d.ts

@@ -5,2 +5,7 @@ /// <reference types="node" />

import { MutationEvent } from './types';
export declare enum MutationStatus {
INITIALIZED = 0,
PENDING = 1,
RESOLVED = 2
}
export declare class Mutation extends EventEmitter implements MutationBase {

@@ -13,3 +18,3 @@ protected $id: string;

protected $timer: any;
protected $done: boolean;
protected $status: MutationStatus;
constructor(provider: any, id: string);

@@ -21,2 +26,4 @@ readonly id: string;

readonly receiverId: string;
isPending(): boolean;
isResolved(): boolean;
emit(event: MutationEvent.CONFIRM, mutation: Mutation): any;

@@ -23,0 +30,0 @@ emit(event: MutationEvent.RESOLVE, mutation: Mutation): any;

41

dist/core/mutation.js

@@ -14,2 +14,8 @@ "use strict";

const types_1 = require("./types");
var MutationStatus;
(function (MutationStatus) {
MutationStatus[MutationStatus["INITIALIZED"] = 0] = "INITIALIZED";
MutationStatus[MutationStatus["PENDING"] = 1] = "PENDING";
MutationStatus[MutationStatus["RESOLVED"] = 2] = "RESOLVED";
})(MutationStatus = exports.MutationStatus || (exports.MutationStatus = {}));
class Mutation extends events_1.EventEmitter {

@@ -20,3 +26,3 @@ constructor(provider, id) {

this.$timer = null;
this.$done = false;
this.$status = MutationStatus.INITIALIZED;
this.$id = normalize_address_1.normalizeAddress(id);

@@ -40,2 +46,8 @@ this.$provider = provider;

}
isPending() {
return this.$status === MutationStatus.PENDING;
}
isResolved() {
return this.$status === MutationStatus.RESOLVED;
}
emit(...args) {

@@ -60,9 +72,20 @@ return super.emit.call(this, ...args);

return __awaiter(this, void 0, void 0, function* () {
if (this.$done) {
const start = this.$status === MutationStatus.INITIALIZED;
if (this.isResolved()) {
return this;
}
else {
this.$status = MutationStatus.PENDING;
}
return new Promise((resolve, reject) => {
this.once(types_1.MutationEvent.RESOLVE, () => resolve(this));
this.once(types_1.MutationEvent.ERROR, (err) => reject(err));
this.loopUntilResolved();
if (!this.isResolved()) {
this.once(types_1.MutationEvent.RESOLVE, () => resolve(this));
this.once(types_1.MutationEvent.ERROR, (err) => reject(err));
}
else {
resolve(this);
}
if (start) {
this.loopUntilResolved();
}
});

@@ -88,5 +111,5 @@ });

this.$receiverId = normalize_address_1.normalizeAddress(tx.to);
this.$confirmations = yield this.getLastBlock().then((lastBlock) => lastBlock - parseInt(tx.blockNumber));
this.$confirmations = yield this.getLastBlock().then((lastBlock) => lastBlock - parseInt(tx.blockNumber || lastBlock));
if (this.confirmations >= 25) {
this.$done = true;
this.$status = MutationStatus.RESOLVED;
this.emit(types_1.MutationEvent.RESOLVE, this);

@@ -104,3 +127,3 @@ }

method: 'eth_getTransactionByHash',
params: this.id,
params: [this.id],
});

@@ -114,3 +137,3 @@ return res.result;

method: 'eth_getTransactionReceipt',
params: this.id,
params: [this.id],
});

@@ -117,0 +140,0 @@ return res.result;

@@ -6,3 +6,3 @@ import { RpcResponse, SendOptions, SignMethod } from './types';

signMethod?: SignMethod;
unsafeRecipientIds?: string[];
unsafeAccountIds?: string[];
}

@@ -12,3 +12,3 @@ export declare class GenericProvider {

signMethod: SignMethod;
unsafeRecipientIds: string[];
unsafeAccountIds: string[];
protected $client: any;

@@ -15,0 +15,0 @@ protected $id: number;

@@ -18,3 +18,3 @@ "use strict";

this.signMethod = options.signMethod || types_1.SignMethod.ETH_SIGN;
this.unsafeRecipientIds = options.unsafeRecipientIds || [];
this.unsafeAccountIds = options.unsafeAccountIds || [];
this.$client = options.client && options.client.currentProvider

@@ -26,2 +26,44 @@ ? options.client.currentProvider

return __awaiter(this, void 0, void 0, function* () {
if (options.method === 'eth_sendTransaction' && options.params.length > 0) {
if (typeof options.params[0].gas === 'undefined') {
options.method = 'eth_estimateGas';
const res = yield new Promise((resolve, reject) => {
this.$client.send(Object.assign({ jsonrpc: '2.0', id: this.getNextId() }, options), (err, res) => {
if (err) {
return reject(err);
}
else if (res.error) {
return reject(res.error);
}
return resolve(res);
});
}).catch((err) => {
throw errors_1.parseError(err);
});
options.params[0].gas = Math.ceil(res.result * 1.1);
options.method = 'eth_sendTransaction';
}
if (typeof options.params[0].gasPrice === 'undefined') {
const res = yield new Promise((resolve, reject) => {
this.$client.send({
jsonrpc: '2.0',
method: 'eth_gasPrice',
params: [],
id: this.getNextId(),
}, (err, res) => {
if (err) {
return reject(err);
}
else if (res.error) {
return reject(res.error);
}
return resolve(res);
});
}).catch((err) => {
throw errors_1.parseError(err);
});
const multiplyer = 1.1;
options.params[0].gasPrice = Math.ceil(res.result * multiplyer);
}
}
const requestIndex = options.id || this.getNextId();

@@ -28,0 +70,0 @@ return new Promise((resolve, reject) => {

@@ -81,3 +81,3 @@ "use strict";

});
yield mutableXcert.instance.methods.updateTokenProof('1', '0x973124ffc4a03e66d6a4458e587d5d6146f71fc57f359c8d516e0b12a50ab0d9')
yield mutableXcert.instance.methods.updateTokenImprint('1', '0x973124ffc4a03e66d6a4458e587d5d6146f71fc57f359c8d516e0b12a50ab0d9')
.call({ from: owner })

@@ -234,3 +234,3 @@ .then(() => { ctx.fail(); })

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -275,3 +275,3 @@ value: '123',

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -316,3 +316,3 @@ value: '123',

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -357,3 +357,3 @@ value: '123',

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -398,3 +398,3 @@ value: '123',

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -441,3 +441,3 @@ value: '123',

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -483,6 +483,6 @@ value: '123',

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,
value: '123',
}
},
];

@@ -524,3 +524,3 @@ const orderData = {

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -527,0 +527,0 @@ value: '123',

@@ -43,3 +43,8 @@ "use strict";

mutation.on(__1.MutationEvent.RESOLVE, () => counters.resolve++);
mutation.resolve();
ctx.true(mutation.isPending());
yield mutation.resolve();
ctx.true(mutation.isResolved());
ctx.true(mutation.confirmations >= 25);
ctx.true(counters.confirm >= 1);
ctx.is(mutation.id, transactionHash);

@@ -49,6 +54,4 @@ ctx.is(mutation.senderId, coinbase.toLowerCase());

ctx.is(counters.confirm, 1);
ctx.true(mutation.confirmations >= 25);
ctx.true(counters.confirm >= 1);
}));
exports.default = spec;
//# sourceMappingURL=resolve-instance-method.test.js.map
{
"files": {
"packages/0xcert-ethereum-generic-provider/nodemon.json": "82b893373db9861f1df4b55d8ea68a5d37b118de",
"packages/0xcert-ethereum-generic-provider/package.json": "37586298ea324269e62417ef3df49c4384b8e200",
"packages/0xcert-ethereum-generic-provider/package.json": "cdbb63425a999db4baaeffa87a31c9b68dac7b23",
"packages/0xcert-ethereum-generic-provider/src/core/errors.ts": "4a3e19bb1a68371e5adfdfd4b1d42098ff73d17c",
"packages/0xcert-ethereum-generic-provider/src/core/mutation.ts": "1d0d6afa658f88c8a4e5b405028f7904c68b8c33",
"packages/0xcert-ethereum-generic-provider/src/core/provider.ts": "f093b9e195bf5fac07462e4479a920975d59ed12",
"packages/0xcert-ethereum-generic-provider/src/core/mutation.ts": "31cd40c11d4f23d9a4ce8d664ddf8ad752bb6355",
"packages/0xcert-ethereum-generic-provider/src/core/provider.ts": "80f41cc653b33d10243edfe69bf646d9190087f1",
"packages/0xcert-ethereum-generic-provider/src/core/types.ts": "02bd82e1d363f2c4e0e11ac1317a6f548d84220c",
"packages/0xcert-ethereum-generic-provider/src/index.ts": "a4b6262ea7cb45960084814850cb98a8717b05e8",
"packages/0xcert-ethereum-generic-provider/src/tests/core/errors/errors.test.ts": "0d10cb8373d8899ebcf9e82bd8fc6449d500dfc5",
"packages/0xcert-ethereum-generic-provider/src/tests/core/mutation/resolve-instance-method.test.ts": "c7a782d42de1867a820c8efd6baa3d97c9344c62",
"packages/0xcert-ethereum-generic-provider/src/tests/core/errors/errors.test.ts": "43c3d85967dd885274306679ef78af32c94ef851",
"packages/0xcert-ethereum-generic-provider/src/tests/core/mutation/resolve-instance-method.test.ts": "e39edc93c56ac25d19418af0ab082b5052307ac8",
"packages/0xcert-ethereum-generic-provider/src/tests/core/provider/send-instance-method.test.ts": "083c4d7c89ba9bbe89bd3ddff62f10a27b932502",
"packages/0xcert-ethereum-generic-provider/src/tests/index.test.ts": "8f3b7d1d01c857ac2d3231518a012242fc0607a5",
"packages/0xcert-ethereum-generic-provider/tsconfig.json": "4aeac3c20e45b7e477e82012eb7788f7dbb11bf3",
"common/config/rush/npm-shrinkwrap.json": "85e9a2392b6dc8ee32e79467374e9a32d2631090"
"common/config/rush/npm-shrinkwrap.json": "a99d60ec92a85b5d9f934b82b318c4360f4c7083"
},
"arguments": "npm run clean; npx tsc "
}
{
"name": "@0xcert/ethereum-generic-provider",
"version": "0.0.0-alpha4",
"version": "0.0.0-alpha5",
"description": "Ethereum ledger for 0xcert protocol.",

@@ -26,7 +26,7 @@ "main": "./dist/index.js",

"devDependencies": {
"@0xcert/ethereum-sandbox": "0.0.0-alpha4",
"@0xcert/ethereum-sandbox": "0.0.0-alpha5",
"@types/node": "^10.12.10",
"@specron/cli": "^0.3.0",
"@specron/spec": "^0.3.0",
"solc": "^0.4.25",
"@specron/cli": "^0.4.3",
"@specron/spec": "^0.4.3",
"solc": "^0.5.1",
"ts-node": "^7.0.1",

@@ -37,5 +37,5 @@ "typescript": "^3.1.1",

"dependencies": {
"@0xcert/ethereum-utils": "0.0.0-alpha4",
"@0xcert/scaffold": "0.0.0-alpha4"
"@0xcert/ethereum-utils": "0.0.0-alpha5",
"@0xcert/scaffold": "0.0.0-alpha5"
}
}

@@ -9,2 +9,11 @@ import { EventEmitter } from 'events';

*/
export enum MutationStatus {
INITIALIZED = 0,
PENDING = 1,
RESOLVED = 2,
}
/**
*
*/
export class Mutation extends EventEmitter implements MutationBase {

@@ -17,3 +26,3 @@ protected $id: string;

protected $timer: any = null;
protected $done: boolean = false;
protected $status: MutationStatus = MutationStatus.INITIALIZED;

@@ -68,2 +77,16 @@ /**

*/
public isPending() {
return this.$status === MutationStatus.PENDING;
}
/**
*
*/
public isResolved() {
return this.$status === MutationStatus.RESOLVED;
}
/**
*
*/
public emit(event: MutationEvent.CONFIRM, mutation: Mutation);

@@ -112,10 +135,23 @@ public emit(event: MutationEvent.RESOLVE, mutation: Mutation);

public async resolve() {
if (this.$done) {
const start = this.$status === MutationStatus.INITIALIZED;
if (this.isResolved()) {
return this;
}
else {
this.$status = MutationStatus.PENDING;
}
return new Promise((resolve, reject) => {
this.once(MutationEvent.RESOLVE, () => resolve(this));
this.once(MutationEvent.ERROR, (err) => reject(err));
this.loopUntilResolved();
if (!this.isResolved()) {
this.once(MutationEvent.RESOLVE, () => resolve(this));
this.once(MutationEvent.ERROR, (err) => reject(err));
}
else {
resolve(this);
}
if (start) {
this.loopUntilResolved();
}
});

@@ -149,6 +185,6 @@ }

this.$receiverId = normalizeAddress(tx.to);
this.$confirmations = await this.getLastBlock().then((lastBlock) => lastBlock - parseInt(tx.blockNumber));
this.$confirmations = await this.getLastBlock().then((lastBlock) => lastBlock - parseInt(tx.blockNumber || lastBlock));
if (this.confirmations >= 25) {
this.$done = true;
this.$status = MutationStatus.RESOLVED;
this.emit(MutationEvent.RESOLVE, this);

@@ -168,3 +204,3 @@ }

method: 'eth_getTransactionByHash',
params: this.id,
params: [this.id],
});

@@ -180,3 +216,3 @@ return res.result;

method: 'eth_getTransactionReceipt',
params: this.id,
params: [this.id],
});

@@ -183,0 +219,0 @@ return res.result;

@@ -11,3 +11,3 @@ import { RpcResponse, SendOptions, SignMethod } from './types';

signMethod?: SignMethod;
unsafeRecipientIds?: string[];
unsafeAccountIds?: string[];
}

@@ -21,3 +21,3 @@

public signMethod: SignMethod;
public unsafeRecipientIds: string[];
public unsafeAccountIds: string[];
protected $client: any;

@@ -34,3 +34,3 @@ protected $id: number = 0;

this.signMethod = options.signMethod || SignMethod.ETH_SIGN;
this.unsafeRecipientIds = options.unsafeRecipientIds || [];
this.unsafeAccountIds = options.unsafeAccountIds || [];

@@ -51,4 +51,62 @@ this.$client = options.client && options.client.currentProvider

public async post(options: SendOptions): Promise<RpcResponse> {
// TODO: testi if this works if error throwing works on ropsten or do we need to check if the
// resulting gas amount is the same as block gas amount => revert.
// if making a transaction where gas is not defined we calculate it using estimateGas.
if (options.method === 'eth_sendTransaction' && options.params.length > 0) {
if (typeof options.params[0].gas === 'undefined') {
options.method = 'eth_estimateGas';
const res = await new Promise<RpcResponse>((resolve, reject) => {
this.$client.send({
jsonrpc: '2.0',
id: this.getNextId(),
...options,
}, (err, res) => {
if (err) {
return reject(err);
}
else if (res.error) {
return reject(res.error);
}
return resolve(res);
});
}).catch((err) => {
throw parseError(err);
});
// estimate gas is sometimes in accurate (depends on the node). So to be sure we have enough
// gas we multiply result with 1.2.
options.params[0].gas = Math.ceil(res.result * 1.1);
options.method = 'eth_sendTransaction';
}
if (typeof options.params[0].gasPrice === 'undefined') {
// get gas price
const res = await new Promise<RpcResponse>((resolve, reject) => {
this.$client.send({
jsonrpc: '2.0',
method: 'eth_gasPrice',
params: [],
id: this.getNextId(),
}, (err, res) => {
if (err) {
return reject(err);
}
else if (res.error) {
return reject(res.error);
}
return resolve(res);
});
}).catch((err) => {
throw parseError(err);
});
// TODO: get multiplyer from provider settings
const multiplyer = 1.1;
// set gas price
options.params[0].gasPrice = Math.ceil(res.result * multiplyer);
}
}
const requestIndex = options.id || this.getNextId();
return new Promise<RpcResponse>((resolve, reject) => {

@@ -55,0 +113,0 @@ this.$client.send({

@@ -85,3 +85,3 @@ import { Spec } from '@specron/spec';

});
await mutableXcert.instance.methods.updateTokenProof('1','0x973124ffc4a03e66d6a4458e587d5d6146f71fc57f359c8d516e0b12a50ab0d9')
await mutableXcert.instance.methods.updateTokenImprint('1','0x973124ffc4a03e66d6a4458e587d5d6146f71fc57f359c8d516e0b12a50ab0d9')
.call({ from: owner })

@@ -251,3 +251,3 @@ .then(() => { ctx.fail(); })

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -299,3 +299,3 @@ value: '123',

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -346,3 +346,3 @@ value: '123',

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -393,3 +393,3 @@ value: '123',

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -439,3 +439,3 @@ value: '123',

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -487,3 +487,3 @@ value: '123',

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -533,6 +533,6 @@ value: '123',

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,
value: '123',
}
},
];

@@ -578,3 +578,3 @@

token: erc721.receipt._address,
param1: ctx.web3.utils.padLeft(jane, 64),
param1: jane,
to: bob,

@@ -581,0 +581,0 @@ value: '123',

@@ -50,4 +50,10 @@ import { Spec } from '@specron/spec';

mutation.on(MutationEvent.RESOLVE, () => counters.resolve++)
mutation.resolve();
ctx.true(mutation.isPending());
await mutation.resolve();
ctx.true(mutation.isResolved());
ctx.true(mutation.confirmations >= 25);
ctx.true(counters.confirm >= 1);
ctx.is(mutation.id, transactionHash);

@@ -57,6 +63,4 @@ ctx.is(mutation.senderId, coinbase.toLowerCase());

ctx.is(counters.confirm, 1);
ctx.true(mutation.confirmations >= 25);
ctx.true(counters.confirm >= 1);
});
export default spec;

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc