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(sdk-coin-dot): make controller optional for bond call #3803

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 || '',
noel-bitgo marked this conversation as resolved.
Show resolved Hide resolved
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
15 changes: 3 additions & 12 deletions modules/sdk-coin-dot/src/lib/stakingBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ export class StakingBuilder extends TransactionBuilder {
*/
protected buildTransaction(): UnsignedTransaction {
const baseTxInfo = this.createBaseTxInfo();
console.log('[Dot staking debug] buildTransaction info', JSON.stringify(baseTxInfo));
console.log('[Dot staking debug] _addToStake', this._addToStake);
if (this._addToStake) {
console.log('calling bondExtra');
return methods.staking.bondExtra(
{
maxAdditional: this._amount,
Expand All @@ -41,10 +38,7 @@ export class StakingBuilder extends TransactionBuilder {
baseTxInfo.options
);
} else {
console.log('[Dot staking debug] calling bond: ');
console.log('[Dot staking debug] this._amount: ', this._amount);
console.log('[Dot staking debug] this._controller: ', this._controller);
const bondMethod = methods.staking.bond(
return methods.staking.bond(
{
value: this._amount,
controller: this._controller,
Expand All @@ -53,8 +47,6 @@ export class StakingBuilder extends TransactionBuilder {
baseTxInfo.baseTxInfo,
baseTxInfo.options
);
console.log('[Dot staking debug] encoded method: ', JSON.stringify(bondMethod.method));
return bondMethod;
}
}

Expand Down Expand Up @@ -125,7 +117,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 @@ -147,10 +139,9 @@ export class StakingBuilder extends TransactionBuilder {
if (this._method?.name === MethodNames.Bond) {
const txMethod = this._method.args as StakeArgs;
this.amount(txMethod.value);
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