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

@harmony-js/network

Package Overview
Dependencies
Maintainers
3
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harmony-js/network - npm Package Compare versions

Comparing version 0.1.43 to 0.1.45

5

dist/index.d.ts

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
* @ignore
*/
import mitt from 'mitt';

@@ -2,0 +7,0 @@ export { mitt };

"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @ignore
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.mitt = void 0;
var tslib_1 = require("tslib");

@@ -4,0 +10,0 @@ var mitt_1 = tslib_1.__importDefault(require("mitt"));

55

dist/messenger/messenger.d.ts

@@ -0,1 +1,5 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { HarmonyCore, ChainType, ChainID } from '@harmony-js/utils';

@@ -7,2 +11,3 @@ import { JsonRpc } from '../rpcMethod/builder';

import { SubscribeReturns } from '../types';
/** @hidden */
export interface ShardingProvider {

@@ -15,7 +20,15 @@ current: boolean;

/**
* @class Messenger
* @description Messenger instance
* @param {HttpProvider} provider HttpProvider
* @param {Object} config config object
* @return {Messenger} Messenger instance
* ## How to Create a Massage
* @example
* ```
* const { HttpProvider, Messenger } = require('@harmony-js/network');
* const { ChainType, ChainID } = require('@harmony-js/utils');
*
* // create a custom messenger
* const customMessenger = new Messenger(
* new HttpProvider('http://localhost:9500'),
* ChainType.Harmony, // if you are connected to Harmony's blockchain
* ChainID.HmyLocal, // check if the chainId is correct
* )
* ```
*/

@@ -30,3 +43,15 @@ declare class Messenger extends HarmonyCore {

constructor(provider: HttpProvider | WSProvider, chainType?: ChainType, chainId?: ChainID, config?: object);
/**
* @example
* ```
* customMessenger.currentShard
* ```
*/
get currentShard(): number;
/**
* @example
* ```
* customMessenger.shardCount
* ```
*/
get shardCount(): number;

@@ -40,3 +65,3 @@ /**

*/
send: (method: string, params?: string | any[] | undefined, rpcPrefix?: string | undefined, shardID?: number) => Promise<any>;
send: (method: RPCMethod | string, params?: string | any[] | undefined, rpcPrefix?: string | undefined, shardID?: number) => Promise<any>;
/**

@@ -62,2 +87,3 @@ * @function setProvider

* @param {String} method - method name
* @hidden
*/

@@ -71,2 +97,3 @@ setReqMiddleware(middleware: any, method: string | undefined, provider: HttpProvider | WSProvider): void;

* @param {String} method - method name
* @hidden
*/

@@ -82,6 +109,18 @@ setResMiddleware(middleware: any, method: string | undefined, provider: HttpProvider | WSProvider): void;

setRPCPrefix(method: RPCMethod | string, prefix: string): string;
subscribe: (method: string, params?: string | any[] | undefined, returnType?: SubscribeReturns, rpcPrefix?: string, shardID?: number) => Promise<any>;
unsubscribe: (method: string, params?: string | any[] | undefined, rpcPrefix?: string | undefined, shardID?: number) => Promise<any>;
subscribe: (method: RPCMethod | string, params?: string | any[] | undefined, returnType?: SubscribeReturns, rpcPrefix?: string, shardID?: number) => Promise<any>;
unsubscribe: (method: RPCMethod | string, params?: string | any[] | undefined, rpcPrefix?: string | undefined, shardID?: number) => Promise<any>;
setShardingProviders(): Promise<void>;
/**
* @example
* ```
* hmy.messenger.getShardProvider()
* ```
*/
getShardProvider(shardID: number): HttpProvider | WSProvider;
/**
* @example
* ```
* hmy.messenger.getCurrentShardID()
* ```
*/
getCurrentShardID(): number | undefined;

@@ -88,0 +127,0 @@ setDefaultShardID(shardID: number): void;

"use strict";
/**
* @packageDocumentation
* @module harmony-network
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Messenger = void 0;
var tslib_1 = require("tslib");

@@ -10,7 +15,15 @@ var utils_1 = require("@harmony-js/utils");

/**
* @class Messenger
* @description Messenger instance
* @param {HttpProvider} provider HttpProvider
* @param {Object} config config object
* @return {Messenger} Messenger instance
* ## How to Create a Massage
* @example
* ```
* const { HttpProvider, Messenger } = require('@harmony-js/network');
* const { ChainType, ChainID } = require('@harmony-js/utils');
*
* // create a custom messenger
* const customMessenger = new Messenger(
* new HttpProvider('http://localhost:9500'),
* ChainType.Harmony, // if you are connected to Harmony's blockchain
* ChainID.HmyLocal, // check if the chainId is correct
* )
* ```
*/

@@ -200,13 +213,25 @@ var Messenger = /** @class */ (function (_super) {

Object.defineProperty(Messenger.prototype, "currentShard", {
/**
* @example
* ```
* customMessenger.currentShard
* ```
*/
get: function () {
return this.getCurrentShardID() || this.defaultShardID || 0;
},
enumerable: true,
enumerable: false,
configurable: true
});
Object.defineProperty(Messenger.prototype, "shardCount", {
/**
* @example
* ```
* customMessenger.shardCount
* ```
*/
get: function () {
return this.shardProviders.size;
},
enumerable: true,
enumerable: false,
configurable: true

@@ -240,2 +265,3 @@ });

* @param {String} method - method name
* @hidden
*/

@@ -252,2 +278,3 @@ Messenger.prototype.setReqMiddleware = function (middleware, method, provider) {

* @param {String} method - method name
* @hidden
*/

@@ -322,2 +349,8 @@ Messenger.prototype.setResMiddleware = function (middleware, method, provider) {

};
/**
* @example
* ```
* hmy.messenger.getShardProvider()
* ```
*/
Messenger.prototype.getShardProvider = function (shardID) {

@@ -332,2 +365,8 @@ var provider = this.shardProviders.get(shardID);

};
/**
* @example
* ```
* hmy.messenger.getCurrentShardID()
* ```
*/
Messenger.prototype.getCurrentShardID = function () {

@@ -334,0 +373,0 @@ var e_3, _a;

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { RPCResponseBody } from '../types';

@@ -2,0 +7,0 @@ /**

21

dist/messenger/responseMiddleware.js
"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResponseMiddleware = void 0;
var tslib_1 = require("tslib");

@@ -20,6 +26,5 @@ var utils_1 = require("@harmony-js/utils");

get: function () {
return utils_1.isObject(this.result)
? tslib_1.__assign(tslib_1.__assign({}, this.result), { responseType: 'result' }) : this.result;
return utils_1.isObject(this.result) ? tslib_1.__assign(tslib_1.__assign({}, this.result), { responseType: 'result' }) : this.result;
},
enumerable: true,
enumerable: false,
configurable: true

@@ -29,6 +34,5 @@ });

get: function () {
return utils_1.isObject(this.error)
? tslib_1.__assign(tslib_1.__assign({}, this.error), { responseType: 'error' }) : this.error;
return utils_1.isObject(this.error) ? tslib_1.__assign(tslib_1.__assign({}, this.error), { responseType: 'error' }) : this.error;
},
enumerable: true,
enumerable: false,
configurable: true

@@ -40,3 +44,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -48,4 +52,3 @@ });

}
else if (this.result ||
(this.result === null && this.result !== undefined)) {
else if (this.result || (this.result === null && this.result !== undefined)) {
return 'result';

@@ -52,0 +55,0 @@ }

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { ReqMiddleware, ResMiddleware, MiddlewareType } from '../types';

@@ -6,6 +11,6 @@ import { RPCMethod } from '../rpcMethod/rpc';

request: {
use: (fn: ReqMiddleware, match?: string | RegExp) => void;
use: (fn: ReqMiddleware, match?: string | RPCMethod | RegExp) => void;
};
response: {
use: (fn: ResMiddleware, match?: string | RegExp) => void;
use: (fn: ResMiddleware, match?: string | RPCMethod | RegExp) => void;
};

@@ -12,0 +17,0 @@ };

"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseProvider = void 0;
var tslib_1 = require("tslib");

@@ -4,0 +10,0 @@ var BaseProvider = /** @class */ (function () {

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import mitt from 'mitt';

@@ -2,0 +7,0 @@ import { BaseProvider } from './baseProvider';

"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseSocket = exports.EmittType = exports.SocketState = exports.SocketConnection = void 0;
var tslib_1 = require("tslib");

@@ -4,0 +10,0 @@ var utils_1 = require("@harmony-js/utils");

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { RPCRequest, RPCError, RPCResult } from '../types';

@@ -2,0 +7,0 @@ export declare const fetchRPC: {

"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchRPC = void 0;
var tslib_1 = require("tslib");

@@ -8,5 +14,3 @@ var cross_fetch_1 = tslib_1.__importDefault(require("cross-fetch"));

return cross_fetch_1.default(request.url, {
method: request.options && request.options.method
? request.options.method
: 'POST',
method: request.options && request.options.method ? request.options.method : 'POST',
cache: 'no-cache',

@@ -17,5 +21,3 @@ mode: 'cors',

body: JSON.stringify(request.payload),
headers: tslib_1.__assign(tslib_1.__assign({}, headers), (request.options && request.options.headers
? request.options.headers
: {})),
headers: tslib_1.__assign(tslib_1.__assign({}, headers), (request.options && request.options.headers ? request.options.headers : {})),
});

@@ -22,0 +24,0 @@ },

@@ -0,1 +1,5 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import mitt from 'mitt';

@@ -2,0 +6,0 @@ declare class Emitter {

"use strict";
/**
* @packageDocumentation
* @module harmony-network
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Emitter = void 0;
var tslib_1 = require("tslib");

@@ -4,0 +9,0 @@ var mitt_1 = tslib_1.__importDefault(require("mitt"));

@@ -0,1 +1,5 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { BaseProvider } from './baseProvider';

@@ -2,0 +6,0 @@ import { RPCRequestPayload } from '../types';

"use strict";
/**
* @packageDocumentation
* @module harmony-network
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpProvider = void 0;
var tslib_1 = require("tslib");

@@ -7,2 +12,3 @@ var baseProvider_1 = require("./baseProvider");

var net_1 = require("../rpcMethod/net");
/** @hidden */
var defaultOptions = {

@@ -61,4 +67,3 @@ method: 'POST',

var reqMiddleware = net_1.composeMiddleware.apply(void 0, tslib_1.__spread(tReq, [function (obj) { return _this.optionsHandler(obj); },
function (obj) { return _this.endpointHandler(obj, endpoint); },
this.payloadHandler]));
function (obj) { return _this.endpointHandler(obj, endpoint); }, this.payloadHandler]));
var resMiddleware = net_1.composeMiddleware.apply(void 0, tslib_1.__spread([function (data) { return _this.callbackHandler(data, callback); }], tRes));

@@ -65,0 +70,0 @@ var req = reqMiddleware(payload);

@@ -0,1 +1,5 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { HttpProvider } from './http';

@@ -2,0 +6,0 @@ import { WSProvider } from './ws';

"use strict";
/**
* @packageDocumentation
* @module harmony-network
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Provider = exports.ProviderType = void 0;
var http_1 = require("./http");

@@ -4,0 +9,0 @@ var ws_1 = require("./ws");

@@ -0,1 +1,5 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { w3cwebsocket as W3CWebsocket } from 'websocket';

@@ -2,0 +6,0 @@ import { BaseSocket } from './baseSocket';

"use strict";
/**
* @packageDocumentation
* @module harmony-network
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.WSProvider = void 0;
var tslib_1 = require("tslib");

@@ -32,3 +37,3 @@ // TODO: implement Websocket Provider

},
enumerable: true,
enumerable: false,
configurable: true

@@ -35,0 +40,0 @@ });

@@ -0,2 +1,8 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { RPCRequestPayload } from '../types';
import { RPCMethod } from './rpc';
/**

@@ -18,5 +24,5 @@ * @class JsonRpc

*/
toPayload: (method: string, params: string | any[] | undefined) => RPCRequestPayload<any>;
toPayload: (method: RPCMethod | string, params: string | undefined | any[]) => RPCRequestPayload<any>;
}
export { JsonRpc };
//# sourceMappingURL=builder.d.ts.map
"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonRpc = void 0;
var tslib_1 = require("tslib");

@@ -27,7 +33,3 @@ /**

_this.messageId += 1;
var sendParams = params === undefined
? []
: typeof params === 'string'
? [params]
: tslib_1.__spread(params);
var sendParams = params === undefined ? [] : typeof params === 'string' ? [params] : tslib_1.__spread(params);
return {

@@ -34,0 +36,0 @@ jsonrpc: '2.0',

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
* @ignore
*/
export declare const DEFAULT_TIMEOUT: number;

@@ -2,0 +7,0 @@ export declare const DEFAULT_HEADERS: object;

"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @ignore
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.composeMiddleware = exports.performRPC = exports.DEFAULT_HEADERS = exports.DEFAULT_TIMEOUT = void 0;
var tslib_1 = require("tslib");

@@ -23,5 +29,3 @@ exports.DEFAULT_TIMEOUT = 120000;

_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, _fetch(fetcher.requestHandler(request, exports.DEFAULT_HEADERS), request.options && request.options.timeout
? request.options.timeout
: exports.DEFAULT_TIMEOUT)];
return [4 /*yield*/, _fetch(fetcher.requestHandler(request, exports.DEFAULT_HEADERS), request.options && request.options.timeout ? request.options.timeout : exports.DEFAULT_TIMEOUT)];
case 1:

@@ -28,0 +32,0 @@ response = _a.sent();

@@ -0,1 +1,25 @@

/**
* ## About this package
*
* `@harmony-js/network` provides functions to handle messenger, providers and subscriptions...
*
* ## How to use this package
*
* ### 1. Create a Message
* ```javascript
* const { HttpProvider, Messenger } = require('@harmony-js/network');
* const { ChainType, ChainID } = require('@harmony-js/utils');
*
* // create a custom messenger
* const customMessenger = new Messenger(
* new HttpProvider('http://localhost:9500'),
* ChainType.Harmony, // if you are connected to Harmony's blockchain
* ChainID.HmyLocal, // check if the chainId is correct
* )
* ```
*
* @packageDocumentation
* @module harmony-network
*/
/**@ignore */
export declare const enum RPCMethod {

@@ -37,2 +61,3 @@ GetBlockByHash = "hmy_getBlockByHash",

}
/**@ignore */
export declare const enum RPCErrorCode {

@@ -39,0 +64,0 @@ RPC_INVALID_REQUEST = -32600,

"use strict";
/**
* ## About this package
*
* `@harmony-js/network` provides functions to handle messenger, providers and subscriptions...
*
* ## How to use this package
*
* ### 1. Create a Message
* ```javascript
* const { HttpProvider, Messenger } = require('@harmony-js/network');
* const { ChainType, ChainID } = require('@harmony-js/utils');
*
* // create a custom messenger
* const customMessenger = new Messenger(
* new HttpProvider('http://localhost:9500'),
* ChainType.Harmony, // if you are connected to Harmony's blockchain
* ChainID.HmyLocal, // check if the chainId is correct
* )
* ```
*
* @packageDocumentation
* @module harmony-network
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.RPCErrorCode = exports.RPCMethod = void 0;
/**@ignore */
var RPCMethod;

@@ -74,2 +99,3 @@ (function (RPCMethod) {

})(RPCMethod = exports.RPCMethod || (exports.RPCMethod = {}));
/**@ignore */
var RPCErrorCode;

@@ -76,0 +102,0 @@ (function (RPCErrorCode) {

@@ -0,1 +1,5 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { Messenger } from '../messenger/messenger';

@@ -2,0 +6,0 @@ import { SubscriptionMethod } from './Subscription';

"use strict";
/**
* @packageDocumentation
* @module harmony-network
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.LogSub = void 0;
var tslib_1 = require("tslib");

@@ -21,3 +26,4 @@ var Subscription_1 = require("./Subscription");

if (!((this.options.fromBlock && this.options.fromBlock !== 'latest') ||
(this.options.fromBlock === 0 || this.options.fromBlock === '0x'))) return [3 /*break*/, 4];
this.options.fromBlock === 0 ||
this.options.fromBlock === '0x')) return [3 /*break*/, 4];
_a.label = 1;

@@ -32,7 +38,9 @@ case 1:

}
logs = getPastLogs.result;
logs.forEach(function (log) {
var formattedLog = _this.onNewSubscriptionItem(log);
_this.emitter.emit('data', formattedLog);
});
else {
logs = getPastLogs.result;
logs.forEach(function (log) {
var formattedLog = _this.onNewSubscriptionItem(log);
_this.emitter.emit('data', formattedLog);
});
}
delete this.options.fromBlock;

@@ -39,0 +47,0 @@ // const sub = this.start();

@@ -0,3 +1,11 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { Messenger } from '../messenger/messenger';
import { SubscriptionMethod } from './Subscription';
/**
* ### Description:
* Subscribes to incoming block headers. This can be used as timer to check for changes on the blockchain.
*/
export declare class NewHeaders extends SubscriptionMethod {

@@ -4,0 +12,0 @@ constructor(messenger: Messenger, shardID?: number);

"use strict";
/**
* @packageDocumentation
* @module harmony-network
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.NewHeaders = void 0;
var tslib_1 = require("tslib");
var Subscription_1 = require("./Subscription");
/**
* ### Description:
* Subscribes to incoming block headers. This can be used as timer to check for changes on the blockchain.
*/
var NewHeaders = /** @class */ (function (_super) {

@@ -6,0 +15,0 @@ tslib_1.__extends(NewHeaders, _super);

@@ -0,3 +1,11 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { Messenger } from '../messenger/messenger';
import { SubscriptionMethod } from './Subscription';
/**
* ### Description:
* Subscribes to incoming pending transactions
*/
export declare class NewPendingTransactions extends SubscriptionMethod {

@@ -4,0 +12,0 @@ constructor(messenger: Messenger, shardID?: number);

"use strict";
/**
* @packageDocumentation
* @module harmony-network
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.NewPendingTransactions = void 0;
var tslib_1 = require("tslib");
var Subscription_1 = require("./Subscription");
/**
* ### Description:
* Subscribes to incoming pending transactions
*/
var NewPendingTransactions = /** @class */ (function (_super) {

@@ -6,0 +15,0 @@ tslib_1.__extends(NewPendingTransactions, _super);

@@ -0,1 +1,5 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { Messenger } from '../messenger/messenger';

@@ -2,0 +6,0 @@ import { WSProvider } from '../providers/ws';

"use strict";
/**
* @packageDocumentation
* @module harmony-network
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubscriptionMethod = void 0;
var tslib_1 = require("tslib");

@@ -4,0 +9,0 @@ var ws_1 = require("../providers/ws");

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { Messenger } from '../messenger/messenger';

@@ -2,0 +7,0 @@ import { SubscriptionMethod } from './Subscription';

"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Syncing = void 0;
var tslib_1 = require("tslib");

@@ -4,0 +10,0 @@ var Subscription_1 = require("./Subscription");

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { Emitter } from '../providers/emitter';

@@ -2,0 +7,0 @@ export declare class BaseBlockTracker extends Emitter {

"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseBlockTracker = void 0;
var tslib_1 = require("tslib");

@@ -7,5 +13,3 @@ var utils_1 = require("@harmony-js/utils");

var sec = 1000;
var calculateSum = function (accumulator, currentValue) {
return accumulator + currentValue;
};
var calculateSum = function (accumulator, currentValue) { return accumulator + currentValue; };
var blockTrackerEvents = ['sync', 'latest'];

@@ -55,5 +59,3 @@ var BaseBlockTracker = /** @class */ (function (_super) {

}
return [4 /*yield*/, new Promise(function (resolve) {
return _this.once('latest', resolve);
})];
return [4 /*yield*/, new Promise(function (resolve) { return _this.once('latest', resolve); })];
case 1:

@@ -60,0 +62,0 @@ latestBlock = _a.sent();

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { BaseBlockTracker } from './baseTracker';

@@ -2,0 +7,0 @@ import { Messenger } from '../messenger/messenger';

"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.PollingBlockTracker = exports.timeout = void 0;
var tslib_1 = require("tslib");

@@ -4,0 +10,0 @@ var baseTracker_1 = require("./baseTracker");

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { Messenger } from '../messenger/messenger';

@@ -2,0 +7,0 @@ import { BaseBlockTracker } from './baseTracker';

"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubscribeBlockTracker = void 0;
var tslib_1 = require("tslib");

@@ -53,5 +59,3 @@ var ws_1 = require("../providers/ws");

if (!blockNumber.isResult()) return [3 /*break*/, 4];
return [4 /*yield*/, this.messenger.subscribe("hmy_subscribe" /* Subscribe */, [
'newHeads',
])];
return [4 /*yield*/, this.messenger.subscribe("hmy_subscribe" /* Subscribe */, ['newHeads'])];
case 3:

@@ -58,0 +62,0 @@ subs = _a.sent();

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
* @ignore
*/
import { RPCMethod, RPCErrorCode } from './rpcMethod/rpc';

@@ -2,0 +7,0 @@ export declare type ReqMiddleware = Map<string | RPCMethod | RegExp, any[]>;

"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @ignore
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubscribeReturns = exports.MiddlewareType = void 0;
var MiddlewareType;

@@ -4,0 +10,0 @@ (function (MiddlewareType) {

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { ResponseMiddleware } from './messenger/responseMiddleware';

@@ -2,0 +7,0 @@ /**

"use strict";
/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.onResponse = exports.getRawForData = exports.getResultForData = void 0;
/**

@@ -4,0 +10,0 @@ * @function getResultForData

{
"name": "@harmony-js/network",
"version": "0.1.43",
"version": "0.1.45",
"description": "network suites for harmony",

@@ -21,3 +21,3 @@ "main": "dist/index.js",

"dependencies": {
"@harmony-js/utils": "^0.1.43",
"@harmony-js/utils": "^0.1.45",
"cross-fetch": "^3.0.2",

@@ -27,3 +27,3 @@ "mitt": "^1.2.0",

},
"gitHead": "bdcfbf0f8050d96da22ed009da33465f7ad7671b"
"gitHead": "a35db780aea823fab8510da0881b22805d35648f"
}

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-network
* @ignore
*/
import mitt from 'mitt';

@@ -2,0 +8,0 @@ export { mitt };

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { HarmonyCore, ChainType, isString, ChainID, defaultConfig } from '@harmony-js/utils';

@@ -10,2 +15,3 @@ import { JsonRpc } from '../rpcMethod/builder';

/** @hidden */
export interface ShardingProvider {

@@ -19,7 +25,15 @@ current: boolean;

/**
* @class Messenger
* @description Messenger instance
* @param {HttpProvider} provider HttpProvider
* @param {Object} config config object
* @return {Messenger} Messenger instance
* ## How to Create a Massage
* @example
* ```
* const { HttpProvider, Messenger } = require('@harmony-js/network');
* const { ChainType, ChainID } = require('@harmony-js/utils');
*
* // create a custom messenger
* const customMessenger = new Messenger(
* new HttpProvider('http://localhost:9500'),
* ChainType.Harmony, // if you are connected to Harmony's blockchain
* ChainID.HmyLocal, // check if the chainId is correct
* )
* ```
*/

@@ -78,2 +92,9 @@ class Messenger extends HarmonyCore {

}
/**
* @example
* ```
* customMessenger.currentShard
* ```
*/
get currentShard(): number {

@@ -83,5 +104,12 @@ return this.getCurrentShardID() || this.defaultShardID || 0;

/**
* @example
* ```
* customMessenger.shardCount
* ```
*/
get shardCount(): number {
return this.shardProviders.size;
}
/**

@@ -158,2 +186,3 @@ * @function send

* @param {String} method - method name
* @hidden
*/

@@ -170,2 +199,3 @@ setReqMiddleware(middleware: any, method = '*', provider: HttpProvider | WSProvider) {

* @param {String} method - method name
* @hidden
*/

@@ -293,2 +323,9 @@ setResMiddleware(middleware: any, method = '*', provider: HttpProvider | WSProvider) {

}
/**
* @example
* ```
* hmy.messenger.getShardProvider()
* ```
*/
getShardProvider(shardID: number): HttpProvider | WSProvider {

@@ -303,2 +340,10 @@ const provider = this.shardProviders.get(shardID);

}
/**
* @example
* ```
* hmy.messenger.getCurrentShardID()
* ```
*/
getCurrentShardID() {

@@ -305,0 +350,0 @@ for (const shard of this.shardProviders) {

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { RPCResponseBody } from '../types';

@@ -22,11 +28,7 @@ import { isObject } from '@harmony-js/utils';

get getResult() {
return isObject(this.result)
? { ...this.result, responseType: 'result' }
: this.result;
return isObject(this.result) ? { ...this.result, responseType: 'result' } : this.result;
}
get getError() {
return isObject(this.error)
? { ...this.error, responseType: 'error' }
: this.error;
return isObject(this.error) ? { ...this.error, responseType: 'error' } : this.error;
}

@@ -41,6 +43,3 @@

return 'error';
} else if (
this.result ||
(this.result === null && this.result !== undefined)
) {
} else if (this.result || (this.result === null && this.result !== undefined)) {
return 'result';

@@ -47,0 +46,0 @@ } else {

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { ReqMiddleware, ResMiddleware, MiddlewareType } from '../types';

@@ -31,7 +37,3 @@ import { RPCMethod } from '../rpcMethod/rpc';

protected pushMiddleware(
fn: any,
type: MiddlewareType,
match: string | RPCMethod | RegExp,
) {
protected pushMiddleware(fn: any, type: MiddlewareType, match: string | RPCMethod | RegExp) {
if (type !== MiddlewareType.REQ && type !== MiddlewareType.RES) {

@@ -48,5 +50,3 @@ throw new Error('Please specify the type of middleware being added');

}
protected getMiddleware(
method: RPCMethod | string,
): [ReqMiddleware[], ResMiddleware[]] {
protected getMiddleware(method: RPCMethod | string): [ReqMiddleware[], ResMiddleware[]] {
const requests: ReqMiddleware[] = [];

@@ -53,0 +53,0 @@ const responses: ResMiddleware[] = [];

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { isWs } from '@harmony-js/utils';

@@ -2,0 +8,0 @@ import mitt from 'mitt';

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import fetch from 'cross-fetch';

@@ -7,6 +13,3 @@ import { RPCRequest, RPCResponseBody, RPCError, RPCResult } from '../types';

fetch(request.url, {
method:
request.options && request.options.method
? request.options.method
: 'POST',
method: request.options && request.options.method ? request.options.method : 'POST',
cache: 'no-cache',

@@ -19,12 +22,6 @@ mode: 'cors',

...headers,
...(request.options && request.options.headers
? request.options.headers
: {}),
...(request.options && request.options.headers ? request.options.headers : {}),
},
}),
responseHandler: (
response: Response,
request: RPCRequest<any>,
handler: any,
) =>
responseHandler: (response: Response, request: RPCRequest<any>, handler: any) =>
response

@@ -31,0 +28,0 @@ .json()

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import mitt from 'mitt';

@@ -2,0 +7,0 @@

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { BaseProvider } from './baseProvider';

@@ -7,2 +12,3 @@ import { fetchRPC } from './defaultFetcher';

/** @hidden */
const defaultOptions = {

@@ -9,0 +15,0 @@ method: 'POST',

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { HttpProvider } from './http';

@@ -2,0 +7,0 @@ import { WSProvider } from './ws';

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
*/
// TODO: implement Websocket Provider

@@ -2,0 +7,0 @@ import { w3cwebsocket as W3CWebsocket } from 'websocket';

@@ -1,4 +0,10 @@

import {RPCRequestPayload} from '../types';
import {RPCMethod} from './rpc';
/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { RPCRequestPayload } from '../types';
import { RPCMethod } from './rpc';
/**
* @class JsonRpc

@@ -40,7 +46,3 @@ * @description json rpc instance

const sendParams =
params === undefined
? []
: typeof params === 'string'
? [params]
: [...params];
params === undefined ? [] : typeof params === 'string' ? [params] : [...params];

@@ -56,2 +58,2 @@ return {

export {JsonRpc};
export { JsonRpc };

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-network
* @ignore
*/
export const DEFAULT_TIMEOUT: number = 120000;

@@ -24,5 +30,3 @@

fetcher.requestHandler(request, DEFAULT_HEADERS),
request.options && request.options.timeout
? request.options.timeout
: DEFAULT_TIMEOUT,
request.options && request.options.timeout ? request.options.timeout : DEFAULT_TIMEOUT,
);

@@ -29,0 +33,0 @@ return fetcher.responseHandler(response, request, handler);

@@ -0,1 +1,26 @@

/**
* ## About this package
*
* `@harmony-js/network` provides functions to handle messenger, providers and subscriptions...
*
* ## How to use this package
*
* ### 1. Create a Message
* ```javascript
* const { HttpProvider, Messenger } = require('@harmony-js/network');
* const { ChainType, ChainID } = require('@harmony-js/utils');
*
* // create a custom messenger
* const customMessenger = new Messenger(
* new HttpProvider('http://localhost:9500'),
* ChainType.Harmony, // if you are connected to Harmony's blockchain
* ChainID.HmyLocal, // check if the chainId is correct
* )
* ```
*
* @packageDocumentation
* @module harmony-network
*/
/**@ignore */
export const enum RPCMethod {

@@ -75,2 +100,3 @@ // 1. hmy_getBlockByHash

/**@ignore */
export const enum RPCErrorCode {

@@ -77,0 +103,0 @@ // Standard JSON-RPC 2.0 errors

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { Messenger } from '../messenger/messenger';

@@ -14,3 +19,4 @@ import { SubscriptionMethod } from './Subscription';

(this.options.fromBlock && this.options.fromBlock !== 'latest') ||
(this.options.fromBlock === 0 || this.options.fromBlock === '0x')
this.options.fromBlock === 0 ||
this.options.fromBlock === '0x'
) {

@@ -27,11 +33,9 @@ try {

this.emitter.emit('error', getPastLogs.error.message);
} else {
const logs = getPastLogs.result;
logs.forEach((log: any) => {
const formattedLog = this.onNewSubscriptionItem(log);
this.emitter.emit('data', formattedLog);
});
}
const logs = getPastLogs.result;
logs.forEach((log: any) => {
const formattedLog = this.onNewSubscriptionItem(log);
this.emitter.emit('data', formattedLog);
});
delete this.options.fromBlock;

@@ -38,0 +42,0 @@ // const sub = this.start();

@@ -0,4 +1,13 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { Messenger } from '../messenger/messenger';
import { SubscriptionMethod } from './Subscription';
/**
* ### Description:
* Subscribes to incoming block headers. This can be used as timer to check for changes on the blockchain.
*/
export class NewHeaders extends SubscriptionMethod {

@@ -5,0 +14,0 @@ constructor(messenger: Messenger, shardID: number = 0) {

@@ -0,4 +1,13 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { Messenger } from '../messenger/messenger';
import { SubscriptionMethod } from './Subscription';
/**
* ### Description:
* Subscribes to incoming pending transactions
*/
export class NewPendingTransactions extends SubscriptionMethod {

@@ -5,0 +14,0 @@ constructor(messenger: Messenger, shardID: number = 0) {

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-network
*/
import { Messenger } from '../messenger/messenger';

@@ -2,0 +7,0 @@ import { RPCMethod } from '../rpcMethod/rpc';

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { Messenger } from '../messenger/messenger';

@@ -2,0 +8,0 @@ import { SubscriptionMethod } from './Subscription';

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { isHex, hexToNumber } from '@harmony-js/utils';

@@ -6,4 +12,3 @@ import { Emitter } from '../providers/emitter';

const calculateSum = (accumulator: number, currentValue: number) =>
accumulator + currentValue;
const calculateSum = (accumulator: number, currentValue: number) => accumulator + currentValue;
const blockTrackerEvents = ['sync', 'latest'];

@@ -59,5 +64,3 @@

// wait for a new latest block
const latestBlock = await new Promise((resolve) =>
this.once('latest', resolve),
);
const latestBlock = await new Promise((resolve) => this.once('latest', resolve));
// return newly set current block

@@ -174,6 +177,3 @@ return latestBlock;

// clear latest block when stale
this._blockResetTimeout = setTimeout(
this._resetCurrentBlock,
this._blockResetDuration,
);
this._blockResetTimeout = setTimeout(this._resetCurrentBlock, this._blockResetDuration);
// nodejs - dont hold process open

@@ -180,0 +180,0 @@ if (this._blockResetTimeout.unref) {

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { BaseBlockTracker } from './baseTracker';

@@ -86,5 +92,3 @@ import { Messenger } from '../messenger/messenger';

const newErr = new Error(
`PollingBlockTracker - encountered an error while attempting to update latest block:\n${
err.stack
}`,
`PollingBlockTracker - encountered an error while attempting to update latest block:\n${err.stack}`,
);

@@ -91,0 +95,0 @@ try {

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { Messenger } from '../messenger/messenger';

@@ -38,5 +44,3 @@ import { WSProvider } from '../providers/ws';

} else if (blockNumber.isResult()) {
const subs = await this.messenger.subscribe(RPCMethod.Subscribe, [
'newHeads',
]);
const subs = await this.messenger.subscribe(RPCMethod.Subscribe, ['newHeads']);
this.subscriptionId = subs;

@@ -43,0 +47,0 @@ subs[0].onData(this._handleSubData);

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-network
* @ignore
*/
import { RPCMethod, RPCErrorCode } from './rpcMethod/rpc';

@@ -2,0 +8,0 @@

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-network
* @hidden
*/
import { ResponseMiddleware } from './messenger/responseMiddleware';

@@ -2,0 +8,0 @@

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

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 too big to display

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 too big to display

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

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

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

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

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

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

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