-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add bridge_amino and test (#61)
* feat: add bridge_amino and test * chore: delete unnecessary regen-message-type-registry
- Loading branch information
Showing
5 changed files
with
89 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { AminoMsg } from '@cosmjs/amino'; | ||
import { AminoConverter } from '@cosmjs/stargate'; | ||
import { MsgBridge } from '../../../../generated/regen/ecocredit/v1/tx'; | ||
import { Credits } from '../../../../generated/regen/ecocredit/v1/types'; | ||
import { AminoCredits } from './msg_cancel'; | ||
|
||
const msgBridgeAminoType = 'regen.core/MsgBridge'; | ||
|
||
export const bridgeTypeUrl = '/' + MsgBridge.$type; | ||
|
||
export interface AminoMsgBridge extends AminoMsg { | ||
readonly type: typeof msgBridgeAminoType; | ||
readonly value: { | ||
// readonly $type: string; TODO: we will leave these off until nested types can be supported | ||
readonly owner: string; | ||
readonly target?: string; | ||
readonly recipient?: string; | ||
readonly credits: AminoCredits[]; | ||
}; | ||
} | ||
|
||
export function isAminoMsgBridge(msg: AminoMsg): msg is AminoMsgBridge { | ||
return msg.type === msgBridgeAminoType; | ||
} | ||
|
||
export function bridgeConverter(): AminoConverter { | ||
return { | ||
aminoType: msgBridgeAminoType, | ||
toAmino: ({ | ||
owner, | ||
target, | ||
recipient, | ||
credits, | ||
}: MsgBridge): AminoMsgBridge['value'] => { | ||
return { | ||
owner, | ||
target, | ||
recipient, | ||
credits: credits.map(credit => { | ||
return { | ||
batch_denom: credit.batchDenom, | ||
amount: credit.amount, | ||
}; | ||
}), | ||
}; | ||
}, | ||
fromAmino: ({ | ||
owner, | ||
target, | ||
recipient, | ||
credits, | ||
}: AminoMsgBridge['value']): Partial<MsgBridge> => { | ||
return { | ||
owner, | ||
target, | ||
recipient, | ||
credits: credits.map(credit => { | ||
return { | ||
$type: Credits.$type, | ||
batchDenom: credit.batch_denom, | ||
amount: credit.amount, | ||
}; | ||
}), | ||
}; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.