Skip to content

Commit

Permalink
Refactoring avail-rust sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
markopoloparadox committed Nov 8, 2024
1 parent 9f31a0e commit aa0529b
Show file tree
Hide file tree
Showing 22 changed files with 1,051 additions and 1,180 deletions.
2 changes: 1 addition & 1 deletion avail-js/docs/cookbook/src/rpc/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const main = async () => {
// Payment Query Free Details
const mtx2 = await alice.balanceTransfer("5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw", SDK.oneAvail())
const tx2 = mtx2._unsafeUnwrap()
const gtx2 = await tx2.details.fetchGenericTransaction(api)
const gtx2 = (await tx2.details.fetchBlock(api)).transactionByIndex(tx2.details.txIndex)._unsafeUnwrap()
const queryFeeDetails: any = await api.call.transactionPaymentApi.queryFeeDetails(gtx2.toHex(), null)

const baseFee: BN = queryFeeDetails.inclusionFee.__internal__raw.baseFee
Expand Down
8 changes: 4 additions & 4 deletions avail-js/src/sdk/transactions/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { KeyringPair } from "@polkadot/keyring/types"
import {
WaitFor,
TransactionOptions,
singAndSendAndParseTransaction,
signAndSendAndParseTransaction,
TxResultDetails,
TransactionFailed,
} from "./common"
Expand Down Expand Up @@ -49,7 +49,7 @@ export class Balances {
options?: TransactionOptions,
): Promise<Result<TransferAllTx, TransactionFailed>> {
const tx = this.api.tx.balances.transferAll(dest, keepAlive)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand Down Expand Up @@ -78,7 +78,7 @@ export class Balances {
options?: TransactionOptions,
): Promise<Result<TransferAllowDeathTx, TransactionFailed>> {
const tx = this.api.tx.balances.transferAllowDeath(dest, value)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand Down Expand Up @@ -107,7 +107,7 @@ export class Balances {
options?: TransactionOptions,
): Promise<Result<TransferKeepAliveTx, TransactionFailed>> {
const tx = this.api.tx.balances.transferKeepAlive(dest, value)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand Down
2 changes: 1 addition & 1 deletion avail-js/src/sdk/transactions/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function signAndSendTransaction(
})
}

export async function singAndSendAndParseTransaction(
export async function signAndSendAndParseTransaction(
api: ApiPromise,
tx: SubmittableExtrinsic<"promise">,
account: KeyringPair,
Expand Down
12 changes: 6 additions & 6 deletions avail-js/src/sdk/transactions/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { decodeError, fromHexToAscii } from "../../helpers"
import {
WaitFor,
TransactionOptions,
singAndSendAndParseTransaction,
signAndSendAndParseTransaction,
TxResultDetails,
TransactionFailed,
} from "./common"
Expand Down Expand Up @@ -73,7 +73,7 @@ export class DataAvailability {
const appId = optionWrapper.app_id || 0

const tx = this.api.tx.dataAvailability.submitData(data)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -99,7 +99,7 @@ export class DataAvailability {
options?: TransactionOptions,
): Promise<Result<CreateApplicationKeyTx, TransactionFailed>> {
const tx = this.api.tx.dataAvailability.createApplicationKey(key)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -125,7 +125,7 @@ export class DataAvailability {
): Promise<Result<SetApplicationKeyTx, TransactionFailed>> {
const call = this.api.tx.dataAvailability.setApplicationKey(oldKey, newKey)
const tx = this.api.tx.sudo.sudo(call)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -151,7 +151,7 @@ export class DataAvailability {
): Promise<Result<SubmitBlockLengthProposalTx, TransactionFailed>> {
const call = this.api.tx.dataAvailability.submitBlockLengthProposal(rows, cols)
const tx = this.api.tx.sudo.sudo(call)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -177,7 +177,7 @@ export class DataAvailability {
): Promise<Result<SetSubmitDataFeeModifierTx, TransactionFailed>> {
const call = this.api.tx.dataAvailability.setSubmitDataFeeModifier(modifier)
const tx = this.api.tx.sudo.sudo(call)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand Down
6 changes: 3 additions & 3 deletions avail-js/src/sdk/transactions/multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TransactionOptions,
TxResultDetails,
MultisigTimepoint,
singAndSendAndParseTransaction,
signAndSendAndParseTransaction,
} from "./common"

export class AsMultiTx {
Expand Down Expand Up @@ -45,7 +45,7 @@ export class Multisig {
options?: TransactionOptions,
): Promise<Result<AsMultiTx, TransactionFailed>> {
const tx = this.api.tx.multisig.asMulti(threshold, otherSignatures, timepoint, call, maxWeight)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -67,7 +67,7 @@ export class Multisig {
options?: TransactionOptions,
): Promise<Result<ApproveAsMultiTx, TransactionFailed>> {
const tx = this.api.tx.multisig.approveAsMulti(threshold, otherSignatures, timepoint, callHash, maxWeight)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand Down
32 changes: 16 additions & 16 deletions avail-js/src/sdk/transactions/nomination_pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { KeyringPair } from "@polkadot/keyring/types"
import {
WaitFor,
TransactionOptions,
singAndSendAndParseTransaction,
signAndSendAndParseTransaction,
TxResultDetails,
TransactionFailed,
} from "./common"
Expand Down Expand Up @@ -137,7 +137,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<CreateTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.create(amount, root, nominator, bouncer)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -162,7 +162,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<CreateWithPoolIdTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.createWithPoolId(amount, root, nominator, bouncer, poolId)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -184,7 +184,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<JoinTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.join(amount, poolId)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -203,7 +203,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<NominateTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.nominate(poolId, validators)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -218,7 +218,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<BondExtraTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.bondExtra(extra)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -237,7 +237,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<SetMetadataTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.setMetadata(poolId, metadata)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -253,7 +253,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<UnbondTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.unbond(memberAccount, unbondingPoints)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -269,7 +269,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<ChillTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.chill(poolId)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -284,7 +284,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<ClaimCommissionTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.claimCommission(poolId)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -301,7 +301,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<ClaimPayoutTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.claimPayout()
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -317,7 +317,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<ClaimPayoutOtherTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.claimPayoutOther(other)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -333,7 +333,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<SetClaimPermissionTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.setClaimPermission(permission)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -357,7 +357,7 @@ export class NominationPools {
}

const tx = this.api.tx.nominationPools.setCommission(poolId, commission)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -376,7 +376,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<WithdrawUnbodedTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.withdrawUnbonded(memberAccount, numSlashingSpans)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -395,7 +395,7 @@ export class NominationPools {
options?: TransactionOptions,
): Promise<Result<SetStateTx, TransactionFailed>> {
const tx = this.api.tx.nominationPools.setState(poolId, state)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand Down
16 changes: 8 additions & 8 deletions avail-js/src/sdk/transactions/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { err, Result, ok } from "neverthrow"
import {
WaitFor,
TransactionOptions,
singAndSendAndParseTransaction,
signAndSendAndParseTransaction,
TxResultDetails,
TransactionFailed,
} from "./common"
Expand Down Expand Up @@ -79,7 +79,7 @@ export class Staking {
options?: TransactionOptions,
): Promise<Result<BondTx, TransactionFailed>> {
const tx = this.api.tx.staking.bond(value, payee)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -97,7 +97,7 @@ export class Staking {
options?: TransactionOptions,
): Promise<Result<BondExtraTx, TransactionFailed>> {
const tx = this.api.tx.staking.bondExtra(maxAdditional)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -114,7 +114,7 @@ export class Staking {
options?: TransactionOptions,
): Promise<Result<ChillTx, TransactionFailed>> {
const tx = this.api.tx.staking.chill()
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -132,7 +132,7 @@ export class Staking {
options?: TransactionOptions,
): Promise<Result<ChillOtherTx, TransactionFailed>> {
const tx = this.api.tx.staking.chillOther(stash)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -150,7 +150,7 @@ export class Staking {
options?: TransactionOptions,
): Promise<Result<NominateTx, TransactionFailed>> {
const tx = this.api.tx.staking.nominate(targets)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -168,7 +168,7 @@ export class Staking {
options?: TransactionOptions,
): Promise<Result<UnbondTx, TransactionFailed>> {
const tx = this.api.tx.staking.unbond(value)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand All @@ -191,7 +191,7 @@ export class Staking {

const validatorPerfs = { commission: maybeCommission.value, blocked } as ValidatorPerfs
const tx = this.api.tx.staking.validate(validatorPerfs)
const maybeParsed = await singAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
const maybeParsed = await signAndSendAndParseTransaction(this.api, tx, account, waitFor, options)
if (maybeParsed.isErr()) return err(maybeParsed.error)

const details = maybeParsed.value
Expand Down
Loading

0 comments on commit aa0529b

Please sign in to comment.