Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Add chainId$ #88

Merged
merged 2 commits into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/api/src/rpc/eth/eth.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class Eth {
.send('eth_call', inOptions(options), inBlockNumber(blockNumber));
}

chainId () {
return this._provider
.send('eth_chainId')
.then(outNumber);
}

coinbase () {
return this._provider
.send('eth_coinbase')
Expand Down
1 change: 1 addition & 0 deletions packages/light.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const {
accounts$,
accountsInfo$,
balanceOf$,
chainId$,
transactionCountOf$,
blockNumber$,
chainName$,
Expand Down
16 changes: 16 additions & 0 deletions packages/light.js/src/rpc/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ import frequency from '../frequency';
import { isNullOrLoading, RPC_LOADING } from '../utils/isLoading';
import { switchMapPromise } from '../utils/operators';

/**
* Observable containing the EIP155 chain ID used for transaction signing.
* Calls `eth_chainId`
*
* @param options - Options to pass to {@link RpcObservableOptions}.
* @return - An Observable containing the chain ID.
*/
export function chainId$ (options?: RpcObservableOptions) {
return createRpc$<any, BigNumber | Symbol>({
calls: ['eth_chainId'],
frequency: [frequency.onStartup$],
name: 'chainId$',
pipes: api => [switchMapPromise(() => api.eth.chainId())]
})(options)();
}

/**
* Observable which contains the array of all addresses managed by the light
* client.
Expand Down
2 changes: 1 addition & 1 deletion packages/light.js/src/utils/testHelpers/mockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class MockProvider extends EventEmitter {

// List of JSONRPCs we want to mock
const listOfMockRps: { [index: string]: string[] } = {
eth: ['accounts', 'blockNumber', 'getBalance', 'getTransactionCount', 'newHeads', 'syncing'],
eth: ['accounts', 'blockNumber', 'chainId', 'getBalance', 'getTransactionCount', 'newHeads', 'syncing'],
fake: ['method'],
net: ['peerCount'],
parity: ['accountsInfo', 'chain', 'postTransaction']
Expand Down