-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4615 from Agoric/mfig-4614-ics20-trace-and-result
feat(pegasus): implement correct result and denom trace handling
- Loading branch information
Showing
6 changed files
with
182 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// @ts-check | ||
import { Far } from '@endo/marshal'; | ||
import { assert, details as X } from '@agoric/assert'; | ||
|
||
import { parse } from '@agoric/swingset-vat/src/vats/network/multiaddr.js'; | ||
|
||
/** | ||
* Return a source-prefixed version of the denomination, as specified in | ||
* ICS20-1. | ||
* | ||
* @param {Address} addr | ||
* @param {Denom} denom | ||
*/ | ||
const sourcePrefixedDenom = (addr, denom) => { | ||
const ma = parse(addr); | ||
|
||
const ibcPort = ma.find(([protocol]) => protocol === 'ibc-port'); | ||
assert(ibcPort, X`${addr} does not contain an IBC port`); | ||
const ibcChannel = ma.find(([protocol]) => protocol === 'ibc-channel'); | ||
assert(ibcChannel, X`${addr} does not contain an IBC channel`); | ||
|
||
return `${ibcPort[1]}/${ibcChannel[1]}/${denom}`; | ||
}; | ||
|
||
/** @type {DenomTransformer} */ | ||
const transformer = { | ||
getDenomsForLocalPeg: async (denom, _localAddress, remoteAddress) => { | ||
return { | ||
sendDenom: denom, | ||
receiveDenom: sourcePrefixedDenom(remoteAddress, denom), | ||
}; | ||
}, | ||
getDenomsForRemotePeg: async (denom, localAddress, _remoteAddress) => { | ||
return { | ||
sendDenom: sourcePrefixedDenom(localAddress, denom), | ||
receiveDenom: denom, | ||
}; | ||
}, | ||
}; | ||
|
||
export const IBCSourceTraceDenomTransformer = Far( | ||
'IBC source trace denom transformer', | ||
transformer, | ||
); |
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
Oops, something went wrong.