@0xcert/ethereum-generic-provider
Advanced tools
Comparing version 0.0.0-alpha3 to 0.0.0-alpha4
@@ -1,2 +0,2 @@ | ||
import { GenericProviderError } from '@0xcert/scaffold'; | ||
export declare function parseError(error: any): GenericProviderError; | ||
import { ProviderError } from '@0xcert/scaffold'; | ||
export declare function parseError(error: any): ProviderError; |
@@ -5,106 +5,108 @@ "use strict"; | ||
function parseError(error) { | ||
if (error instanceof scaffold_1.GenericProviderError) { | ||
if (error instanceof scaffold_1.ProviderError) { | ||
return error; | ||
} | ||
else { | ||
const stringError = String(error); | ||
if (stringError.indexOf('revert') > 0) { | ||
if (stringError.indexOf('003001') > 0 | ||
|| stringError.indexOf('004001') > 0 | ||
|| stringError.indexOf('005001') > 0 | ||
|| stringError.indexOf('006001') > 0 | ||
|| stringError.indexOf('018002') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.ZERO_ADDRESS, error); | ||
} | ||
if (stringError.indexOf('003002') > 0 | ||
|| stringError.indexOf('004002') > 0 | ||
|| stringError.indexOf('005002') > 0 | ||
|| stringError.indexOf('006002') > 0 | ||
|| stringError.indexOf('010001') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.INVALID_NFT, error); | ||
} | ||
if (stringError.indexOf('003003') > 0 | ||
|| stringError.indexOf('003004') > 0 | ||
|| stringError.indexOf('004003') > 0 | ||
|| stringError.indexOf('004004') > 0 | ||
|| stringError.indexOf('005003') > 0 | ||
|| stringError.indexOf('005004') > 0 | ||
|| stringError.indexOf('006003') > 0 | ||
|| stringError.indexOf('006004') > 0 | ||
|| stringError.indexOf('008001') > 0 | ||
|| stringError.indexOf('017001') > 0 | ||
|| stringError.indexOf('018001') > 0 | ||
|| stringError.indexOf('019001') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.NOT_AUTHORIZED, error); | ||
} | ||
if (stringError.indexOf('003005') > 0 | ||
|| stringError.indexOf('004005') > 0 | ||
|| stringError.indexOf('005005') > 0 | ||
|| stringError.indexOf('006005') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.RECEIVER_DOES_NOT_SUPPORT_NFT, error); | ||
} | ||
if (stringError.indexOf('003006') > 0 | ||
|| stringError.indexOf('004006') > 0 | ||
|| stringError.indexOf('005006') > 0 | ||
|| stringError.indexOf('006006') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.NFT_ALREADY_EXISTS, error); | ||
} | ||
if (stringError.indexOf('005007') > 0 | ||
|| stringError.indexOf('006007') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.INVALID_INDEX, error); | ||
} | ||
if (stringError.indexOf('009001') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.TRANSFERS_PAUSED, error); | ||
} | ||
if (stringError.indexOf('012001') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.COIN_TRANSFER_FAILED, error); | ||
} | ||
if (stringError.indexOf('015001') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.INVALID_SIGNATURE_KIND, error); | ||
} | ||
if (stringError.indexOf('015002') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.INVALID_PROXY, error); | ||
} | ||
if (stringError.indexOf('015003') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.YOU_ARE_NOT_THE_TAKER, error); | ||
} | ||
if (stringError.indexOf('015004') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.SENDER_NOT_TAKER_OR_MAKER, error); | ||
} | ||
if (stringError.indexOf('015005') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.ORDER_EXPIRED, error); | ||
} | ||
if (stringError.indexOf('015006') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.INVALID_SIGNATURE, error); | ||
} | ||
if (stringError.indexOf('015007') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.ORDER_CANCELED, error); | ||
} | ||
if (stringError.indexOf('015008') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.ORDER_CANNOT_BE_PERFORMED_TWICE, error); | ||
} | ||
if (stringError.indexOf('015009') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.YOU_ARE_NOT_THE_MAKER, error); | ||
} | ||
if (stringError.indexOf('015010') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.SIGNER_NOT_AUTHORIZED, error); | ||
} | ||
if (stringError.indexOf('017002') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.ONE_ZERO_ABILITY_HAS_TO_EXIST, error); | ||
} | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.GENERAL_REVERT, error); | ||
const stringError = String(error); | ||
if (stringError.indexOf('revert') > 0) { | ||
if (stringError.indexOf('003001') > 0 | ||
|| stringError.indexOf('004001') > 0 | ||
|| stringError.indexOf('005001') > 0 | ||
|| stringError.indexOf('006001') > 0 | ||
|| stringError.indexOf('018002') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.ZERO_ADDRESS, error); | ||
} | ||
if (stringError.indexOf('Transaction was not mined within') > 0 | ||
|| stringError.indexOf('Invalid JSON RPC response') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.TRANSATION_RESPONSE_ERROR_CHECK_PENDING_TRANSACTIONS, error); | ||
else if (stringError.indexOf('003002') > 0 | ||
|| stringError.indexOf('004002') > 0 | ||
|| stringError.indexOf('005002') > 0 | ||
|| stringError.indexOf('006002') > 0 | ||
|| stringError.indexOf('010001') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.INVALID_NFT, error); | ||
} | ||
if (stringError.indexOf('invalid address') > 0 | ||
|| stringError.indexOf('is invalid, the capitalization checksum test failed, or its an indrect IBAN address which') > 0 | ||
|| stringError.indexOf('Provided address is not a valid addres') > 0) { | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.INVALID_ADDRESS, error); | ||
else if (stringError.indexOf('003003') > 0 | ||
|| stringError.indexOf('003004') > 0 | ||
|| stringError.indexOf('004003') > 0 | ||
|| stringError.indexOf('004004') > 0 | ||
|| stringError.indexOf('005003') > 0 | ||
|| stringError.indexOf('005004') > 0 | ||
|| stringError.indexOf('006003') > 0 | ||
|| stringError.indexOf('006004') > 0 | ||
|| stringError.indexOf('008001') > 0 | ||
|| stringError.indexOf('017001') > 0 | ||
|| stringError.indexOf('018001') > 0 | ||
|| stringError.indexOf('019001') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.NOT_AUTHORIZED, error); | ||
} | ||
return new scaffold_1.GenericProviderError(scaffold_1.GenericProviderIssue.UNHANDLED, error); | ||
else if (stringError.indexOf('003005') > 0 | ||
|| stringError.indexOf('004005') > 0 | ||
|| stringError.indexOf('005005') > 0 | ||
|| stringError.indexOf('006005') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.RECEIVER_DOES_NOT_SUPPORT_NFT, error); | ||
} | ||
else if (stringError.indexOf('003006') > 0 | ||
|| stringError.indexOf('004006') > 0 | ||
|| stringError.indexOf('005006') > 0 | ||
|| stringError.indexOf('006006') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.NFT_ALREADY_EXISTS, error); | ||
} | ||
else if (stringError.indexOf('005007') > 0 | ||
|| stringError.indexOf('006007') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.INVALID_INDEX, error); | ||
} | ||
else if (stringError.indexOf('009001') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.TRANSFERS_PAUSED, error); | ||
} | ||
else if (stringError.indexOf('012001') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.COIN_TRANSFER_FAILED, error); | ||
} | ||
else if (stringError.indexOf('015001') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.INVALID_SIGNATURE_KIND, error); | ||
} | ||
else if (stringError.indexOf('015002') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.INVALID_PROXY, error); | ||
} | ||
else if (stringError.indexOf('015003') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.YOU_ARE_NOT_THE_TAKER, error); | ||
} | ||
else if (stringError.indexOf('015004') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.SENDER_NOT_TAKER_OR_MAKER, error); | ||
} | ||
else if (stringError.indexOf('015005') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.ORDER_EXPIRED, error); | ||
} | ||
else if (stringError.indexOf('015006') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.INVALID_SIGNATURE, error); | ||
} | ||
else if (stringError.indexOf('015007') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.ORDER_CANCELED, error); | ||
} | ||
else if (stringError.indexOf('015008') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.ORDER_CANNOT_BE_PERFORMED_TWICE, error); | ||
} | ||
else if (stringError.indexOf('015009') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.YOU_ARE_NOT_THE_MAKER, error); | ||
} | ||
else if (stringError.indexOf('015010') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.SIGNER_NOT_AUTHORIZED, error); | ||
} | ||
else if (stringError.indexOf('017002') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.ONE_ZERO_ABILITY_HAS_TO_EXIST, error); | ||
} | ||
else { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.GENERAL_REVERT, error); | ||
} | ||
} | ||
else if (stringError.indexOf('Transaction was not mined within') > 0 | ||
|| stringError.indexOf('Invalid JSON RPC response') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.TRANSATION_RESPONSE_ERROR_CHECK_PENDING_TRANSACTIONS, error); | ||
} | ||
else if (stringError.indexOf('invalid address') > 0 | ||
|| stringError.indexOf('is invalid, the capitalization checksum test failed, or its an indrect IBAN address which') > 0 | ||
|| stringError.indexOf('Provided address is not a valid addres') > 0) { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.INVALID_ADDRESS, error); | ||
} | ||
else { | ||
return new scaffold_1.ProviderError(scaffold_1.ProviderIssue.UNHANDLED, error); | ||
} | ||
} | ||
exports.parseError = parseError; | ||
//# sourceMappingURL=errors.js.map |
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import { MutationBase } from '@0xcert/scaffold'; | ||
import { MutationEvent } from './types'; | ||
export declare class Mutation extends EventEmitter { | ||
id: string; | ||
confirmations: number; | ||
protected provider: any; | ||
protected timer: any; | ||
protected done: boolean; | ||
export declare class Mutation extends EventEmitter implements MutationBase { | ||
protected $id: string; | ||
protected $confirmations: number; | ||
protected $senderId: string; | ||
protected $receiverId: string; | ||
protected $provider: any; | ||
protected $timer: any; | ||
protected $done: boolean; | ||
constructor(provider: any, id: string); | ||
readonly id: string; | ||
readonly provider: any; | ||
readonly confirmations: number; | ||
readonly senderId: string; | ||
readonly receiverId: string; | ||
emit(event: MutationEvent.CONFIRM, mutation: Mutation): any; | ||
@@ -24,2 +32,5 @@ emit(event: MutationEvent.RESOLVE, mutation: Mutation): any; | ||
protected loopUntilResolved(): Promise<any>; | ||
protected getTransactionObject(): Promise<any>; | ||
protected getTransactionReceipt(): Promise<any>; | ||
protected getLastBlock(): Promise<number>; | ||
} |
@@ -12,2 +12,3 @@ "use strict"; | ||
const events_1 = require("events"); | ||
const normalize_address_1 = require("@0xcert/ethereum-utils/dist/lib/normalize-address"); | ||
const types_1 = require("./types"); | ||
@@ -17,8 +18,23 @@ class Mutation extends events_1.EventEmitter { | ||
super(); | ||
this.confirmations = 0; | ||
this.timer = null; | ||
this.done = false; | ||
this.provider = provider; | ||
this.id = id; | ||
this.$confirmations = 0; | ||
this.$timer = null; | ||
this.$done = false; | ||
this.$id = normalize_address_1.normalizeAddress(id); | ||
this.$provider = provider; | ||
} | ||
get id() { | ||
return this.$id; | ||
} | ||
get provider() { | ||
return this.$provider; | ||
} | ||
get confirmations() { | ||
return this.$confirmations; | ||
} | ||
get senderId() { | ||
return this.$senderId; | ||
} | ||
get receiverId() { | ||
return this.$receiverId; | ||
} | ||
emit(...args) { | ||
@@ -43,3 +59,3 @@ return super.emit.call(this, ...args); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.done) { | ||
if (this.$done) { | ||
return this; | ||
@@ -55,4 +71,4 @@ } | ||
forget() { | ||
if (this.timer) { | ||
clearTimeout(this.timer); | ||
if (this.$timer) { | ||
clearTimeout(this.$timer); | ||
} | ||
@@ -63,13 +79,14 @@ return this; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const tx = yield this.provider.getTransactionByHash(this.id); | ||
const tx = yield this.getTransactionObject(); | ||
if (!tx) { | ||
return this.emit(types_1.MutationEvent.ERROR, new Error('Mutation not found (1)')); | ||
} | ||
const block = yield this.provider.getBlockByNumber('latest'); | ||
if (!block) { | ||
return this.emit(types_1.MutationEvent.ERROR, new Error('Mutation not found (2)')); | ||
else if (!tx.to) { | ||
tx.to = yield this.getTransactionReceipt().then((r) => r.contractAddress); | ||
} | ||
this.confirmations = block.number - tx.blockNumber; | ||
this.$senderId = normalize_address_1.normalizeAddress(tx.from); | ||
this.$receiverId = normalize_address_1.normalizeAddress(tx.to); | ||
this.$confirmations = yield this.getLastBlock().then((lastBlock) => lastBlock - parseInt(tx.blockNumber)); | ||
if (this.confirmations >= 25) { | ||
this.done = true; | ||
this.$done = true; | ||
this.emit(types_1.MutationEvent.RESOLVE, this); | ||
@@ -79,8 +96,34 @@ } | ||
this.emit(types_1.MutationEvent.CONFIRM, this); | ||
this.timer = setTimeout(this.loopUntilResolved.bind(this), 14000); | ||
this.$timer = setTimeout(this.loopUntilResolved.bind(this), 14000); | ||
} | ||
}); | ||
} | ||
getTransactionObject() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield this.$provider.post({ | ||
method: 'eth_getTransactionByHash', | ||
params: this.id, | ||
}); | ||
return res.result; | ||
}); | ||
} | ||
getTransactionReceipt() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield this.$provider.post({ | ||
method: 'eth_getTransactionReceipt', | ||
params: this.id, | ||
}); | ||
return res.result; | ||
}); | ||
} | ||
getLastBlock() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield this.$provider.post({ | ||
method: 'eth_blockNumber', | ||
}); | ||
return parseInt(res.result); | ||
}); | ||
} | ||
} | ||
exports.Mutation = Mutation; | ||
//# sourceMappingURL=mutation.js.map |
@@ -1,27 +0,17 @@ | ||
/// <reference types="node" /> | ||
import { EventEmitter } from "events"; | ||
import { TransactionObject, BlockObject, RpcResponse, QuantityTag, ContractQueryOptions, ContractMutationOptions, SendOptions, SignOptions, SignMethod, ProviderEvent } from './types'; | ||
import { Mutation } from './mutation'; | ||
import { RpcResponse, SendOptions, SignMethod } from './types'; | ||
export interface GenericProviderOptions { | ||
accountId?: string; | ||
client: any; | ||
client?: any; | ||
signMethod?: SignMethod; | ||
unsafeRecipientIds?: string[]; | ||
} | ||
export declare class GenericProvider extends EventEmitter { | ||
protected client: any; | ||
protected requestIndex: number; | ||
export declare class GenericProvider { | ||
accountId: string; | ||
signMethod: SignMethod; | ||
unsafeRecipientIds: string[]; | ||
protected $client: any; | ||
protected $id: number; | ||
constructor(options: GenericProviderOptions); | ||
emit(event: ProviderEvent): boolean; | ||
on(event: ProviderEvent, handler: () => any): this; | ||
once(event: ProviderEvent, handler: () => any): this; | ||
off(event: ProviderEvent, handler?: () => any): this; | ||
getBlockByNumber(tag: QuantityTag): Promise<BlockObject>; | ||
getTransactionByHash(hash: string): Promise<TransactionObject>; | ||
mutateContract(options: ContractMutationOptions): Promise<Mutation>; | ||
queryContract<T = any[]>(options: ContractQueryOptions): Promise<T>; | ||
sign(options: SignOptions): Promise<string>; | ||
protected send(options: SendOptions): Promise<RpcResponse>; | ||
protected getUniqueRequestIndex(): number; | ||
post(options: SendOptions): Promise<RpcResponse>; | ||
protected getNextId(): number; | ||
} |
@@ -11,101 +11,19 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const events_1 = require("events"); | ||
const getBlockByNumber = require("../procedures/get-block-by-number"); | ||
const getTransactionByHash = require("../procedures/get-transaction-by-hash"); | ||
const mutateContract = require("../procedures/mutate-contract"); | ||
const queryContract = require("../procedures/query-contract"); | ||
const sign = require("../procedures/sign"); | ||
const types_1 = require("./types"); | ||
const errors_1 = require("./errors"); | ||
const mutation_1 = require("./mutation"); | ||
class GenericProvider extends events_1.EventEmitter { | ||
class GenericProvider { | ||
constructor(options) { | ||
super(); | ||
this.requestIndex = 0; | ||
this.$id = 0; | ||
this.accountId = options.accountId; | ||
this.signMethod = options.signMethod || types_1.SignMethod.ETH_SIGN; | ||
this.client = options.client && options.client.currentProvider | ||
this.unsafeRecipientIds = options.unsafeRecipientIds || []; | ||
this.$client = options.client && options.client.currentProvider | ||
? options.client.currentProvider | ||
: options.client; | ||
if (this.client) { | ||
this.client.on(types_1.ProviderEvent.NETWORK_CHANGE, () => this.emit(types_1.ProviderEvent.NETWORK_CHANGE)); | ||
this.client.on(types_1.ProviderEvent.ACCOUNT_CHANGE, () => this.emit(types_1.ProviderEvent.ACCOUNT_CHANGE)); | ||
} | ||
} | ||
emit(event) { | ||
return super.emit(event); | ||
} | ||
on(event, handler) { | ||
return super.on(event, handler); | ||
} | ||
once(event, handler) { | ||
return super.once(event, handler); | ||
} | ||
off(event, handler) { | ||
if (handler) { | ||
return super.off(event, handler); | ||
} | ||
else { | ||
return super.removeAllListeners(event); | ||
} | ||
} | ||
getBlockByNumber(tag) { | ||
post(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.send({ | ||
method: 'eth_getBlockByNumber', | ||
params: getBlockByNumber.buildParams(tag), | ||
}).then((res) => { | ||
return getBlockByNumber.parseResult(res); | ||
}); | ||
}); | ||
} | ||
getTransactionByHash(hash) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.send({ | ||
method: 'eth_getTransactionByHash', | ||
params: getTransactionByHash.buildParams(hash), | ||
}).then((res) => { | ||
return getTransactionByHash.parseResult(res); | ||
}); | ||
}); | ||
} | ||
mutateContract(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
options = Object.assign({ from: this.accountId }, options); | ||
return this.send({ | ||
method: 'eth_sendTransaction', | ||
params: mutateContract.buildParams(options), | ||
}).then((res) => { | ||
return mutateContract.parseResult(res); | ||
}).then((id) => { | ||
return new mutation_1.Mutation(this, id); | ||
}); | ||
}); | ||
} | ||
queryContract(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.send({ | ||
method: 'eth_call', | ||
params: queryContract.buildParams(options), | ||
}).then((res) => { | ||
return queryContract.parseResult(options, res); | ||
}); | ||
}); | ||
} | ||
sign(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
options = Object.assign({ from: this.accountId, signMethod: this.signMethod }, options); | ||
return this.send({ | ||
method: 'eth_sign', | ||
params: sign.buildParams(options), | ||
}).then((res) => { | ||
return sign.parseResult(options, res); | ||
}); | ||
}); | ||
} | ||
send(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const requestIndex = this.getUniqueRequestIndex(); | ||
const requestIndex = options.id || this.getNextId(); | ||
return new Promise((resolve, reject) => { | ||
this.client.send(Object.assign({ jsonrpc: '2.0', id: requestIndex }, options), (err, res) => { | ||
this.$client.send(Object.assign({ jsonrpc: '2.0', id: requestIndex }, options), (err, res) => { | ||
if (err) { | ||
@@ -127,5 +45,5 @@ return reject(err); | ||
} | ||
getUniqueRequestIndex() { | ||
this.requestIndex++; | ||
return this.requestIndex; | ||
getNextId() { | ||
this.$id++; | ||
return this.$id; | ||
} | ||
@@ -132,0 +50,0 @@ } |
@@ -6,6 +6,2 @@ export declare enum SignMethod { | ||
} | ||
export declare enum ProviderEvent { | ||
NETWORK_CHANGE = "networkChanged", | ||
ACCOUNT_CHANGE = "accountsChanged" | ||
} | ||
export declare enum MutationEvent { | ||
@@ -21,33 +17,2 @@ RESOLVE = "resolve", | ||
} | ||
export interface BlockObject { | ||
number: number; | ||
hash: string; | ||
nonce: number; | ||
timestamp: number; | ||
} | ||
export interface TransactionObject { | ||
blockHash: string; | ||
blockNumber: number; | ||
from: string; | ||
hash: string; | ||
nonce: number; | ||
to: string; | ||
transactionIndex: number; | ||
} | ||
export interface ContractMutationOptions { | ||
to: string; | ||
abi: { | ||
[key: string]: any; | ||
}; | ||
data: any; | ||
from?: string; | ||
} | ||
export interface ContractQueryOptions { | ||
to: string; | ||
abi: { | ||
[key: string]: any; | ||
}; | ||
tag: QuantityTag; | ||
data?: any; | ||
} | ||
export interface SendOptions { | ||
@@ -59,7 +24,1 @@ method: string; | ||
} | ||
export interface SignOptions { | ||
message: string; | ||
from?: string; | ||
signMethod?: SignMethod; | ||
} | ||
export declare type QuantityTag = 'earliest' | 'pending' | 'latest' | number; |
@@ -9,7 +9,2 @@ "use strict"; | ||
})(SignMethod = exports.SignMethod || (exports.SignMethod = {})); | ||
var ProviderEvent; | ||
(function (ProviderEvent) { | ||
ProviderEvent["NETWORK_CHANGE"] = "networkChanged"; | ||
ProviderEvent["ACCOUNT_CHANGE"] = "accountsChanged"; | ||
})(ProviderEvent = exports.ProviderEvent || (exports.ProviderEvent = {})); | ||
var MutationEvent; | ||
@@ -16,0 +11,0 @@ (function (MutationEvent) { |
@@ -13,3 +13,3 @@ "use strict"; | ||
const ethereum_sandbox_1 = require("@0xcert/ethereum-sandbox"); | ||
const errors_1 = require("@0xcert/scaffold/dist/core/errors"); | ||
const scaffold_1 = require("@0xcert/scaffold"); | ||
const __1 = require("../../.."); | ||
@@ -48,3 +48,3 @@ const spec = new spec_1.Spec(); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.ZERO_ADDRESS); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.ZERO_ADDRESS); | ||
}); | ||
@@ -54,3 +54,3 @@ yield erc721Metadata.instance.methods.balanceOf(zeroAddress).call() | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.ZERO_ADDRESS); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.ZERO_ADDRESS); | ||
}); | ||
@@ -60,3 +60,3 @@ yield erc721Enumerable.instance.methods.balanceOf(zeroAddress).call() | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.ZERO_ADDRESS); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.ZERO_ADDRESS); | ||
}); | ||
@@ -73,3 +73,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.INVALID_NFT); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.INVALID_NFT); | ||
}); | ||
@@ -79,3 +79,3 @@ yield erc721Metadata.instance.methods.ownerOf('2').call() | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.INVALID_NFT); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.INVALID_NFT); | ||
}); | ||
@@ -85,3 +85,3 @@ yield erc721Enumerable.instance.methods.ownerOf('2').call() | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.INVALID_NFT); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.INVALID_NFT); | ||
}); | ||
@@ -92,3 +92,3 @@ yield mutableXcert.instance.methods.updateTokenProof('1', '0x973124ffc4a03e66d6a4458e587d5d6146f71fc57f359c8d516e0b12a50ab0d9') | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.INVALID_NFT); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.INVALID_NFT); | ||
}); | ||
@@ -108,3 +108,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -114,3 +114,3 @@ yield erc721Metadata.instance.methods.approve(bob, '2').call({ from: owner }) | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -120,3 +120,3 @@ yield erc721Enumerable.instance.methods.approve(bob, '2').call({ from: owner }) | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -126,3 +126,3 @@ yield erc721.instance.methods.transferFrom(jane, bob, '123').call({ from: bob }) | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -132,3 +132,3 @@ yield erc721Metadata.instance.methods.transferFrom(jane, bob, '123').call({ from: bob }) | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -138,3 +138,3 @@ yield erc721Enumerable.instance.methods.transferFrom(jane, bob, '123').call({ from: bob }) | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -144,3 +144,3 @@ yield burnableXcert.instance.methods.burn('123').call({ from: bob }) | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -150,3 +150,3 @@ yield xcert.instance.methods.assignAbilities(bob, [0]).call({ from: bob }) | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -162,3 +162,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.GENERAL_REVERT); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.GENERAL_REVERT); | ||
}); | ||
@@ -168,3 +168,3 @@ yield erc721Metadata.instance.methods.safeTransferFrom(jane, erc721.instance._address, '123').call({ from: jane }) | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.GENERAL_REVERT); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.GENERAL_REVERT); | ||
}); | ||
@@ -174,3 +174,3 @@ yield erc721Enumerable.instance.methods.safeTransferFrom(jane, erc721.instance._address, '123').call({ from: jane }) | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.GENERAL_REVERT); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.GENERAL_REVERT); | ||
}); | ||
@@ -187,3 +187,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.NFT_ALREADY_EXISTS); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.NFT_ALREADY_EXISTS); | ||
}); | ||
@@ -193,3 +193,3 @@ yield erc721Metadata.instance.methods.mint(bob, '123').call({ from: owner }) | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.NFT_ALREADY_EXISTS); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.NFT_ALREADY_EXISTS); | ||
}); | ||
@@ -199,3 +199,3 @@ yield erc721Enumerable.instance.methods.mint(bob, '123').call({ from: owner }) | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.NFT_ALREADY_EXISTS); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.NFT_ALREADY_EXISTS); | ||
}); | ||
@@ -209,3 +209,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.INVALID_INDEX); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.INVALID_INDEX); | ||
}); | ||
@@ -215,3 +215,3 @@ yield erc721Enumerable.instance.methods.tokenOfOwnerByIndex(owner, 2).call() | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.INVALID_INDEX); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.INVALID_INDEX); | ||
}); | ||
@@ -227,3 +227,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.TRANSFERS_PAUSED); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.TRANSFERS_PAUSED); | ||
}); | ||
@@ -244,3 +244,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.GENERAL_REVERT); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.GENERAL_REVERT); | ||
}); | ||
@@ -284,3 +284,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.INVALID_PROXY); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.INVALID_PROXY); | ||
}); | ||
@@ -326,3 +326,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.YOU_ARE_NOT_THE_TAKER); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.YOU_ARE_NOT_THE_TAKER); | ||
}); | ||
@@ -367,3 +367,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.SENDER_NOT_TAKER_OR_MAKER); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.SENDER_NOT_TAKER_OR_MAKER); | ||
}); | ||
@@ -408,3 +408,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.ORDER_EXPIRED); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.ORDER_EXPIRED); | ||
}); | ||
@@ -451,3 +451,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.INVALID_SIGNATURE); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.INVALID_SIGNATURE); | ||
}); | ||
@@ -493,3 +493,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.ORDER_CANCELED); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.ORDER_CANCELED); | ||
}); | ||
@@ -535,3 +535,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.ORDER_CANNOT_BE_PERFORMED_TWICE); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.ORDER_CANNOT_BE_PERFORMED_TWICE); | ||
}); | ||
@@ -565,3 +565,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.YOU_ARE_NOT_THE_MAKER); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.YOU_ARE_NOT_THE_MAKER); | ||
}); | ||
@@ -604,3 +604,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.SIGNER_NOT_AUTHORIZED); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.SIGNER_NOT_AUTHORIZED); | ||
}); | ||
@@ -614,3 +614,3 @@ })); | ||
.catch((e) => { | ||
ctx.is(__1.parseError(e).issue, errors_1.GenericProviderIssue.ONE_ZERO_ABILITY_HAS_TO_EXIST); | ||
ctx.is(__1.parseError(e).issue, scaffold_1.ProviderIssue.ONE_ZERO_ABILITY_HAS_TO_EXIST); | ||
}); | ||
@@ -617,0 +617,0 @@ })); |
@@ -32,6 +32,8 @@ "use strict"; | ||
const provider = ctx.get('provider'); | ||
const coinbase = ctx.get('coinbase'); | ||
const bob = ctx.get('bob'); | ||
const counters = { confirm: 0, resolve: 0 }; | ||
const { transactionHash } = yield ctx.web3.eth.sendTransaction({ | ||
from: ctx.get('coinbase'), | ||
to: ctx.get('bob'), | ||
from: coinbase, | ||
to: bob, | ||
value: 100000, | ||
@@ -44,7 +46,9 @@ }); | ||
ctx.is(mutation.id, transactionHash); | ||
ctx.is(mutation.senderId, coinbase.toLowerCase()); | ||
ctx.is(mutation.receiverId, bob.toLowerCase()); | ||
ctx.is(counters.confirm, 1); | ||
ctx.true(mutation.confirmations >= 25); | ||
ctx.true(counters.confirm >= 1); | ||
ctx.true(mutation.confirmations >= 25); | ||
})); | ||
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": "2168ef27a10fbbaecf3c15c67ebf9e5ca03d562e", | ||
"packages/0xcert-ethereum-generic-provider/src/core/errors.ts": "a7c91c3cdc15b8b906b00879550d1c31ddd9ec91", | ||
"packages/0xcert-ethereum-generic-provider/src/core/mutation.ts": "96870fb038ab29fb09653dbb264ce4c14d30c754", | ||
"packages/0xcert-ethereum-generic-provider/src/core/provider.ts": "10393bab9af50fef3f47a29365ed59964efbb2c6", | ||
"packages/0xcert-ethereum-generic-provider/src/core/types.ts": "fc1def4dc650ef7d8b598f1602ae51a3ab43f209", | ||
"packages/0xcert-ethereum-generic-provider/package.json": "37586298ea324269e62417ef3df49c4384b8e200", | ||
"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/types.ts": "02bd82e1d363f2c4e0e11ac1317a6f548d84220c", | ||
"packages/0xcert-ethereum-generic-provider/src/index.ts": "a4b6262ea7cb45960084814850cb98a8717b05e8", | ||
"packages/0xcert-ethereum-generic-provider/src/procedures/get-block-by-number.ts": "225a1352040f4837d3a55d7a9b5277c81f5d6fad", | ||
"packages/0xcert-ethereum-generic-provider/src/procedures/get-transaction-by-hash.ts": "f0e27c895585aeaeda2279575017987165bb6975", | ||
"packages/0xcert-ethereum-generic-provider/src/procedures/mutate-contract.ts": "b4fc171d98ffb3b47f30ea75fb6f47a049bcbbbc", | ||
"packages/0xcert-ethereum-generic-provider/src/procedures/query-contract.ts": "0fa6b0b29145ff69c746d6cf7a3cf1e8792f7b10", | ||
"packages/0xcert-ethereum-generic-provider/src/procedures/sign.ts": "1ca193eb92b22da781c4a22ec31cedc2adbc66bf", | ||
"packages/0xcert-ethereum-generic-provider/src/tests/core/errors/errors.test.ts": "6b42a2d0c8f852d9a51e014c5d25ce133523040b", | ||
"packages/0xcert-ethereum-generic-provider/src/tests/core/mutation/resolve-instance-method.test.ts": "6bbdea02d72f8b9a61bbbbb5b9a78defb27519bd", | ||
"packages/0xcert-ethereum-generic-provider/src/tests/core/provider/get-block-by-number-instance-method.test.ts": "3277c0d7c7e678fb5e337cd9aa1d545a93957d4a", | ||
"packages/0xcert-ethereum-generic-provider/src/tests/core/provider/get-transaction-by-hash-instance-method.test.ts": "98b6d2974413d553eb899b5fd2327378a0fb0ad1", | ||
"packages/0xcert-ethereum-generic-provider/src/tests/core/provider/mutate-contract-instance-method.test.ts": "54c1625b8f48843d30c57afb0696b00e9aa4309d", | ||
"packages/0xcert-ethereum-generic-provider/src/tests/core/provider/query-contract-instance-method.test.ts": "de3b1e437b1580e8ada19cf5e18c5633394a73e6", | ||
"packages/0xcert-ethereum-generic-provider/src/tests/core/provider/sign-instance-method.test.ts": "8a5da359cb327afbc11d5f50254f77dbda2673b6", | ||
"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/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": "9dea1ec1c34d5bcf4df825f8250513472c8f14f2" | ||
"common/config/rush/npm-shrinkwrap.json": "85e9a2392b6dc8ee32e79467374e9a32d2631090" | ||
}, | ||
"arguments": "npx specron test " | ||
"arguments": "npm run clean; npx tsc " | ||
} |
{ | ||
"name": "@0xcert/ethereum-generic-provider", | ||
"version": "0.0.0-alpha3", | ||
"version": "0.0.0-alpha4", | ||
"description": "Ethereum ledger for 0xcert protocol.", | ||
@@ -26,3 +26,3 @@ "main": "./dist/index.js", | ||
"devDependencies": { | ||
"@0xcert/ethereum-sandbox": "0.0.0-alpha3", | ||
"@0xcert/ethereum-sandbox": "0.0.0-alpha4", | ||
"@types/node": "^10.12.10", | ||
@@ -37,6 +37,5 @@ "@specron/cli": "^0.3.0", | ||
"dependencies": { | ||
"@0xcert/scaffold": "0.0.0-alpha3", | ||
"@0xcert/utils": "0.0.0-alpha3", | ||
"web3-eth-abi": "^1.0.0-beta.36" | ||
"@0xcert/ethereum-utils": "0.0.0-alpha4", | ||
"@0xcert/scaffold": "0.0.0-alpha4" | ||
} | ||
} |
@@ -1,134 +0,116 @@ | ||
import { GenericProviderError, GenericProviderIssue } from '@0xcert/scaffold'; | ||
import { ProviderError, ProviderIssue } from '@0xcert/scaffold'; | ||
/** | ||
* Converts web3 error into uified GenericProviderError. | ||
* Converts web3 error into uified ProviderError. | ||
* @param error Error object. | ||
*/ | ||
export function parseError(error: any) { | ||
if (error instanceof GenericProviderError) { | ||
if (error instanceof ProviderError) { | ||
return error; | ||
} | ||
else { | ||
const stringError = String(error); | ||
// contract(revert) errors | ||
if(stringError.indexOf('revert') > 0) | ||
{ | ||
if(stringError.indexOf('003001') > 0 | ||
|| stringError.indexOf('004001') > 0 | ||
|| stringError.indexOf('005001') > 0 | ||
|| stringError.indexOf('006001') > 0 | ||
|| stringError.indexOf('018002') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.ZERO_ADDRESS, error); | ||
} | ||
if(stringError.indexOf('003002') > 0 | ||
|| stringError.indexOf('004002') > 0 | ||
|| stringError.indexOf('005002') > 0 | ||
|| stringError.indexOf('006002') > 0 | ||
|| stringError.indexOf('010001') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.INVALID_NFT, error); | ||
} | ||
if(stringError.indexOf('003003') > 0 | ||
|| stringError.indexOf('003004') > 0 | ||
|| stringError.indexOf('004003') > 0 | ||
|| stringError.indexOf('004004') > 0 | ||
|| stringError.indexOf('005003') > 0 | ||
|| stringError.indexOf('005004') > 0 | ||
|| stringError.indexOf('006003') > 0 | ||
|| stringError.indexOf('006004') > 0 | ||
|| stringError.indexOf('008001') > 0 | ||
|| stringError.indexOf('017001') > 0 | ||
|| stringError.indexOf('018001') > 0 | ||
|| stringError.indexOf('019001') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.NOT_AUTHORIZED, error); | ||
} | ||
if(stringError.indexOf('003005') > 0 | ||
|| stringError.indexOf('004005') > 0 | ||
|| stringError.indexOf('005005') > 0 | ||
|| stringError.indexOf('006005') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.RECEIVER_DOES_NOT_SUPPORT_NFT, error); | ||
} | ||
if(stringError.indexOf('003006') > 0 | ||
|| stringError.indexOf('004006') > 0 | ||
|| stringError.indexOf('005006') > 0 | ||
|| stringError.indexOf('006006') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.NFT_ALREADY_EXISTS, error); | ||
} | ||
if(stringError.indexOf('005007') > 0 | ||
|| stringError.indexOf('006007') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.INVALID_INDEX, error); | ||
} | ||
if(stringError.indexOf('009001') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.TRANSFERS_PAUSED, error); | ||
} | ||
if(stringError.indexOf('012001') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.COIN_TRANSFER_FAILED, error); | ||
} | ||
if(stringError.indexOf('015001') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.INVALID_SIGNATURE_KIND, error); | ||
} | ||
if(stringError.indexOf('015002') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.INVALID_PROXY, error); | ||
} | ||
if(stringError.indexOf('015003') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.YOU_ARE_NOT_THE_TAKER, error); | ||
} | ||
if(stringError.indexOf('015004') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.SENDER_NOT_TAKER_OR_MAKER, error); | ||
} | ||
if(stringError.indexOf('015005') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.ORDER_EXPIRED, error); | ||
} | ||
if(stringError.indexOf('015006') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.INVALID_SIGNATURE, error); | ||
} | ||
if(stringError.indexOf('015007') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.ORDER_CANCELED, error); | ||
} | ||
if(stringError.indexOf('015008') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.ORDER_CANNOT_BE_PERFORMED_TWICE, error); | ||
} | ||
if(stringError.indexOf('015009') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.YOU_ARE_NOT_THE_MAKER, error); | ||
} | ||
if(stringError.indexOf('015010') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.SIGNER_NOT_AUTHORIZED, error); | ||
} | ||
if(stringError.indexOf('017002') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.ONE_ZERO_ABILITY_HAS_TO_EXIST, error); | ||
} | ||
return new GenericProviderError(GenericProviderIssue.GENERAL_REVERT, error); | ||
const stringError = String(error); | ||
// contract(revert) errors | ||
if (stringError.indexOf('revert') > 0) { | ||
if (stringError.indexOf('003001') > 0 | ||
|| stringError.indexOf('004001') > 0 | ||
|| stringError.indexOf('005001') > 0 | ||
|| stringError.indexOf('006001') > 0 | ||
|| stringError.indexOf('018002') > 0) { | ||
return new ProviderError(ProviderIssue.ZERO_ADDRESS, error); | ||
} | ||
// node errors | ||
if(stringError.indexOf('Transaction was not mined within') > 0 | ||
|| stringError.indexOf('Invalid JSON RPC response') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.TRANSATION_RESPONSE_ERROR_CHECK_PENDING_TRANSACTIONS, error); | ||
else if (stringError.indexOf('003002') > 0 | ||
|| stringError.indexOf('004002') > 0 | ||
|| stringError.indexOf('005002') > 0 | ||
|| stringError.indexOf('006002') > 0 | ||
|| stringError.indexOf('010001') > 0) { | ||
return new ProviderError(ProviderIssue.INVALID_NFT, error); | ||
} | ||
if(stringError.indexOf('invalid address') > 0 | ||
|| stringError.indexOf('is invalid, the capitalization checksum test failed, or its an indrect IBAN address which') > 0 | ||
|| stringError.indexOf('Provided address is not a valid addres') > 0) | ||
{ | ||
return new GenericProviderError(GenericProviderIssue.INVALID_ADDRESS, error); | ||
else if (stringError.indexOf('003003') > 0 | ||
|| stringError.indexOf('003004') > 0 | ||
|| stringError.indexOf('004003') > 0 | ||
|| stringError.indexOf('004004') > 0 | ||
|| stringError.indexOf('005003') > 0 | ||
|| stringError.indexOf('005004') > 0 | ||
|| stringError.indexOf('006003') > 0 | ||
|| stringError.indexOf('006004') > 0 | ||
|| stringError.indexOf('008001') > 0 | ||
|| stringError.indexOf('017001') > 0 | ||
|| stringError.indexOf('018001') > 0 | ||
|| stringError.indexOf('019001') > 0) { | ||
return new ProviderError(ProviderIssue.NOT_AUTHORIZED, error); | ||
} | ||
return new GenericProviderError(GenericProviderIssue.UNHANDLED, error); | ||
else if (stringError.indexOf('003005') > 0 | ||
|| stringError.indexOf('004005') > 0 | ||
|| stringError.indexOf('005005') > 0 | ||
|| stringError.indexOf('006005') > 0) { | ||
return new ProviderError(ProviderIssue.RECEIVER_DOES_NOT_SUPPORT_NFT, error); | ||
} | ||
else if (stringError.indexOf('003006') > 0 | ||
|| stringError.indexOf('004006') > 0 | ||
|| stringError.indexOf('005006') > 0 | ||
|| stringError.indexOf('006006') > 0) { | ||
return new ProviderError(ProviderIssue.NFT_ALREADY_EXISTS, error); | ||
} | ||
else if (stringError.indexOf('005007') > 0 | ||
|| stringError.indexOf('006007') > 0) { | ||
return new ProviderError(ProviderIssue.INVALID_INDEX, error); | ||
} | ||
else if (stringError.indexOf('009001') > 0) { | ||
return new ProviderError(ProviderIssue.TRANSFERS_PAUSED, error); | ||
} | ||
else if (stringError.indexOf('012001') > 0) { | ||
return new ProviderError(ProviderIssue.COIN_TRANSFER_FAILED, error); | ||
} | ||
else if (stringError.indexOf('015001') > 0) { | ||
return new ProviderError(ProviderIssue.INVALID_SIGNATURE_KIND, error); | ||
} | ||
else if (stringError.indexOf('015002') > 0) { | ||
return new ProviderError(ProviderIssue.INVALID_PROXY, error); | ||
} | ||
else if (stringError.indexOf('015003') > 0) { | ||
return new ProviderError(ProviderIssue.YOU_ARE_NOT_THE_TAKER, error); | ||
} | ||
else if (stringError.indexOf('015004') > 0) { | ||
return new ProviderError(ProviderIssue.SENDER_NOT_TAKER_OR_MAKER, error); | ||
} | ||
else if (stringError.indexOf('015005') > 0) { | ||
return new ProviderError(ProviderIssue.ORDER_EXPIRED, error); | ||
} | ||
else if (stringError.indexOf('015006') > 0) { | ||
return new ProviderError(ProviderIssue.INVALID_SIGNATURE, error); | ||
} | ||
else if (stringError.indexOf('015007') > 0) { | ||
return new ProviderError(ProviderIssue.ORDER_CANCELED, error); | ||
} | ||
else if (stringError.indexOf('015008') > 0) { | ||
return new ProviderError(ProviderIssue.ORDER_CANNOT_BE_PERFORMED_TWICE, error); | ||
} | ||
else if (stringError.indexOf('015009') > 0) { | ||
return new ProviderError(ProviderIssue.YOU_ARE_NOT_THE_MAKER, error); | ||
} | ||
else if (stringError.indexOf('015010') > 0) { | ||
return new ProviderError(ProviderIssue.SIGNER_NOT_AUTHORIZED, error); | ||
} | ||
else if (stringError.indexOf('017002') > 0) { | ||
return new ProviderError(ProviderIssue.ONE_ZERO_ABILITY_HAS_TO_EXIST, error); | ||
} | ||
else { | ||
return new ProviderError(ProviderIssue.GENERAL_REVERT, error); | ||
} | ||
} | ||
// node errors | ||
else if (stringError.indexOf('Transaction was not mined within') > 0 | ||
|| stringError.indexOf('Invalid JSON RPC response') > 0) { | ||
return new ProviderError(ProviderIssue.TRANSATION_RESPONSE_ERROR_CHECK_PENDING_TRANSACTIONS, error); | ||
} | ||
else if (stringError.indexOf('invalid address') > 0 | ||
|| stringError.indexOf('is invalid, the capitalization checksum test failed, or its an indrect IBAN address which') > 0 | ||
|| stringError.indexOf('Provided address is not a valid addres') > 0) { | ||
return new ProviderError(ProviderIssue.INVALID_ADDRESS, error); | ||
} | ||
else { | ||
return new ProviderError(ProviderIssue.UNHANDLED, error); | ||
} | ||
} |
import { EventEmitter } from 'events'; | ||
import { MutationBase } from '@0xcert/scaffold'; | ||
import { normalizeAddress } from '@0xcert/ethereum-utils/dist/lib/normalize-address'; | ||
import { MutationEvent } from './types'; | ||
@@ -7,8 +9,10 @@ | ||
*/ | ||
export class Mutation extends EventEmitter { | ||
public id: string; | ||
public confirmations: number = 0; | ||
protected provider: any; | ||
protected timer: any = null; | ||
protected done: boolean = false; | ||
export class Mutation extends EventEmitter implements MutationBase { | ||
protected $id: string; | ||
protected $confirmations: number = 0; | ||
protected $senderId: string; | ||
protected $receiverId: string; | ||
protected $provider: any; | ||
protected $timer: any = null; | ||
protected $done: boolean = false; | ||
@@ -21,9 +25,44 @@ /** | ||
this.provider = provider; | ||
this.id = id; | ||
this.$id = normalizeAddress(id); | ||
this.$provider = provider; | ||
} | ||
/** | ||
/** | ||
* | ||
*/ | ||
public get id() { | ||
return this.$id; | ||
} | ||
/** | ||
* | ||
*/ | ||
public get provider() { | ||
return this.$provider; | ||
} | ||
/** | ||
* | ||
*/ | ||
public get confirmations() { | ||
return this.$confirmations; | ||
} | ||
/** | ||
* | ||
*/ | ||
public get senderId() { | ||
return this.$senderId; | ||
} | ||
/** | ||
* | ||
*/ | ||
public get receiverId() { | ||
return this.$receiverId; | ||
} | ||
/** | ||
* | ||
*/ | ||
public emit(event: MutationEvent.CONFIRM, mutation: Mutation); | ||
@@ -72,3 +111,3 @@ public emit(event: MutationEvent.RESOLVE, mutation: Mutation); | ||
public async resolve() { | ||
if (this.done) { | ||
if (this.$done) { | ||
return this; | ||
@@ -88,4 +127,4 @@ } | ||
public forget() { | ||
if (this.timer) { | ||
clearTimeout(this.timer); | ||
if (this.$timer) { | ||
clearTimeout(this.$timer); | ||
} | ||
@@ -100,15 +139,16 @@ | ||
protected async loopUntilResolved() { | ||
const tx = await this.provider.getTransactionByHash(this.id); | ||
const tx = await this.getTransactionObject(); | ||
if (!tx) { | ||
return this.emit(MutationEvent.ERROR, new Error('Mutation not found (1)')); | ||
} | ||
else if (!tx.to) { | ||
tx.to = await this.getTransactionReceipt().then((r) => r.contractAddress); | ||
} | ||
const block = await this.provider.getBlockByNumber('latest'); | ||
if (!block) { | ||
return this.emit(MutationEvent.ERROR, new Error('Mutation not found (2)')); | ||
} | ||
this.confirmations = block.number - tx.blockNumber; | ||
this.$senderId = normalizeAddress(tx.from); | ||
this.$receiverId = normalizeAddress(tx.to); | ||
this.$confirmations = await this.getLastBlock().then((lastBlock) => lastBlock - parseInt(tx.blockNumber)); | ||
if (this.confirmations >= 25) { | ||
this.done = true; | ||
this.$done = true; | ||
this.emit(MutationEvent.RESOLVE, this); | ||
@@ -118,6 +158,38 @@ } | ||
this.emit(MutationEvent.CONFIRM, this); | ||
this.timer = setTimeout(this.loopUntilResolved.bind(this), 14000); | ||
this.$timer = setTimeout(this.loopUntilResolved.bind(this), 14000); | ||
} | ||
} | ||
/** | ||
* | ||
*/ | ||
protected async getTransactionObject() { | ||
const res = await this.$provider.post({ | ||
method: 'eth_getTransactionByHash', | ||
params: this.id, | ||
}); | ||
return res.result; | ||
} | ||
/** | ||
* | ||
*/ | ||
protected async getTransactionReceipt() { | ||
const res = await this.$provider.post({ | ||
method: 'eth_getTransactionReceipt', | ||
params: this.id, | ||
}); | ||
return res.result; | ||
} | ||
/** | ||
* | ||
*/ | ||
protected async getLastBlock() { | ||
const res = await this.$provider.post({ | ||
method: 'eth_blockNumber', | ||
}); | ||
return parseInt(res.result); | ||
} | ||
} |
@@ -1,12 +0,3 @@ | ||
import { EventEmitter } from "events"; | ||
import * as getBlockByNumber from '../procedures/get-block-by-number'; | ||
import * as getTransactionByHash from '../procedures/get-transaction-by-hash'; | ||
import * as mutateContract from '../procedures/mutate-contract'; | ||
import * as queryContract from '../procedures/query-contract'; | ||
import * as sign from '../procedures/sign'; | ||
import { TransactionObject, BlockObject, RpcResponse, QuantityTag, | ||
ContractQueryOptions, ContractMutationOptions, SendOptions, SignOptions, | ||
SignMethod, ProviderEvent } from './types'; | ||
import { RpcResponse, SendOptions, SignMethod } from './types'; | ||
import { parseError } from './errors'; | ||
import { Mutation } from './mutation'; | ||
@@ -18,4 +9,5 @@ /** | ||
accountId?: string; | ||
client: any; | ||
client?: any; | ||
signMethod?: SignMethod; | ||
unsafeRecipientIds?: string[]; | ||
} | ||
@@ -26,7 +18,8 @@ | ||
*/ | ||
export class GenericProvider extends EventEmitter { | ||
protected client: any; | ||
protected requestIndex: number = 0; | ||
export class GenericProvider { | ||
public accountId: string; | ||
public signMethod: SignMethod; | ||
public unsafeRecipientIds: string[]; | ||
protected $client: any; | ||
protected $id: number = 0; | ||
@@ -39,138 +32,12 @@ /** | ||
public constructor(options: GenericProviderOptions) { | ||
super(); | ||
this.accountId = options.accountId; | ||
this.signMethod = options.signMethod || SignMethod.ETH_SIGN; | ||
this.unsafeRecipientIds = options.unsafeRecipientIds || []; | ||
this.client = options.client && options.client.currentProvider | ||
this.$client = options.client && options.client.currentProvider | ||
? options.client.currentProvider | ||
: options.client; | ||
if (this.client) { | ||
this.client.on(ProviderEvent.NETWORK_CHANGE, () => this.emit(ProviderEvent.NETWORK_CHANGE)); | ||
this.client.on(ProviderEvent.ACCOUNT_CHANGE, () => this.emit(ProviderEvent.ACCOUNT_CHANGE)); | ||
} | ||
} | ||
/** | ||
* | ||
*/ | ||
public emit(event: ProviderEvent) { | ||
return super.emit(event); | ||
} | ||
/** | ||
* | ||
*/ | ||
public on(event: ProviderEvent, handler: () => any) { | ||
return super.on(event, handler); | ||
} | ||
/** | ||
* | ||
*/ | ||
public once(event: ProviderEvent, handler: () => any) { | ||
return super.once(event, handler); | ||
} | ||
/** | ||
* | ||
*/ | ||
public off(event: ProviderEvent, handler?: () => any) { | ||
if (handler) { | ||
return super.off(event, handler); | ||
} | ||
else { | ||
return super.removeAllListeners(event); | ||
} | ||
} | ||
/** | ||
* Returns block information. | ||
* @param tag Block number or tag. | ||
* @see https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblockbynumber | ||
*/ | ||
public async getBlockByNumber(tag: QuantityTag): Promise<BlockObject> { | ||
return this.send({ | ||
method: 'eth_getBlockByNumber', | ||
params: getBlockByNumber.buildParams(tag), | ||
}).then((res) => { | ||
return getBlockByNumber.parseResult(res); | ||
}); | ||
} | ||
/** | ||
* Returns transaction information. | ||
* @param hash Transaction hash. | ||
* @see https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyhash | ||
*/ | ||
public async getTransactionByHash(hash: string): Promise<TransactionObject> { | ||
return this.send({ | ||
method: 'eth_getTransactionByHash', | ||
params: getTransactionByHash.buildParams(hash), | ||
}).then((res) => { | ||
return getTransactionByHash.parseResult(res); | ||
}); | ||
} | ||
/** | ||
* Performs a mutation operation on a smart contract. | ||
* @param options.from Sender's wallet address. | ||
* @param options.to Contract address. | ||
* @param options.abi Contract method ABI. | ||
* @param options.tag Block number or tag. | ||
* @see https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendtransaction | ||
*/ | ||
public async mutateContract(options: ContractMutationOptions): Promise<Mutation> { | ||
options = { | ||
from: this.accountId, | ||
...options, | ||
}; | ||
return this.send({ | ||
method: 'eth_sendTransaction', | ||
params: mutateContract.buildParams(options), | ||
}).then((res) => { | ||
return mutateContract.parseResult(res); | ||
}).then((id) => { | ||
return new Mutation(this, id); | ||
}); | ||
} | ||
/** | ||
* Performs a query operation on a smart contract. | ||
* @param options.to Contract address. | ||
* @param options.abi Contract method ABI. | ||
* @param options.tag Block number or tag. | ||
* @see https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_call | ||
*/ | ||
public async queryContract<T=any[]>(options: ContractQueryOptions): Promise<T> { | ||
return this.send({ | ||
method: 'eth_call', | ||
params: queryContract.buildParams(options), | ||
}).then((res) => { | ||
return queryContract.parseResult(options, res); | ||
}); | ||
} | ||
/** | ||
* Signs a message. | ||
* @param options.from Signer's wallet address. | ||
* @param options.message Text tobe signed. | ||
* @see https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign | ||
*/ | ||
public async sign(options: SignOptions): Promise<string> { | ||
options = { | ||
from: this.accountId, | ||
signMethod: this.signMethod, | ||
...options, | ||
}; | ||
return this.send({ | ||
method: 'eth_sign', | ||
params: sign.buildParams(options), | ||
}).then((res) => { | ||
return sign.parseResult(options, res); | ||
}); | ||
} | ||
/** | ||
* Sends a raw RPC request through the provider. | ||
@@ -183,7 +50,7 @@ * @param options.method RPC procedure name. | ||
*/ | ||
protected async send(options: SendOptions): Promise<RpcResponse> { | ||
const requestIndex = this.getUniqueRequestIndex(); | ||
public async post(options: SendOptions): Promise<RpcResponse> { | ||
const requestIndex = options.id || this.getNextId(); | ||
return new Promise<RpcResponse>((resolve, reject) => { | ||
this.client.send({ | ||
this.$client.send({ | ||
jsonrpc: '2.0', | ||
@@ -212,7 +79,7 @@ id: requestIndex, | ||
*/ | ||
protected getUniqueRequestIndex() { | ||
this.requestIndex++; | ||
return this.requestIndex; | ||
protected getNextId() { | ||
this.$id++; | ||
return this.$id; | ||
} | ||
} |
@@ -13,10 +13,2 @@ /** | ||
*/ | ||
export enum ProviderEvent { | ||
NETWORK_CHANGE = 'networkChanged', | ||
ACCOUNT_CHANGE = 'accountsChanged', | ||
} | ||
/** | ||
* | ||
*/ | ||
export enum MutationEvent { | ||
@@ -40,45 +32,2 @@ RESOLVE = 'resolve', | ||
*/ | ||
export interface BlockObject { | ||
number: number; | ||
hash: string; | ||
nonce: number; | ||
timestamp: number; | ||
} | ||
/** | ||
* | ||
*/ | ||
export interface TransactionObject { | ||
blockHash: string; | ||
blockNumber: number; | ||
from: string; | ||
hash: string; | ||
nonce: number | ||
to: string; | ||
transactionIndex: number; | ||
} | ||
/** | ||
* | ||
*/ | ||
export interface ContractMutationOptions { | ||
to: string; | ||
abi: {[key: string]: any}; | ||
data: any; | ||
from?: string; | ||
} | ||
/** | ||
* | ||
*/ | ||
export interface ContractQueryOptions { | ||
to: string; | ||
abi: {[key: string]: any}; | ||
tag: QuantityTag; | ||
data?: any; | ||
} | ||
/** | ||
* | ||
*/ | ||
export interface SendOptions { | ||
@@ -90,15 +39,1 @@ method: string; | ||
} | ||
/** | ||
* | ||
*/ | ||
export interface SignOptions { | ||
message: string; | ||
from?: string; | ||
signMethod?: SignMethod; | ||
} | ||
/** | ||
* | ||
*/ | ||
export type QuantityTag = 'earliest' | 'pending' | 'latest' | number; |
import { Spec } from '@specron/spec'; | ||
import { Protocol } from '@0xcert/ethereum-sandbox'; | ||
import { GenericProviderIssue } from '@0xcert/scaffold/dist/core/errors'; | ||
import { ProviderIssue } from '@0xcert/scaffold'; | ||
import { parseError } from '../../..'; | ||
@@ -50,3 +50,3 @@ | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.ZERO_ADDRESS); | ||
ctx.is(parseError(e).issue, ProviderIssue.ZERO_ADDRESS); | ||
}); | ||
@@ -56,3 +56,3 @@ await erc721Metadata.instance.methods.balanceOf(zeroAddress).call() | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.ZERO_ADDRESS); | ||
ctx.is(parseError(e).issue, ProviderIssue.ZERO_ADDRESS); | ||
}); | ||
@@ -62,3 +62,3 @@ await erc721Enumerable.instance.methods.balanceOf(zeroAddress).call() | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.ZERO_ADDRESS); | ||
ctx.is(parseError(e).issue, ProviderIssue.ZERO_ADDRESS); | ||
}); | ||
@@ -76,3 +76,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.INVALID_NFT); | ||
ctx.is(parseError(e).issue, ProviderIssue.INVALID_NFT); | ||
}); | ||
@@ -82,3 +82,3 @@ await erc721Metadata.instance.methods.ownerOf('2').call() | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.INVALID_NFT); | ||
ctx.is(parseError(e).issue, ProviderIssue.INVALID_NFT); | ||
}); | ||
@@ -88,3 +88,3 @@ await erc721Enumerable.instance.methods.ownerOf('2').call() | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.INVALID_NFT); | ||
ctx.is(parseError(e).issue, ProviderIssue.INVALID_NFT); | ||
}); | ||
@@ -95,3 +95,3 @@ await mutableXcert.instance.methods.updateTokenProof('1','0x973124ffc4a03e66d6a4458e587d5d6146f71fc57f359c8d516e0b12a50ab0d9') | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.INVALID_NFT); | ||
ctx.is(parseError(e).issue, ProviderIssue.INVALID_NFT); | ||
}); | ||
@@ -113,3 +113,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(parseError(e).issue, ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -119,3 +119,3 @@ await erc721Metadata.instance.methods.approve(bob, '2').call({ from: owner }) | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(parseError(e).issue, ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -125,3 +125,3 @@ await erc721Enumerable.instance.methods.approve(bob, '2').call({ from: owner }) | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(parseError(e).issue, ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -131,3 +131,3 @@ await erc721.instance.methods.transferFrom(jane, bob, '123').call({ from: bob }) | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(parseError(e).issue, ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -137,3 +137,3 @@ await erc721Metadata.instance.methods.transferFrom(jane, bob, '123').call({ from: bob }) | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(parseError(e).issue, ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -143,3 +143,3 @@ await erc721Enumerable.instance.methods.transferFrom(jane, bob, '123').call({ from: bob }) | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(parseError(e).issue, ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -149,3 +149,3 @@ await burnableXcert.instance.methods.burn('123').call({ from: bob }) | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(parseError(e).issue, ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -155,3 +155,3 @@ await xcert.instance.methods.assignAbilities(bob, [0]).call({from: bob}) | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.NOT_AUTHORIZED); | ||
ctx.is(parseError(e).issue, ProviderIssue.NOT_AUTHORIZED); | ||
}); | ||
@@ -170,3 +170,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.GENERAL_REVERT); | ||
ctx.is(parseError(e).issue, ProviderIssue.GENERAL_REVERT); | ||
}); | ||
@@ -176,3 +176,3 @@ await erc721Metadata.instance.methods.safeTransferFrom(jane, erc721.instance._address, '123').call({ from: jane }) | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.GENERAL_REVERT); | ||
ctx.is(parseError(e).issue, ProviderIssue.GENERAL_REVERT); | ||
}); | ||
@@ -182,3 +182,3 @@ await erc721Enumerable.instance.methods.safeTransferFrom(jane, erc721.instance._address, '123').call({ from: jane }) | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.GENERAL_REVERT); | ||
ctx.is(parseError(e).issue, ProviderIssue.GENERAL_REVERT); | ||
}); | ||
@@ -196,3 +196,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.NFT_ALREADY_EXISTS); | ||
ctx.is(parseError(e).issue, ProviderIssue.NFT_ALREADY_EXISTS); | ||
}); | ||
@@ -202,3 +202,3 @@ await erc721Metadata.instance.methods.mint(bob, '123').call({ from: owner }) | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.NFT_ALREADY_EXISTS); | ||
ctx.is(parseError(e).issue, ProviderIssue.NFT_ALREADY_EXISTS); | ||
}); | ||
@@ -208,3 +208,3 @@ await erc721Enumerable.instance.methods.mint(bob, '123').call({ from: owner }) | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.NFT_ALREADY_EXISTS); | ||
ctx.is(parseError(e).issue, ProviderIssue.NFT_ALREADY_EXISTS); | ||
}); | ||
@@ -219,3 +219,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.INVALID_INDEX); | ||
ctx.is(parseError(e).issue, ProviderIssue.INVALID_INDEX); | ||
}); | ||
@@ -225,3 +225,3 @@ await erc721Enumerable.instance.methods.tokenOfOwnerByIndex(owner, 2).call() | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.INVALID_INDEX); | ||
ctx.is(parseError(e).issue, ProviderIssue.INVALID_INDEX); | ||
}); | ||
@@ -238,3 +238,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.TRANSFERS_PAUSED); | ||
ctx.is(parseError(e).issue, ProviderIssue.TRANSFERS_PAUSED); | ||
}); | ||
@@ -258,3 +258,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.GENERAL_REVERT); // INVALID_SIGNATURE_KIND | ||
ctx.is(parseError(e).issue, ProviderIssue.GENERAL_REVERT); // INVALID_SIGNATURE_KIND | ||
}); | ||
@@ -304,3 +304,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.INVALID_PROXY); | ||
ctx.is(parseError(e).issue, ProviderIssue.INVALID_PROXY); | ||
}); | ||
@@ -353,3 +353,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.YOU_ARE_NOT_THE_TAKER); | ||
ctx.is(parseError(e).issue, ProviderIssue.YOU_ARE_NOT_THE_TAKER); | ||
}); | ||
@@ -400,3 +400,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.SENDER_NOT_TAKER_OR_MAKER); | ||
ctx.is(parseError(e).issue, ProviderIssue.SENDER_NOT_TAKER_OR_MAKER); | ||
}); | ||
@@ -446,3 +446,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.ORDER_EXPIRED); | ||
ctx.is(parseError(e).issue, ProviderIssue.ORDER_EXPIRED); | ||
}); | ||
@@ -494,3 +494,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.INVALID_SIGNATURE); | ||
ctx.is(parseError(e).issue, ProviderIssue.INVALID_SIGNATURE); | ||
}); | ||
@@ -540,3 +540,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.ORDER_CANCELED); | ||
ctx.is(parseError(e).issue, ProviderIssue.ORDER_CANCELED); | ||
}); | ||
@@ -586,3 +586,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.ORDER_CANNOT_BE_PERFORMED_TWICE); | ||
ctx.is(parseError(e).issue, ProviderIssue.ORDER_CANNOT_BE_PERFORMED_TWICE); | ||
}); | ||
@@ -620,3 +620,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.YOU_ARE_NOT_THE_MAKER); | ||
ctx.is(parseError(e).issue, ProviderIssue.YOU_ARE_NOT_THE_MAKER); | ||
}); | ||
@@ -663,3 +663,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.SIGNER_NOT_AUTHORIZED); | ||
ctx.is(parseError(e).issue, ProviderIssue.SIGNER_NOT_AUTHORIZED); | ||
}); | ||
@@ -675,3 +675,3 @@ }); | ||
.catch((e) => { | ||
ctx.is(parseError(e).issue, GenericProviderIssue.ONE_ZERO_ABILITY_HAS_TO_EXIST); | ||
ctx.is(parseError(e).issue, ProviderIssue.ONE_ZERO_ABILITY_HAS_TO_EXIST); | ||
}); | ||
@@ -678,0 +678,0 @@ }); |
@@ -37,7 +37,9 @@ import { Spec } from '@specron/spec'; | ||
const provider = ctx.get('provider'); | ||
const coinbase = ctx.get('coinbase'); | ||
const bob = ctx.get('bob'); | ||
const counters = { confirm: 0, resolve: 0 }; | ||
const { transactionHash } = await ctx.web3.eth.sendTransaction({ | ||
from: ctx.get('coinbase'), | ||
to: ctx.get('bob'), | ||
from: coinbase, | ||
to: bob, | ||
value: 100000, | ||
@@ -52,7 +54,9 @@ }); | ||
ctx.is(mutation.id, transactionHash); | ||
ctx.is(mutation.senderId, coinbase.toLowerCase()); | ||
ctx.is(mutation.receiverId, bob.toLowerCase()); | ||
ctx.is(counters.confirm, 1); | ||
ctx.true(mutation.confirmations >= 25); | ||
ctx.true(counters.confirm >= 1); | ||
ctx.true(mutation.confirmations >= 25); | ||
}); | ||
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2
127335
42
2164
+ Added@0xcert/ethereum-utils@0.0.0-alpha4(transitive)
+ Added@0xcert/scaffold@0.0.0-alpha4(transitive)
- Removed@0xcert/utils@0.0.0-alpha3
- Removedweb3-eth-abi@^1.0.0-beta.36
- Removed@0xcert/scaffold@0.0.0-alpha3(transitive)
- Removed@0xcert/utils@0.0.0-alpha3(transitive)