diff --git a/packages/light.js/src/rpc/other/makeContract.ts b/packages/light.js/src/rpc/other/makeContract.ts index 8c718285..55bf8bdd 100644 --- a/packages/light.js/src/rpc/other/makeContract.ts +++ b/packages/light.js/src/rpc/other/makeContract.ts @@ -45,14 +45,13 @@ const getContract = memoizee( * @ignore * @param address - The contract address. * @param abiJson - The contract abi. - * @param passphrase - Passphrase of the account creating the contract * @param api - The api Object. * @return - An object whose keys are all the functions of the * contract, and each function returns an Observable which will fire when the * function resolves. */ const makeContractWithApi = memoizee( - (address: Address, abiJson: any[], passphrase: string, api: any) => { + (address: Address, abiJson: any[], api: any) => { const abi = new Abi(abiJson); // use types from @parity/abi // Variable result will hold the final object to return @@ -90,6 +89,8 @@ const makeContractWithApi = memoizee( ] })({ provider: api.provider })(...args); } else { + const { estimate, passphrase, ...txFields } = options; + return post$({ to: address, data: abiEncode( @@ -97,8 +98,8 @@ const makeContractWithApi = memoizee( method.inputs.map(({ kind: { type } }: any) => type), // TODO Use @parity/api types args ), - ...options - }, passphrase); + ...txFields + }, { estimate, passphrase }); } }; }); @@ -112,7 +113,6 @@ const makeContractWithApi = memoizee( * * @param address - The contract address. * @param abiJson - The contract abi. - * @param passphrase - Passphrase of the account creating the contract * @param options - The options to pass in when creating the contract. * @return - An object whose keys are all the functions of the * contract, and each function return an Observable which will fire when the @@ -121,11 +121,10 @@ const makeContractWithApi = memoizee( export const makeContract = ( address: Address, abiJson: any[], - passphrase: string, options: { provider?: any } = {} ) => { const { provider } = options; const api = provider ? createApiFromProvider(provider) : getApi(); - return makeContractWithApi(address, abiJson, passphrase, api); + return makeContractWithApi(address, abiJson, api); }; diff --git a/packages/light.js/src/rpc/other/post.ts b/packages/light.js/src/rpc/other/post.ts index 78711874..dbd51855 100644 --- a/packages/light.js/src/rpc/other/post.ts +++ b/packages/light.js/src/rpc/other/post.ts @@ -13,6 +13,7 @@ import { RpcObservableOptions, Tx, TxStatus } from '../../types'; interface PostOptions extends RpcObservableOptions { estimate?: boolean; + passphrase: String; } function getTransactionReceipt (transactionHash: string, api: any) { @@ -42,12 +43,16 @@ function getTransactionReceipt (transactionHash: string, api: any) { * the transaction. * * @param tx - Transaction object - * @param passphrase - Passphrase of the account - * @param options? - Options to pass to the {@link RpcObservable}. - * @return - The status of the transaction. + * @param options - Options to pass to the {@link RpcObservable}. + * @param options.passphrase - Passphrase of the account + * @return - The status of the transaction: (estimated), signed, sent, confirmed */ -export function post$ (tx: Tx, passphrase: string, options: PostOptions = {}) { - const { estimate, provider } = options; +export function post$ (tx: Tx, options: PostOptions) { + const { estimate, passphrase, provider } = options; + if (!passphrase) { + throw new Error('The passphrase is missing from the options'); + } + const api = provider ? createApiFromProvider(provider) : getApi(); const source$ = Observable.create(async (observer: Observer) => { @@ -80,9 +85,9 @@ export function post$ (tx: Tx, passphrase: string, options: PostOptions = {}) { * * @param rawTx - Raw transaction * @param options? - Options to pass to the {@link RpcObservable}. - * @return - The status of the transaction. + * @return - The status of the transaction: sent, confirmed */ -export function postRaw$ (rawTx: string, options: PostOptions = {}) { +export function postRaw$ (rawTx: string, options: RpcObservableOptions = {}) { const { provider } = options; const api = provider ? createApiFromProvider(provider) : getApi();