Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

web3-core-method

Package Overview
Dependencies
Maintainers
2
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-core-method - npm Package Compare versions

Comparing version 1.0.0-beta.51 to 1.0.0-beta.52

197

dist/web3-core-method.esm.js
import EventEmitter from 'eventemitter3';
import { NewHeadsSubscription } from 'web3-core-subscriptions';
import isFunction from 'lodash/isFunction';
import isString from 'lodash/isString';
import cloneDeep from 'lodash/cloneDeep';
import { Observable } from 'rxjs';
import isFunction from 'lodash/isFunction';

@@ -95,4 +95,4 @@ class PromiEvent {

}
setArguments(args) {
let parameters = cloneDeep([...args]);
setArguments(methodArguments) {
let parameters = cloneDeep([...methodArguments]);
let callback = null;

@@ -170,3 +170,3 @@ if (parameters.length > this.parametersAmount) {

return Observable.create(observer => {
if (this.isSocketBasedProvider()) {
if (this.provider.supportsSubscriptions()) {
this.startSocketObserver(transactionHash, observer);

@@ -263,4 +263,4 @@ } else {

}
getBlockByNumber(blockHash) {
this.getBlockByNumberMethod.parameters = [blockHash];
getBlockByNumber(blockNumber) {
this.getBlockByNumberMethod.parameters = [blockNumber];
return this.getBlockByNumberMethod.execute();

@@ -277,11 +277,2 @@ }

}
isSocketBasedProvider() {
switch (this.provider.constructor.name) {
case 'CustomProvider':
case 'HttpProvider':
return false;
default:
return true;
}
}
increaseBlockNumber(blockNumber) {

@@ -309,69 +300,2 @@ return '0x' + (parseInt(blockNumber, 16) + 1).toString(16);

class AbstractObservedTransactionMethod extends AbstractMethod {
constructor(rpcMethod, parametersAmount, utils, formatters, moduleInstance, transactionObserver) {
super(rpcMethod, parametersAmount, utils, formatters, moduleInstance);
this.transactionObserver = transactionObserver;
this.promiEvent = new PromiEvent();
}
static get Type() {
return 'observed-transaction-method';
}
execute() {
this.beforeExecution(this.moduleInstance);
this.moduleInstance.currentProvider.send(this.rpcMethod, this.parameters).then(transactionHash => {
let confirmations, receipt;
if (this.callback) {
this.callback(false, transactionHash);
return;
}
this.promiEvent.emit('transactionHash', transactionHash);
const transactionConfirmationSubscription = this.transactionObserver.observe(transactionHash).subscribe(transactionConfirmation => {
confirmations = transactionConfirmation.confirmations;
receipt = transactionConfirmation.receipt;
if (!receipt.status) {
if (this.parameters[0].gas === receipt.gasUsed) {
this.handleError(new Error(`Transaction ran out of gas. Please provide more gas:\n${JSON.stringify(receipt, null, 2)}`), receipt, confirmations);
transactionConfirmationSubscription.unsubscribe();
return;
}
this.handleError(new Error(`Transaction has been reverted by the EVM:\n${JSON.stringify(receipt, null, 2)}`), receipt, confirmations);
transactionConfirmationSubscription.unsubscribe();
return;
}
this.promiEvent.emit('confirmation', confirmations, this.afterExecution(receipt));
}, error => {
this.handleError(error, receipt, confirmations);
}, () => {
if (this.promiEvent.listenerCount('receipt') > 0) {
this.promiEvent.emit('receipt', this.afterExecution(receipt));
this.promiEvent.removeAllListeners();
return;
}
this.promiEvent.resolve(this.afterExecution(receipt));
});
}).catch(error => {
if (this.callback) {
this.callback(error, null);
return;
}
this.handleError(error, false, 0);
});
return this.promiEvent;
}
handleError(error, receipt, confirmations) {
if (this.promiEvent.listenerCount('error') > 0) {
this.promiEvent.emit('error', error, receipt, confirmations);
this.promiEvent.removeAllListeners();
return;
}
this.promiEvent.reject(error);
}
}
class SendRawTransactionMethod extends AbstractObservedTransactionMethod {
constructor(utils, formatters, moduleInstance, transactionObserver) {
super('eth_sendRawTransaction', 1, utils, formatters, moduleInstance, transactionObserver);
}
}
class ChainIdMethod extends AbstractMethod {

@@ -410,4 +334,3 @@ constructor(utils, formatters, moduleInstance) {

if (method.Type === 'eth-send-transaction-method') {
const transactionObserver = this.createTransactionObserver(moduleInstance);
return new method(this.utils, this.formatters, moduleInstance, transactionObserver, new ChainIdMethod(this.utils, this.formatters, moduleInstance), new GetTransactionCountMethod(this.utils, this.formatters, moduleInstance), new SendRawTransactionMethod(this.utils, this.formatters, moduleInstance, transactionObserver));
return new method(this.utils, this.formatters, moduleInstance, this.createTransactionObserver(moduleInstance), new ChainIdMethod(this.utils, this.formatters, moduleInstance), new GetTransactionCountMethod(this.utils, this.formatters, moduleInstance));
}

@@ -418,3 +341,3 @@ return new method(this.utils, this.formatters, moduleInstance);

let timeout = moduleInstance.transactionBlockTimeout;
if (!moduleInstance.currentProvider.SOCKET_MESSAGE) {
if (!moduleInstance.currentProvider.supportsSubscriptions()) {
timeout = moduleInstance.transactionPollingTimeout;

@@ -438,12 +361,12 @@ }

const method = methodFactory.createMethod(name, target);
function anonymousFunction() {
function RpcMethod() {
method.setArguments(arguments);
return method.execute();
}
anonymousFunction.method = method;
anonymousFunction.request = function () {
RpcMethod.method = method;
RpcMethod.request = function () {
method.setArguments(arguments);
return method;
};
return anonymousFunction;
return RpcMethod;
}

@@ -460,2 +383,5 @@ return target[name];

}
afterExecution(response) {
return this.utils.hexToNumber(response);
}
}

@@ -682,2 +608,63 @@

class AbstractObservedTransactionMethod extends AbstractMethod {
constructor(rpcMethod, parametersAmount, utils, formatters, moduleInstance, transactionObserver) {
super(rpcMethod, parametersAmount, utils, formatters, moduleInstance);
this.transactionObserver = transactionObserver;
this.promiEvent = new PromiEvent();
}
static get Type() {
return 'observed-transaction-method';
}
execute() {
this.beforeExecution(this.moduleInstance);
this.moduleInstance.currentProvider.send(this.rpcMethod, this.parameters).then(transactionHash => {
let confirmations, receipt;
if (this.callback) {
this.callback(false, transactionHash);
return;
}
this.promiEvent.emit('transactionHash', transactionHash);
const transactionConfirmationSubscription = this.transactionObserver.observe(transactionHash).subscribe(transactionConfirmation => {
confirmations = transactionConfirmation.confirmations;
receipt = transactionConfirmation.receipt;
if (!receipt.status) {
if (this.parameters[0].gas === receipt.gasUsed) {
this.handleError(new Error(`Transaction ran out of gas. Please provide more gas:\n${JSON.stringify(receipt, null, 2)}`), receipt, confirmations);
transactionConfirmationSubscription.unsubscribe();
return;
}
this.handleError(new Error(`Transaction has been reverted by the EVM:\n${JSON.stringify(receipt, null, 2)}`), receipt, confirmations);
transactionConfirmationSubscription.unsubscribe();
return;
}
this.promiEvent.emit('confirmation', confirmations, this.afterExecution(receipt));
}, error => {
this.handleError(error, receipt, confirmations);
}, () => {
if (this.promiEvent.listenerCount('receipt') > 0) {
this.promiEvent.emit('receipt', this.afterExecution(receipt));
this.promiEvent.removeAllListeners();
return;
}
this.promiEvent.resolve(this.afterExecution(receipt));
});
}).catch(error => {
if (this.callback) {
this.callback(error, null);
return;
}
this.handleError(error, false, 0);
});
return this.promiEvent;
}
handleError(error, receipt, confirmations) {
if (this.promiEvent.listenerCount('error') > 0) {
this.promiEvent.emit('error', error, receipt, confirmations);
this.promiEvent.removeAllListeners();
return;
}
this.promiEvent.reject(error);
}
}
class SendTransactionMethod extends AbstractObservedTransactionMethod {

@@ -693,7 +680,6 @@ constructor(utils, formatters, moduleInstance, transactionObserver) {

class EthSendTransactionMethod extends SendTransactionMethod {
constructor(utils, formatters, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod) {
constructor(utils, formatters, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod) {
super(utils, formatters, moduleInstance, transactionObserver);
this.chainIdMethod = chainIdMethod;
this.getTransactionCountMethod = getTransactionCountMethod;
this.sendRawTransactionMethod = sendRawTransactionMethod;
}

@@ -703,2 +689,7 @@ static get Type() {

}
beforeExecution(moduleInstance) {
if (this.rpcMethod !== 'eth_sendRawTransaction') {
super.beforeExecution(moduleInstance);
}
}
execute() {

@@ -737,2 +728,3 @@ if (!this.parameters[0].gas && this.moduleInstance.defaultGas) {

async sendRawTransaction(privateKey = null) {
this.beforeExecution(this.moduleInstance);
if (!this.parameters[0].chainId) {

@@ -742,6 +734,6 @@ this.parameters[0].chainId = await this.chainIdMethod.execute();

if (!this.parameters[0].nonce && this.parameters[0].nonce !== 0) {
this.getTransactionCountMethod.parameters = [this.parameters[0].from];
this.getTransactionCountMethod.parameters = [this.parameters[0].from, 'latest'];
this.parameters[0].nonce = await this.getTransactionCountMethod.execute();
}
let transaction = this.formatters.inputCallFormatter(this.parameters[0], this.moduleInstance);
let transaction = this.parameters[0];
transaction.to = transaction.to || '0x';

@@ -753,9 +745,8 @@ transaction.data = transaction.data || '0x';

const response = await this.moduleInstance.transactionSigner.sign(transaction, privateKey);
this.sendRawTransactionMethod.parameters = [response.rawTransaction];
this.sendRawTransactionMethod.callback = this.callback;
this.sendRawTransactionMethod.promiEvent = this.promiEvent;
return this.sendRawTransactionMethod.execute();
this.parameters = [response.rawTransaction];
this.rpcMethod = 'eth_sendRawTransaction';
return super.execute();
}
isDefaultSigner() {
return this.moduleInstance.transactionSigner.constructor.name === 'TransactionSigner';
return this.moduleInstance.transactionSigner.type === 'TransactionSigner';
}

@@ -766,3 +757,3 @@ hasAccounts() {

hasCustomSigner() {
return this.moduleInstance.transactionSigner.constructor.name !== 'TransactionSigner';
return this.moduleInstance.transactionSigner.type !== 'TransactionSigner';
}

@@ -792,2 +783,8 @@ }

class SendRawTransactionMethod extends AbstractObservedTransactionMethod {
constructor(utils, formatters, moduleInstance, transactionObserver) {
super('eth_sendRawTransaction', 1, utils, formatters, moduleInstance, transactionObserver);
}
}
class SignTransactionMethod extends AbstractMethod {

@@ -1093,2 +1090,2 @@ constructor(utils, formatters, moduleInstance) {

export { PromiEvent, AbstractMethodFactory, AbstractMethod, MethodProxy, TransactionObserver, GetProtocolVersionMethod, VersionMethod, ListeningMethod, PeerCountMethod, ChainIdMethod, GetNodeInfoMethod, GetCoinbaseMethod, IsMiningMethod, GetHashrateMethod, IsSyncingMethod, GetGasPriceMethod, SubmitWorkMethod, GetWorkMethod, GetAccountsMethod, GetBalanceMethod, GetTransactionCountMethod, RequestAccountsMethod, AbstractGetBlockMethod, AbstractGetUncleMethod, AbstractGetBlockTransactionCountMethod, AbstractGetBlockUncleCountMethod, GetBlockByHashMethod, GetBlockByNumberMethod, GetBlockNumberMethod, GetBlockTransactionCountByHashMethod, GetBlockTransactionCountByNumberMethod, GetBlockUncleCountByBlockHashMethod, GetBlockUncleCountByBlockNumberMethod, GetUncleByBlockHashAndIndexMethod, GetUncleByBlockNumberAndIndexMethod, AbstractGetTransactionFromBlockMethod, AbstractObservedTransactionMethod, EthSendTransactionMethod, GetTransactionMethod, GetTransactionByBlockHashAndIndexMethod, GetTransactionByBlockNumberAndIndexMethod, GetTransactionReceiptMethod, SendRawTransactionMethod, SignTransactionMethod, SendTransactionMethod, GetCodeMethod, SignMethod, CallMethod, GetStorageAtMethod, EstimateGasMethod, GetPastLogsMethod, EcRecoverMethod, ImportRawKeyMethod, ListAccountsMethod, LockAccountMethod, NewAccountMethod, PersonalSendTransactionMethod, PersonalSignMethod, PersonalSignTransactionMethod, UnlockAccountMethod, AddPrivateKeyMethod, AddSymKeyMethod, DeleteKeyPairMethod, DeleteMessageFilterMethod, DeleteSymKeyMethod, GenerateSymKeyFromPasswordMethod, GetFilterMessagesMethod, GetInfoMethod, GetPrivateKeyMethod, GetPublicKeyMethod, GetSymKeyMethod, HasKeyPairMethod, HasSymKeyMethod, MarkTrustedPeerMethod, NewKeyPairMethod, NewMessageFilterMethod, NewSymKeyMethod, PostMethod, SetMaxMessageSizeMethod, SetMinPoWMethod, ShhVersionMethod };
export { AbstractGetBlockMethod, AbstractGetBlockTransactionCountMethod, AbstractGetBlockUncleCountMethod, AbstractGetTransactionFromBlockMethod, AbstractGetUncleMethod, AbstractMethod, AbstractMethodFactory, AbstractObservedTransactionMethod, AddPrivateKeyMethod, AddSymKeyMethod, CallMethod, ChainIdMethod, DeleteKeyPairMethod, DeleteMessageFilterMethod, DeleteSymKeyMethod, EcRecoverMethod, EstimateGasMethod, EthSendTransactionMethod, GenerateSymKeyFromPasswordMethod, GetAccountsMethod, GetBalanceMethod, GetBlockByHashMethod, GetBlockByNumberMethod, GetBlockNumberMethod, GetBlockTransactionCountByHashMethod, GetBlockTransactionCountByNumberMethod, GetBlockUncleCountByBlockHashMethod, GetBlockUncleCountByBlockNumberMethod, GetCodeMethod, GetCoinbaseMethod, GetFilterMessagesMethod, GetGasPriceMethod, GetHashrateMethod, GetInfoMethod, GetNodeInfoMethod, GetPastLogsMethod, GetPrivateKeyMethod, GetProtocolVersionMethod, GetPublicKeyMethod, GetStorageAtMethod, GetSymKeyMethod, GetTransactionByBlockHashAndIndexMethod, GetTransactionByBlockNumberAndIndexMethod, GetTransactionCountMethod, GetTransactionMethod, GetTransactionReceiptMethod, GetUncleByBlockHashAndIndexMethod, GetUncleByBlockNumberAndIndexMethod, GetWorkMethod, HasKeyPairMethod, HasSymKeyMethod, ImportRawKeyMethod, IsMiningMethod, IsSyncingMethod, ListAccountsMethod, ListeningMethod, LockAccountMethod, MarkTrustedPeerMethod, MethodProxy, NewAccountMethod, NewKeyPairMethod, NewMessageFilterMethod, NewSymKeyMethod, PeerCountMethod, PersonalSendTransactionMethod, PersonalSignMethod, PersonalSignTransactionMethod, PostMethod, PromiEvent, RequestAccountsMethod, SendRawTransactionMethod, SendTransactionMethod, SetMaxMessageSizeMethod, SetMinPoWMethod, ShhVersionMethod, SignMethod, SignTransactionMethod, SubmitWorkMethod, TransactionObserver, UnlockAccountMethod, VersionMethod };
{
"name": "web3-core-method",
"namespace": "ethereum",
"version": "1.0.0-beta.51",
"version": "1.0.0-beta.52",
"description": "Handles the JSON-RPC methods. This package is also internally used by web3.",

@@ -18,3 +18,3 @@ "repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-core-method",

},
"types": "types",
"types": "types/index.d.ts",
"dependencies": {

@@ -29,7 +29,7 @@ "@babel/runtime": "^7.3.1",

"rxjs": "^6.4.0",
"web3-core": "1.0.0-beta.51",
"web3-core-helpers": "1.0.0-beta.51",
"web3-core-subscriptions": "1.0.0-beta.51",
"web3-providers": "1.0.0-beta.51",
"web3-utils": "1.0.0-beta.51"
"web3-core": "1.0.0-beta.52",
"web3-core-helpers": "1.0.0-beta.52",
"web3-core-subscriptions": "1.0.0-beta.52",
"web3-providers": "1.0.0-beta.52",
"web3-utils": "1.0.0-beta.52"
},

@@ -40,3 +40,3 @@ "files": [

],
"gitHead": "67468b3f923d85839fc06ff4eedbe553ba60c185"
"gitHead": "1c89f503c90180598910d29892f6ebf92455cfe1"
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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