Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoomProvider: Use a dummy address when making static calls #304

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion src/loom-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
import { soliditySha3 } from './solidity-helpers'
import { marshalBigUIntPB } from './big-uint'
import { SignedEthTxMiddleware } from './middleware'
import { CryptoUtils } from '.'

export interface IEthReceipt {
transactionHash: string
Expand Down Expand Up @@ -147,7 +148,7 @@ export class LoomProvider {
*/
constructor(
client: Client,
privateKey: Uint8Array,
privateKeyOrAddress: Uint8Array | Address,
setupMiddlewaresFunction?: SetupMiddlewareFunction
) {
this._client = client
Expand All @@ -157,12 +158,21 @@ export class LoomProvider {
this._ethRPCMethods = new Map<string, EthRPCMethod>()
this.notificationCallbacks = new Array()
this.accounts = new Map<string, Uint8Array>()
let privateKey: Uint8Array

// Only subscribe for event emitter do not call subevents
this._client.addListener(ClientEvent.EVMEvent, (msg: IChainEventArgs) =>
this._onWebSocketMessage(msg)
)

if ('chainId' in privateKeyOrAddress) {
privateKey = CryptoUtils.generatePrivateKey()
this.setMiddlewaresForAddress(privateKeyOrAddress.local.toString(), client.txMiddleware)
redben marked this conversation as resolved.
Show resolved Hide resolved
this.callerChainId = privateKeyOrAddress.chainId
} else {
privateKey = privateKeyOrAddress
}

if (!this._setupMiddlewares) {
this._setupMiddlewares = (client: Client, privateKey: Uint8Array) => {
return createDefaultTxMiddleware(client, privateKey as Uint8Array)
Expand Down