-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: add bridge_amino and test #61
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
blushi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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, | ||
}; | ||
}), | ||
}; | ||
}, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { | |
import { Registry, EncodeObject, GeneratedType } from '@cosmjs/proto-signing'; | ||
|
||
import { SigningConnectionOptions } from '../api'; | ||
import { regenRegistry } from './regen-message-type-registry'; | ||
import { regenTypeRegistry } from './regen-message-type-registry'; | ||
import { createStargateSigningClient } from './stargate-signing'; | ||
import { createEcocreditAminoConverters } from './modules'; | ||
import { messageTypeRegistry } from '../generated/typeRegistry'; | ||
|
@@ -37,7 +37,7 @@ export async function setupTxExtension( | |
messageTypeRegistry.forEach((value, key) => { | ||
customRegistry.push([`/${key}`, value]); | ||
}); | ||
regenRegistry.forEach(([key, value]) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deleting this. As @blushi pointed out, the |
||
regenTypeRegistry.forEach(([key, value]) => { | ||
customRegistry.push([`/${key}`, value]); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not related to this PR, but why do we need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deleted |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ import { | |
} from '../generated/regen/ecocredit/marketplace/v1/tx'; | ||
import { GeneratedType } from '@cosmjs/proto-signing'; | ||
|
||
const ecocreditRegistry: Array<[string, GeneratedType]> = [ | ||
const ecocreditRegistry: ReadonlyArray<[string, GeneratedType]> = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
[MsgCancel.$type, MsgCancel], | ||
[MsgCreateClass.$type, MsgCreateClass], | ||
[MsgSend.$type, MsgSend], | ||
|
@@ -40,20 +40,20 @@ const ecocreditRegistry: Array<[string, GeneratedType]> = [ | |
[MsgUpdateProjectAdmin.$type, MsgUpdateProjectAdmin], | ||
]; | ||
|
||
const basketRegistry: Array<[string, GeneratedType]> = [ | ||
const basketRegistry: ReadonlyArray<[string, GeneratedType]> = [ | ||
[MsgCreate.$type, MsgCreate], | ||
[MsgPut.$type, MsgPut], | ||
[MsgTake.$type, MsgTake], | ||
]; | ||
|
||
const marketplaceRegistry: Array<[string, GeneratedType]> = [ | ||
const marketplaceRegistry: ReadonlyArray<[string, GeneratedType]> = [ | ||
[MsgBuyDirect.$type, MsgBuyDirect], | ||
[MsgSell.$type, MsgSell], | ||
[MsgUpdateSellOrders.$type, MsgUpdateSellOrders], | ||
[MsgCancelSellOrder.$type, MsgCancelSellOrder], | ||
]; | ||
|
||
export const regenRegistry = [ | ||
export const regenTypeRegistry = [ | ||
...ecocreditRegistry, | ||
...basketRegistry, | ||
...marketplaceRegistry, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested this against redwood locally, including all negative tests I could think of, but we will need to implement #59 to run it in CI.
https://redwood.regen.aneka.io/txs/C70A43E236BAAB1B2DD2D352A03CBB72D8DF307EB7F03D61905315B26324C738