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

Commit

Permalink
post$: pass passphrase in the options; fix makeContract$
Browse files Browse the repository at this point in the history
  • Loading branch information
axelchalon committed Jan 21, 2019
1 parent aba163e commit 624aed2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
13 changes: 6 additions & 7 deletions packages/light.js/src/rpc/other/makeContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,15 +89,17 @@ const makeContractWithApi = memoizee(
]
})({ provider: api.provider })(...args);
} else {
const { estimate, passphrase, ...txFields } = options;

return post$({
to: address,
data: abiEncode(
method.name,
method.inputs.map(({ kind: { type } }: any) => type), // TODO Use @parity/api types
args
),
...options
}, passphrase);
...txFields
}, { estimate, passphrase });
}
};
});
Expand All @@ -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
Expand All @@ -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);
};
19 changes: 12 additions & 7 deletions packages/light.js/src/rpc/other/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { RpcObservableOptions, Tx, TxStatus } from '../../types';

interface PostOptions extends RpcObservableOptions {
estimate?: boolean;
passphrase: String;
}

function getTransactionReceipt (transactionHash: string, api: any) {
Expand Down Expand Up @@ -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<TxStatus>) => {
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 624aed2

Please sign in to comment.