Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(sdk-coin-dot): make controller optional for bond call
  • Loading branch information
noel-bitgo committed Aug 14, 2023
commit a6f6a0d96afdb663a7a096c4eb2caf9ca1649d63
3 changes: 2 additions & 1 deletion modules/sdk-coin-dot/src/lib/batchTransactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ export class BatchTransactionBuilder extends TransactionBuilder {
const baseTxInfo = this.createBaseTxInfo();
const unsigned = methods.staking.bond(
{
controller: args.controller.id,
// TODO(EA-1242): update DOT library to remove controller optional field -> https://github.com/paritytech/txwrapper-core/pull/309 and https://github.com/paritytech/substrate/pull/14039
controller: args.controller?.id || '',
value: args.value,
payee: this.getPayee(args.payee),
},
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-dot/src/lib/iface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export type StakeArgsPayeeRaw = { controller?: null; stash?: null; staked?: null
*/
export interface StakeArgs {
value: string;
controller: { id: string };
controller?: { id: string };
payee: StakeArgsPayee;
}

Expand Down Expand Up @@ -275,7 +275,7 @@ export type StakeBatchCallPayee =

export interface StakeBatchCallArgs {
value: string;
controller: { id: string };
controller?: { id: string };
payee: StakeBatchCallPayee;
}

Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-dot/src/lib/stakingBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class StakingBuilder extends TransactionBuilder {
if (decodedTxn.method?.name === MethodNames.Bond) {
const txMethod = decodedTxn.method.args as unknown as StakeArgs;
const value = txMethod.value;
const controller = txMethod.controller.id;
const controller = txMethod.controller?.id;
const payee = txMethod.payee;
const validationResult = StakeTransactionSchema.validate({ value, controller, payee });
if (validationResult.error) {
Expand All @@ -150,7 +150,7 @@ export class StakingBuilder extends TransactionBuilder {
console.log('[Dot staking debug] calling owner: ', JSON.stringify(txMethod));
this.owner({
address: utils.decodeDotAddress(
txMethod.controller.id,
txMethod.controller?.id || '',
utils.getAddressFormat(this._coinConfig.name as DotAssetTypes)
),
});
Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-dot/src/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ export class Transaction extends BaseTransaction {
const txMethod = decodedTx.method.args;
if (utils.isBond(txMethod)) {
const keypair = new KeyPair({
pub: Buffer.from(decodeAddress(txMethod.controller.id, false, this._registry.chainSS58)).toString('hex'),
pub: Buffer.from(decodeAddress(txMethod.controller?.id || '', false, this._registry.chainSS58)).toString(
'hex'
),
});

result.controller = keypair.getAddress(utils.getAddressFormat(this._coinConfig.name as DotAssetTypes));
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-dot/src/lib/txnSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const TransferAllTransactionSchema = joi.object({

const CreateStakeTransactionSchema = joi.object({
value: joi.string().required(),
controller: addressSchema.required(),
controller: joi.string().optional(),
payee: [
joi.string(),
joi.object({
Expand Down