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

Fix broken web frontend #122

Merged
merged 13 commits into from
May 16, 2023
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.16.0
18.16.0
12 changes: 6 additions & 6 deletions common/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
"main": "./src/index.ts",
"scripts": {
"build": "yarn generate:defs && yarn generate:meta",
"generate:defs": "ts-node node_modules/.bin/polkadot-types-from-defs --package '.' --input './src/interfaces'",
"generate:meta": "ts-node node_modules/.bin/polkadot-types-from-chain --package '.' --endpoint 'ws://127.0.0.1:9944' --output './src/interfaces'",
"generate:defs": "ts-node --project './tsconfig.base.json' --esm node_modules/.bin/polkadot-types-from-defs --package '.' --endpoint 'ws://127.0.0.1:9988' --input './src/interfaces'",
"generate:meta": "ts-node --project './tsconfig.base.json' --esm node_modules/.bin/polkadot-types-from-chain --package '.' --endpoint 'ws://127.0.0.1:9988' --output './src/interfaces'",
"lint": "prettier --write '{src,scripts}/**/*'",
"check-ts": "tsc -p . --noEmit"
},
"dependencies": {
"@polkadot/api-contract": "9.3.1",
"@polkadot/typegen": "9.3.1",
"prettier": "2.7.1",
"@polkadot/api-contract": "10.6.1",
"@polkadot/typegen": "10.6.1",
"prettier": "2.8.8",
"ts-node": "10.9.1",
"typescript": "4.7.4"
"typescript": "5.0.4"
}
}
15 changes: 12 additions & 3 deletions common/js/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ApiPromise } from "@polkadot/api"
import type { SignerOptions } from "@polkadot/api/submittable/types"
import { ContractPromise } from "@polkadot/api-contract"

import { tx, buildErrorText } from "./api"
import { tx, buildErrorText, createType } from "./api"
import type { KeyringPairOrAddressAndSigner } from "./utils"

import gameAbi from "../../../contract/deploy/202109210_init/game.json"
Expand All @@ -20,7 +20,14 @@ export const queryContract = async (
throw new Error(`query fn not found: ${fnName}`)
}

const { result, output } = await contract.query[fnName](caller, { value: 0 }, ...fnArgs)
const { result, output } = await contract.query[fnName](
caller,
{
gasLimit: bigWeight,
value: 0,
},
...fnArgs
)

if (!result.isOk) {
throw new Error(
Expand All @@ -47,9 +54,11 @@ export const txContract = (

return tx(
contract.api as ApiPromise,
() => contract.tx[fnName]({ value: 0 }, ...fnArgs),
() => contract.tx[fnName]({ gasLimit: bigWeight, value: 0 }, ...fnArgs),
account,
undefined,
{ tip: 1, ...overrideOptions }
)
}

const bigWeight = createType("WeightV2", { proofSize: 3_000_000, refTime: 300_000_000_000 })
1 change: 1 addition & 0 deletions common/js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./interfaces/augment-api"
import "./interfaces/augment-types"
import "./interfaces/types-lookup"

export * from "./api"
export * from "./pow"
Expand Down
191 changes: 168 additions & 23 deletions common/js/src/interfaces/augment-api-consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,141 @@
import '@polkadot/api-base/types/consts';

import type { ApiTypes, AugmentedConst } from '@polkadot/api-base/types';
import type { Vec, u8 } from '@polkadot/types-codec';
import type { bool, u128, u16, u32, u64, u8 } from '@polkadot/types-codec';
import type { Codec } from '@polkadot/types-codec/types';
import type { Balance, BalanceOf, BlockNumber, Moment, RuntimeDbWeight } from '@polkadot/types/interfaces/runtime';
import type { RuntimeVersion } from '@polkadot/types/interfaces/state';
import type { WeightToFeeCoefficient } from '@polkadot/types/interfaces/support';
import type { BlockLength, BlockWeights } from '@polkadot/types/interfaces/system';
import type { FrameSystemLimitsBlockLength, FrameSystemLimitsBlockWeights, PalletContractsSchedule, SpVersionRuntimeVersion, SpWeightsRuntimeDbWeight } from '@polkadot/types/lookup';

export type __AugmentedConst<ApiType extends ApiTypes> = AugmentedConst<ApiType>;

declare module '@polkadot/api-base/types/consts' {
interface AugmentedConsts<ApiType extends ApiTypes> {
assets: {
/**
* The amount of funds that must be reserved when creating a new approval.
**/
approvalDeposit: u128 & AugmentedConst<ApiType>;
/**
* The amount of funds that must be reserved for a non-provider asset account to be
* maintained.
**/
assetAccountDeposit: u128 & AugmentedConst<ApiType>;
/**
* The basic amount of funds that must be reserved for an asset.
**/
assetDeposit: u128 & AugmentedConst<ApiType>;
/**
* The basic amount of funds that must be reserved when adding metadata to your asset.
**/
metadataDepositBase: u128 & AugmentedConst<ApiType>;
/**
* The additional funds that must be reserved for the number of bytes you store in your
* metadata.
**/
metadataDepositPerByte: u128 & AugmentedConst<ApiType>;
/**
* Max number of items to destroy per `destroy_accounts` and `destroy_approvals` call.
*
* Must be configured to result in a weight that makes each call fit in a block.
**/
removeItemsLimit: u32 & AugmentedConst<ApiType>;
/**
* The maximum length of a name or symbol stored on-chain.
**/
stringLimit: u32 & AugmentedConst<ApiType>;
/**
* Generic const
**/
[key: string]: Codec;
};
balances: {
/**
* The minimum amount required to keep an account open.
* The minimum amount required to keep an account open. MUST BE GREATER THAN ZERO!
*
* If you *really* need it to be zero, you can enable the feature `insecure_zero_ed` for
* this pallet. However, you do so at your own risk: this will open up a major DoS vector.
* In case you have multiple sources of provider references, you may also get unexpected
* behaviour if you set this to zero.
*
* Bottom line: Do yourself a favour and make it at least one!
**/
existentialDeposit: u128 & AugmentedConst<ApiType>;
/**
* The maximum number of individual freeze locks that can exist on an account at any time.
**/
maxFreezes: u32 & AugmentedConst<ApiType>;
/**
* The maximum number of holds that can exist on an account at any time.
**/
maxHolds: u32 & AugmentedConst<ApiType>;
/**
* The maximum number of locks that should exist on an account.
* Not strictly enforced, but used for weight estimation.
**/
maxLocks: u32 & AugmentedConst<ApiType>;
/**
* The maximum number of named reserves that can exist on an account.
**/
maxReserves: u32 & AugmentedConst<ApiType>;
/**
* Generic const
**/
[key: string]: Codec;
};
contracts: {
/**
* Fallback value to limit the storage deposit if it's not being set by the caller.
**/
defaultDepositLimit: u128 & AugmentedConst<ApiType>;
/**
* The amount of balance a caller has to pay for each byte of storage.
*
* # Note
*
* Changing this value for an existing chain might need a storage migration.
**/
depositPerByte: u128 & AugmentedConst<ApiType>;
/**
* The amount of balance a caller has to pay for each storage item.
*
* # Note
*
* Changing this value for an existing chain might need a storage migration.
**/
depositPerItem: u128 & AugmentedConst<ApiType>;
/**
* The maximum length of a contract code in bytes. This limit applies to the instrumented
* version of the code. Therefore `instantiate_with_code` can fail even when supplying
* a wasm binary below this maximum size.
*
* The value should be chosen carefully taking into the account the overall memory limit
* your runtime has, as well as the [maximum allowed callstack
* depth](#associatedtype.CallStack). Look into the `integrity_test()` for some insights.
**/
maxCodeLen: u32 & AugmentedConst<ApiType>;
/**
* The maximum length of the debug buffer in bytes.
**/
maxDebugBufferLen: u32 & AugmentedConst<ApiType>;
/**
* The maximum allowable length in bytes for storage keys.
**/
maxStorageKeyLen: u32 & AugmentedConst<ApiType>;
/**
* Cost schedule and limits.
**/
existentialDeposit: Balance & AugmentedConst<ApiType>;
schedule: PalletContractsSchedule & AugmentedConst<ApiType>;
/**
* Make contract callable functions marked as `#[unstable]` available.
*
* Contracts that use `#[unstable]` functions won't be able to be uploaded unless
* this is set to `true`. This is only meant for testnets and dev nodes in order to
* experiment with new features.
*
* # Warning
*
* Do **not** set to `true` on productions chains.
**/
unsafeUnstableInterface: bool & AugmentedConst<ApiType>;
/**
* Generic const
**/
Expand All @@ -31,58 +150,84 @@ declare module '@polkadot/api-base/types/consts' {
/**
* Maximum number of block number to block hash mappings to keep (oldest pruned first).
**/
blockHashCount: BlockNumber & AugmentedConst<ApiType>;
blockHashCount: u32 & AugmentedConst<ApiType>;
/**
* The maximum length of a block (in bytes).
**/
blockLength: BlockLength & AugmentedConst<ApiType>;
blockLength: FrameSystemLimitsBlockLength & AugmentedConst<ApiType>;
/**
* Block & extrinsics weights: base values and limits.
**/
blockWeights: BlockWeights & AugmentedConst<ApiType>;
blockWeights: FrameSystemLimitsBlockWeights & AugmentedConst<ApiType>;
/**
* The weight of runtime database operations the runtime can invoke.
**/
dbWeight: RuntimeDbWeight & AugmentedConst<ApiType>;
dbWeight: SpWeightsRuntimeDbWeight & AugmentedConst<ApiType>;
/**
* The designated SS85 prefix of this chain.
* The designated SS58 prefix of this chain.
*
* This replaces the "ss58Format" property declared in the chain spec. Reason is
* that the runtime should know about the prefix in order to make use of it as
* an identifier of the chain.
**/
ss58Prefix: u8 & AugmentedConst<ApiType>;
ss58Prefix: u16 & AugmentedConst<ApiType>;
/**
* Get the chain's current version.
**/
version: RuntimeVersion & AugmentedConst<ApiType>;
version: SpVersionRuntimeVersion & AugmentedConst<ApiType>;
/**
* Generic const
**/
[key: string]: Codec;
};
timestamp: {
/**
* The minimum period between blocks. Beware that this is different to the *expected* period
* that the block production apparatus provides. Your chosen consensus system will generally
* work with this to determine a sensible block time. e.g. For Aura, it will be double this
* period on default settings.
* The minimum period between blocks. Beware that this is different to the *expected*
* period that the block production apparatus provides. Your chosen consensus system will
* generally work with this to determine a sensible block time. e.g. For Aura, it will be
* double this period on default settings.
**/
minimumPeriod: Moment & AugmentedConst<ApiType>;
minimumPeriod: u64 & AugmentedConst<ApiType>;
/**
* Generic const
**/
[key: string]: Codec;
};
transactionPayment: {
/**
* The fee to be paid for making a transaction; the per-byte portion.
* A fee mulitplier for `Operational` extrinsics to compute "virtual tip" to boost their
* `priority`
*
* This value is multipled by the `final_fee` to obtain a "virtual tip" that is later
* added to a tip component in regular `priority` calculations.
* It means that a `Normal` transaction can front-run a similarly-sized `Operational`
* extrinsic (with no tip), by including a tip value greater than the virtual tip.
*
* ```rust,ignore
* // For `Normal`
* let priority = priority_calc(tip);
*
* // For `Operational`
* let virtual_tip = (inclusion_fee + tip) * OperationalFeeMultiplier;
* let priority = priority_calc(tip + virtual_tip);
* ```
*
* Note that since we use `final_fee` the multiplier applies also to the regular `tip`
* sent with the transaction. So, not only does the transaction get a priority bump based
* on the `inclusion_fee`, but we also amplify the impact of tips applied to `Operational`
* transactions.
**/
operationalFeeMultiplier: u8 & AugmentedConst<ApiType>;
/**
* Generic const
**/
transactionByteFee: BalanceOf & AugmentedConst<ApiType>;
[key: string]: Codec;
};
utility: {
/**
* The polynomial that is applied in order to derive fee from weight.
* The limit on the number of batched calls.
**/
weightToFee: Vec<WeightToFeeCoefficient> & AugmentedConst<ApiType>;
batchedCallsLimit: u32 & AugmentedConst<ApiType>;
/**
* Generic const
**/
Expand Down
Loading