Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
erer1243 authored and jeapostrophe committed Sep 15, 2022
1 parent 4c7095d commit 92772c3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
5 changes: 3 additions & 2 deletions docs/src/frontend/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,8 @@ stdlib.contract(bin: Backend, info?: Promise<ContractInfo>) => Promise<Contract>

Returns a Reach contract handle based on the `{!js} bin` argument, and optional `ContractInfo` provided.
The `{!js} acc.contract` form will use the account `{!js} acc` to interact with the returned contract.
The `{!js} stdlib.contract` form is equivalent to `{!js} (await stdlib.createAccount()).contract`, generating an account on demand.
The `{!js} stdlib.contract` form is equivalent to `{!js} (await stdlib.createAccount()).contract`, generating an account on demand
(this means the contract can only be used for read-only operations).
This `{!js} bin` argument is the module produced by `{!cmd} reach compile`.

If `{!js} info` is provided, it must be a `{!js} ContractInfo` value, or a `{!js} Promise` that eventually yields a `{!js} ContractInfo` value.
Expand All @@ -856,7 +857,7 @@ This deployment can only happen one time, so subsequent attempts will fail with
This function may emit warnings if there is any danger, risk, or subtlety to using this contract on your chosen consensus network.
You can omit this warning by setting `{!cmd} REACH_NO_WARN`, but we recommend that you do not.

The `acc.contract` form of the function does not block.
The `{!js} acc.contract` form of the function does not block.

---

Expand Down
10 changes: 4 additions & 6 deletions js/stdlib/ts/ALGO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
hasProp,
makeParseCurrency,
TransferOpts,
stdlibShared,
} from './shared_impl';
import {
bigNumberify,
Expand Down Expand Up @@ -2707,10 +2708,7 @@ const launchToken = async (accCreator: Account, name: string, sym: string, opts:
return { name, sym, id, mint, optOut };
}

const contract = (bin: Backend, ctcInfo?: Promise<ContractInfo>): Promise<Contract> =>
createAccount().then(acc => acc.contract(bin, ctcInfo));

return {
return stdlibShared({
...stdlib,
...typeDefs,
...shared_user,
Expand All @@ -2733,6 +2731,6 @@ const contract = (bin: Backend, ctcInfo?: Promise<ContractInfo>): Promise<Contra
parseCurrency, minimumBalance, formatCurrency,
reachStdlib, algosdk,
connector, standardUnit, atomicUnit,
tokensAccepted, contract,
};
tokensAccepted
});
};
5 changes: 3 additions & 2 deletions js/stdlib/ts/CFX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as ethers from './cfxers';
import * as shared_user from './shared_user';
import * as CFX_compiled from './CFX_compiled';
import * as ETH_compiled_impl from './ETH_compiled_impl';
import { stdlibShared } from './shared_impl';

const _ETH_compiled_impl: EthLikeCompiledArgs = ETH_compiled_impl;
void(_ETH_compiled_impl);
Expand All @@ -25,12 +26,12 @@ export const load = (): Stdlib_User<Provider, ProviderEnv, ProviderName, Token,
const CFX_compiled_: EthLikeCompiled = CFX_compiled;

const connector = 'CFX';
return {
return stdlibShared({
...ethers_,
...ethLike,
...ethLike.reachStdlib,
...shared_user,
...CFX_compiled_,
connector,
};
});
};
5 changes: 3 additions & 2 deletions js/stdlib/ts/ETH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as ethers from 'ethers';
import * as shared_user from './shared_user';
import * as ETH_compiled from './ETH_compiled';
import * as ETH_compiled_impl from './ETH_compiled_impl';
import { stdlibShared } from './shared_impl';

const _ETH_compiled_impl: EthLikeCompiledArgs = ETH_compiled_impl;
void(_ETH_compiled_impl);
Expand All @@ -25,12 +26,12 @@ export const load = (): Stdlib_User<Provider, ProviderEnv, ProviderName, Token,
const ETH_compiled_: EthLikeCompiled = ETH_compiled;

const connector = 'ETH';
return {
return stdlibShared({
...ethers_,
...ethLike,
...ethLike.reachStdlib,
...shared_user,
...ETH_compiled_,
connector,
};
});
};
4 changes: 0 additions & 4 deletions js/stdlib/ts/ETH_like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1172,9 +1172,6 @@ function setCustomHttpEventHandler() {
console.warn(`setCustomHttpEventHandler is not supported on this connector`);
}

const contract = (bin: Backend, ctcInfo?: Promise<ContractInfo>): Promise<Contract> =>
createAccount().then(acc => acc.contract(bin, ctcInfo));

// TODO: restore type ann once types are in place
// const ethLike: EthLike = {
const ethLike = {
Expand Down Expand Up @@ -1224,7 +1221,6 @@ const ethLike = {
setSigningMonitor,
getTimeSecs,
tokensAccepted,
contract,
};
return ethLike;
}
17 changes: 16 additions & 1 deletion js/stdlib/ts/shared_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { process } from './shim';
export {
hexlify
} from './shared_backend';
import type { Arith } from './interfaces';
import type { Arith, Stdlib_User } from './interfaces';

type BigNumber = ethers.BigNumber;

Expand Down Expand Up @@ -283,6 +283,21 @@ export type EventStream<T> = {
monitor: (f: any) => void
}

export const stdlibShared =
<ContractInfo,
Backend extends IBackend<any>,
Account extends IAccount<any, any, any, any, any>,
Contract extends IContract<ContractInfo, any, any, any>,
ConnectorStdlib extends
Omit<Stdlib_User<any, any, any, any, ContractInfo, any, any, any, Backend, Contract, Account>, "contract">
>(connectorStdlib: ConnectorStdlib) =>
{
const contract = (bin: Backend, ctcInfo?: Promise<ContractInfo>): Promise<Contract> =>
connectorStdlib.createAccount().then(acc => acc.contract(bin, ctcInfo));

return { ...connectorStdlib, contract };
}

export const stdVerifyContract =
async <ContractInfo, VerifyResult>(
stdArgs: Pick<ISetupViewArgs<ContractInfo, VerifyResult>, ("getTrustedVerifyResult"|"setTrustedVerifyResult")>,
Expand Down

0 comments on commit 92772c3

Please sign in to comment.