Skip to content

Commit

Permalink
Merge pull request #181 from notional-labs/add_missing_memo
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
sontrinh16 authored Oct 10, 2023
2 parents 8339647 + 297cdd7 commit 217f334
Showing 1 changed file with 71 additions and 24 deletions.
95 changes: 71 additions & 24 deletions libs/CustomSigner.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,24 @@ import {
import { Registry } from '@cosmjs/proto-signing';
import * as multisigjs from 'multisigjs'
import * as stridejs from 'stridejs'
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
import Long from "long";

// export const getSignningSuperClient = async (signer) => {
// // registry
// const registry = new Registry(defaultRegistryTypes);

// // aminotypes
// const aminoTypes = new AminoTypes({
// ...telescopePackage.cosmwasm.wasm.v1.AminoConverter,
// ...telescopePackage.osmosis.gamm.v1beta1.AminoConverter,
// ...telescopePackage.osmosis.lockup.AminoConverter,
// ...telescopePackage.osmosis.superfluid.AminoConverter
// });

// telescopePackage.cosmwasm.wasm.v1.load(registry);
// telescopePackage.osmosis.gamm.v1beta1.load(registry);
// telescopePackage.osmosis.lockup.load(registry);
// telescopePackage.osmosis.superfluid.load(registry);

// const client = await SigningStargateClient.offline(
// signer,
// { registry, aminoTypes }
// );

// return client;
// }
function omitDefault(input) {
if (typeof input === "string") {
return input === "" ? undefined : input;
}

if (typeof input === "number") {
return input === 0 ? undefined : input;
}

if (Long.isLong(input)) {
return input.isZero() ? undefined : input;
}

throw new Error(`Got unsupported type '${typeof input}'`);
}

export const getCustomClient = async (types, signer) => {
// registry
Expand Down Expand Up @@ -92,6 +85,60 @@ export const getCustomClient = async (types, signer) => {
{ registry, aminoTypes }
);

// fix memo missing in amino converter in cosmjs
client.aminoTypes.register['/ibc.applications.transfer.v1.MsgTransfer'] = {
aminoType: 'cosmos-sdk/MsgTransfer',
toAmino: ({
sourcePort,
sourceChannel,
token,
sender,
receiver,
timeoutHeight,
timeoutTimestamp,
memo,
}) => ({
source_port: sourcePort,
source_channel: sourceChannel,
token: token,
sender: sender,
receiver: receiver,
timeout_height: timeoutHeight
? {
revision_height: omitDefault(timeoutHeight.revisionHeight)?.toString(),
revision_number: omitDefault(timeoutHeight.revisionNumber)?.toString(),
}
: {},
timeout_timestamp: omitDefault(timeoutTimestamp)?.toString(),
memo: omitDefault(memo)?.toString(),
}),
fromAmino: ({
source_port,
source_channel,
token,
sender,
receiver,
timeout_height,
timeout_timestamp,
memo,
}) =>
MsgTransfer.fromPartial({
sourcePort: source_port,
sourceChannel: source_channel,
token: token,
sender: sender,
receiver: receiver,
timeoutHeight: timeout_height
? {
revisionHeight: Long.fromString(timeout_height.revision_height || "0", true),
revisionNumber: Long.fromString(timeout_height.revision_number || "0", true),
}
: undefined,
timeoutTimestamp: Long.fromString(timeout_timestamp || "0", true),
memo: omitDefault(memo)?.toString(),
}),
}

return client;
}

Expand Down

0 comments on commit 217f334

Please sign in to comment.