Skip to content

Commit 9fd4c17

Browse files
committed
use fixed padding for sdk swift decode fn
1 parent 01c54de commit 9fd4c17

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

sdk/src/driftClient.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6565,9 +6565,10 @@ export class DriftClient {
65656565
}
65666566

65676567
/*
6568-
* Decode signedMsg taker order params from borsh buffer. Zero pads the message on failed deserializations until
6569-
* the message is successfuly decoded, or we've hit max iterations. This is necessary if the client
6570-
* decodes a message encoded by an outdated IDL.
6568+
* Decode signedMsg taker order params from borsh buffer. Zero pads the message in case the
6569+
* received message was encoded by an outdated IDL (size will be too small and decode will throw).
6570+
* Note: the 128 will be problematic if the type we are expecting to deserializze into is 128 bytes
6571+
* larger than the message we are receiving (unlikely, especially if all new fields are Options).
65716572
*/
65726573
public decodeSignedMsgOrderParamsMessage(
65736574
encodedMessage: Buffer,
@@ -6576,26 +6577,9 @@ export class DriftClient {
65766577
const decodeStr = delegateSigner
65776578
? 'SignedMsgOrderParamsDelegateMessage'
65786579
: 'SignedMsgOrderParamsMessage';
6579-
let decodeAttempts = 0;
6580-
do {
6581-
try {
6582-
return this.program.coder.types.decode(
6583-
decodeStr,
6584-
encodedMessage.slice(8) // assumes discriminator
6585-
);
6586-
} catch (err) {
6587-
if (err.message.includes('out of range')) {
6588-
decodeAttempts++;
6589-
encodedMessage = Buffer.concat([encodedMessage, Buffer.from([0])]);
6590-
continue;
6591-
} else {
6592-
throw err;
6593-
}
6594-
}
6595-
} while (decodeAttempts < 100);
6596-
6597-
throw new Error(
6598-
`Failed to decode SignedMsgOrderParamsMessage after ${decodeAttempts} attempts`
6580+
return this.program.coder.types.decode(
6581+
decodeStr,
6582+
Buffer.concat([encodedMessage.slice(8), Buffer.alloc(128)]) // assumes discriminator
65996583
);
66006584
}
66016585

0 commit comments

Comments
 (0)