Skip to content

Commit

Permalink
Replaced avail-js SignerOptions with TransactionOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
markopoloparadox committed Oct 24, 2024
1 parent 4f0439f commit ee90297
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 269 deletions.
446 changes: 223 additions & 223 deletions avail-js/docs/extrinsics/README.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions avail-js/docs/extrinsics/da_submit_data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SDK, WaitFor, Keyring } from "avail-js-sdk"
import { SDK, WaitFor, Keyring, TransactionOptions } from "avail-js-sdk"

const main = async () => {
const providerEndpoint = "ws://127.0.0.1:9944"
Expand All @@ -8,7 +8,8 @@ const main = async () => {
const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice")
const data = "My Awesome Data"

const result = await sdk.tx.dataAvailability.submitData(data, WaitFor.BlockInclusion, account)
const options: TransactionOptions = { app_id: 1 }
const result = await sdk.tx.dataAvailability.submitData(data, WaitFor.BlockInclusion, account, options)
if (result.isErr) {
console.log(result.reason)
process.exit(1)
Expand Down
1 change: 1 addition & 0 deletions avail-js/examples/next-example/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MouseEventHandler, useState } from "react"
import { ApiPromise, initialize, signedExtensions, types } from "avail-js-sdk"
import { isNumber } from "@polkadot/util"
import { SignerOptions } from "@polkadot/api/types"

import Head from "next/head"

export default function Home() {
Expand Down
4 changes: 2 additions & 2 deletions avail-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions avail-js/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export {
ClaimPermission,
NewCommission,
PoolState,
TransactionOptions,
} from "./transactions"

export class SDK {
Expand Down
9 changes: 4 additions & 5 deletions avail-js/src/sdk/transactions/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { BN } from "@polkadot/util"
import { KeyringPair } from "@polkadot/keyring/types"
import { err, Result } from "neverthrow"

import { SignerOptions } from "@polkadot/api/types"
import { decodeError } from "../../helpers"
import { WaitFor, GenericFailure, standardCallback, getBlockHashAndTxHash } from "./common"
import { WaitFor, GenericFailure, standardCallback, getBlockHashAndTxHash, TransactionOptions } from "./common"

type TransferKeepAliveTxSuccess = {
isErr: false
Expand Down Expand Up @@ -51,7 +50,7 @@ export class Balances {
keepAlive: boolean,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<TransferAllTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -96,7 +95,7 @@ export class Balances {
value: BN,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<TransferAllowDeathTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -150,7 +149,7 @@ export class Balances {
value: BN,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<TransferKeepAliveTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down
7 changes: 7 additions & 0 deletions avail-js/src/sdk/transactions/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ export async function getBlockHashAndTxHash(
}

export type GenericFailure = { isErr: true; reason: string }

export interface TransactionOptions {
app_id?: number
nonce?: number
era?: number
blockHash?: H256
}
14 changes: 6 additions & 8 deletions avail-js/src/sdk/transactions/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { H256, EventRecord } from "@polkadot/types/interfaces/types"
import { BN } from "@polkadot/util"
import { KeyringPair } from "@polkadot/keyring/types"
import { err, Result } from "neverthrow"

import * as TransactionData from "./../transaction_data"
import { SignerOptions } from "@polkadot/api/types"
import { decodeError, fromHexToAscii } from "../../helpers"
import { WaitFor, GenericFailure, standardCallback, getBlockHashAndTxHash } from "./common"
import { WaitFor, GenericFailure, standardCallback, getBlockHashAndTxHash, TransactionOptions } from "./common"

export type DispatchFeeModifier = {
weightMaximumFee: BN | null
Expand Down Expand Up @@ -74,7 +72,7 @@ export class DataAvailability {
data: string,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<SubmitDataTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -131,7 +129,7 @@ export class DataAvailability {
key: string,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<CreateApplicationKeyTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -175,7 +173,7 @@ export class DataAvailability {
newKey: string,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<SetApplicationKeyTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -230,7 +228,7 @@ export class DataAvailability {
cols: number,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<SubmitBlockLengthProposalTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -292,7 +290,7 @@ export class DataAvailability {
modifier: DispatchFeeModifier,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<SetSubmitDataFeeModifierTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down
2 changes: 1 addition & 1 deletion avail-js/src/sdk/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Staking } from "./staking"
import { DataAvailability } from "./da"
import { NominationPools } from "./nomination_pools"

export { WaitFor } from "./common"
export { WaitFor, TransactionOptions } from "./common"
export { DispatchFeeModifier } from "./da"
export { StakingRewardDestination } from "./staking"
export { BondExtra, ClaimPermission, NewCommission, PoolState } from "./nomination_pools"
Expand Down
34 changes: 16 additions & 18 deletions avail-js/src/sdk/transactions/nomination_pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import { H256, EventRecord } from "@polkadot/types/interfaces/types"
import { BN } from "@polkadot/util"
import { KeyringPair } from "@polkadot/keyring/types"
import { err, Result } from "neverthrow"

import { SignerOptions } from "@polkadot/api/types"
import { decodeError } from "../../helpers"
import { WaitFor, GenericFailure, standardCallback, getBlockHashAndTxHash } from "./common"
import { WaitFor, GenericFailure, standardCallback, getBlockHashAndTxHash, TransactionOptions } from "./common"
import { commissionNumberToPerbill } from "../utils"

export interface BondExtra {
Expand Down Expand Up @@ -185,7 +183,7 @@ export class NominationPools {
bouncer: string,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolCreateTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -237,7 +235,7 @@ export class NominationPools {
poolId: number,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolCreateWithPoolIdTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -295,7 +293,7 @@ export class NominationPools {
poolId: number,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolJoinTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -339,7 +337,7 @@ export class NominationPools {
validators: string[],
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolNominateTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -377,7 +375,7 @@ export class NominationPools {
extra: BondExtra,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolBondExtraTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -421,7 +419,7 @@ export class NominationPools {
metadata: string,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolSetMetadataTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -460,7 +458,7 @@ export class NominationPools {
unbondingPoints: BN,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolUnbondTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -499,7 +497,7 @@ export class NominationPools {
poolId: number,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolChillTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -537,7 +535,7 @@ export class NominationPools {
poolId: number,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolClaimCommissionTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -579,7 +577,7 @@ export class NominationPools {
async claimPayout(
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolClaimPayoutTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -618,7 +616,7 @@ export class NominationPools {
other: string,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolClaimPayoutOtherTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -657,7 +655,7 @@ export class NominationPools {
permission: ClaimPermission,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolSetClaimPermissionOtherTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -696,7 +694,7 @@ export class NominationPools {
newCommission: NewCommission | null,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolSetCommissionTxSuccess | GenericFailure> {
const optionWrapper = options || {}

Expand Down Expand Up @@ -749,7 +747,7 @@ export class NominationPools {
numSlashingSpans: number,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolWithdrawUnbodedTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -793,7 +791,7 @@ export class NominationPools {
state: PoolState,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<PoolSetStateTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down
18 changes: 8 additions & 10 deletions avail-js/src/sdk/transactions/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { H256, EventRecord } from "@polkadot/types/interfaces/types"
import { BN } from "@polkadot/util"
import { KeyringPair } from "@polkadot/keyring/types"
import { err, Result } from "neverthrow"

import * as TransactionData from "./../transaction_data"
import { SignerOptions } from "@polkadot/api/types"
import { decodeError } from "../../helpers"
import { WaitFor, GenericFailure, standardCallback, getBlockHashAndTxHash } from "./common"
import { WaitFor, GenericFailure, standardCallback, getBlockHashAndTxHash, TransactionOptions } from "./common"
import { commissionNumberToPerbill } from "../utils"

type ValidatorPerfs = { commission: string; blocked: boolean }
Expand Down Expand Up @@ -90,7 +88,7 @@ export class Staking {
payee: StakingRewardDestination,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<BondTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -133,7 +131,7 @@ export class Staking {
maxAdditional: BN,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<BondExtraTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -175,7 +173,7 @@ export class Staking {
async chill(
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<ChillTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -218,7 +216,7 @@ export class Staking {
stash: string,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<ChillOtherTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -261,7 +259,7 @@ export class Staking {
targets: string[],
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<NominateTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -312,7 +310,7 @@ export class Staking {
value: BN,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<UnbondTxSuccess | GenericFailure> {
const optionWrapper = options || {}
const maybeTxResult = await new Promise<Result<ISubmittableResult, string>>((res, _) => {
Expand Down Expand Up @@ -356,7 +354,7 @@ export class Staking {
blocked: boolean,
waitFor: WaitFor,
account: KeyringPair,
options?: Partial<SignerOptions>,
options?: TransactionOptions,
): Promise<ValidatexSuccess | GenericFailure> {
const maybeCommission = commissionNumberToPerbill(commission)
if (maybeCommission.isErr()) {
Expand Down

0 comments on commit ee90297

Please sign in to comment.