Skip to content

Commit

Permalink
WIP: figured out some encoding stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed May 1, 2024
1 parent 7ba1699 commit 835fba2
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 130 deletions.
15 changes: 9 additions & 6 deletions packages/orchestration/src/exos/stakingAccountKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ const toJSON = x => /** @type {AnyJson} */ (Any.toJSON(x));
/**
* @template T
* @param {string} ackStr
* @param {(m: Uint8Array) => T} decode
* @param {(p: {typeUrl: string, value: Uint8Array}) => T} fromProtoMsg
*/
export const tryDecodeResponse = (ackStr, decode) => {
export const tryDecodeResponse = (ackStr, fromProtoMsg) => {
try {
const decoded = decode(decodeBase64(ackStr));
return decoded;
const any = Any.decode(decodeBase64(ackStr));
const protoMsg = Any.decode(any.value);

const msg = fromProtoMsg(protoMsg);
return msg;
} catch (cause) {
throw assert.error(`bad response: ${ackStr}`, undefined, { cause });
}
Expand Down Expand Up @@ -153,7 +156,7 @@ export const prepareStakingAccountKit = (baggage, makeRecorderKit, zcf) => {
]);

if (!result) throw Fail`Failed to delegate.`;
return tryDecodeResponse(result, MsgDelegateResponse.decode);
return tryDecodeResponse(result, MsgDelegateResponse.fromProtoMsg);
},

/**
Expand All @@ -171,7 +174,7 @@ export const prepareStakingAccountKit = (baggage, makeRecorderKit, zcf) => {
// @ts-expect-error type is wrong for MsgWithdrawDelegatorRewardResponse???
const { amount: coins } = tryDecodeResponse(
result,
MsgWithdrawDelegatorRewardResponse.decode,
MsgWithdrawDelegatorRewardResponse.fromProtoMsg,
);
return harden(coins.map(toChainAmount));
},
Expand Down
Loading

0 comments on commit 835fba2

Please sign in to comment.