-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
196 additions
and
59 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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
export { Query as IbcChannelService } from '../../gen/ibc/core/channel/v1/query_connect.js'; | ||
export { Msg as IbcChannelMsgService } from '../../gen/ibc/core/channel/v1/tx_connect.js'; | ||
|
||
export { Query as IbcClientService } from '../../gen/ibc/core/client/v1/query_connect.js'; | ||
export { Msg as IbcClientMsgService } from '../../gen/ibc/core/client/v1/tx_connect.js'; | ||
export { Msg as IbcChannelMsgService } from '../../gen/ibc/core/channel/v1/tx_connect.js'; | ||
|
||
export { Query as IbcConnectionService } from '../../gen/ibc/core/connection/v1/query_connect.js'; | ||
export { Msg as IbcConnectionMsgService } from '../../gen/ibc/core/connection/v1/tx_connect.js'; |
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
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,24 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
import { parseIntoAddr } from './address.js'; | ||
|
||
describe('parseIntoAddr', () => { | ||
test('works with compat', () => { | ||
expect(() => | ||
parseIntoAddr( | ||
'penumbracompat1147mfall0zr6am5r45qkwht7xqqrdsp50czde7empv7yq2nk3z8yyfh9k9520ddgswkmzar22vhz9dwtuem7uxw0qytfpv7lk3q9dp8ccaw2fn5c838rfackazmgf3ahhwqq0da', | ||
), | ||
).not.toThrow(); | ||
}); | ||
|
||
test('works with normal addresses', () => { | ||
expect(() => | ||
parseIntoAddr( | ||
'penumbra1e8k5cyds484dxvapeamwveh5khqv4jsvyvaf5wwxaaccgfghm229qw03pcar3ryy8smptevstycch0qk3uu0rgkvtjpxy3cu3rjd0agawqtlz6erev28a6sg69u7cxy0t02nd4', | ||
), | ||
).not.toThrow(); | ||
}); | ||
|
||
test('raises on invalid addresses', () => { | ||
expect(() => parseIntoAddr('not_valid_format')).toThrow(); | ||
}); | ||
}); |
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,10 @@ | ||
import { Address } from '@penumbra-zone/protobuf/penumbra/core/keys/v1/keys_pb'; | ||
import { addressFromBech32m } from '@penumbra-zone/bech32m/penumbra'; | ||
import { compatAddressFromBech32, isCompatAddress } from '@penumbra-zone/bech32m/penumbracompat1'; | ||
|
||
export const parseIntoAddr = (addrStr: string): Address => { | ||
if (isCompatAddress(addrStr)) { | ||
return new Address(compatAddressFromBech32(addrStr)); | ||
} | ||
return new Address(addressFromBech32m(addrStr)); | ||
}; |
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
141 changes: 141 additions & 0 deletions
141
packages/ui/components/ui/tx/actions-views/ibc-relay.tsx
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,141 @@ | ||
import { ViewBox } from '../viewbox'; | ||
import { ActionDetails } from './action-details'; | ||
import { | ||
FungibleTokenPacketData, | ||
IbcRelay, | ||
} from '@penumbra-zone/protobuf/penumbra/core/component/ibc/v1/ibc_pb'; | ||
import { MsgRecvPacket } from '@penumbra-zone/protobuf/ibc/core/channel/v1/tx_pb'; | ||
import { MsgUpdateClient } from '@penumbra-zone/protobuf/ibc/core/client/v1/tx_pb'; | ||
import { UnimplementedView } from './unimplemented-view.tsx'; | ||
import { uint8ArrayToBase64 } from '@penumbra-zone/types/base64'; | ||
import { getUtcTime } from './isc20-withdrawal.tsx'; | ||
import { useMemo } from 'react'; | ||
|
||
// Packet data stored as json string encoded into bytes | ||
const parsePacket = ({ packet }: MsgRecvPacket): FungibleTokenPacketData | undefined => { | ||
if (!packet?.data) { | ||
return undefined; | ||
} | ||
|
||
try { | ||
const dataString = new TextDecoder().decode(packet.data); | ||
return FungibleTokenPacketData.fromJsonString(dataString); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
}; | ||
|
||
const MsgResvComponent = ({ packet }: { packet: MsgRecvPacket }) => { | ||
const packetData = useMemo(() => parsePacket(packet), [packet]); | ||
|
||
return ( | ||
<ViewBox | ||
label='IBC Relay: Msg Received' | ||
visibleContent={ | ||
<ActionDetails> | ||
{!!packetData?.sender && ( | ||
<ActionDetails.Row label='Sender'> | ||
<ActionDetails.TruncatedText>{packetData.sender}</ActionDetails.TruncatedText> | ||
</ActionDetails.Row> | ||
)} | ||
{!!packetData?.receiver && ( | ||
<ActionDetails.Row label='Receiver'> | ||
<ActionDetails.TruncatedText>{packetData.receiver}</ActionDetails.TruncatedText> | ||
</ActionDetails.Row> | ||
)} | ||
{!!packetData?.denom && ( | ||
<ActionDetails.Row label='Denom'>{packetData.denom}</ActionDetails.Row> | ||
)} | ||
{!!packetData?.amount && ( | ||
<ActionDetails.Row label='Amount'>{packetData.amount}</ActionDetails.Row> | ||
)} | ||
{packetData && 'memo' in packetData && ( | ||
<ActionDetails.Row label='Memo'>{packetData.memo}</ActionDetails.Row> | ||
)} | ||
{!!packet.packet?.sequence && ( | ||
<ActionDetails.Row label='Sequence'>{Number(packet.packet.sequence)}</ActionDetails.Row> | ||
)} | ||
{!!packet.packet?.sourcePort && ( | ||
<ActionDetails.Row label='Source Port'>{packet.packet.sourcePort}</ActionDetails.Row> | ||
)} | ||
{!!packet.packet?.sourceChannel && ( | ||
<ActionDetails.Row label='Source Channel'> | ||
{packet.packet.sourceChannel} | ||
</ActionDetails.Row> | ||
)} | ||
{!!packet.packet?.destinationPort && ( | ||
<ActionDetails.Row label='Destination Port'> | ||
{packet.packet.destinationPort} | ||
</ActionDetails.Row> | ||
)} | ||
{!!packet.packet?.destinationChannel && ( | ||
<ActionDetails.Row label='Destination Channel'> | ||
{packet.packet.destinationChannel} | ||
</ActionDetails.Row> | ||
)} | ||
{!!packet.packet?.timeoutHeight?.revisionHeight && ( | ||
<ActionDetails.Row label='Timeout revision height'> | ||
{Number(packet.packet.timeoutHeight.revisionHeight)} | ||
</ActionDetails.Row> | ||
)} | ||
{!!packet.packet?.timeoutHeight?.revisionNumber && ( | ||
<ActionDetails.Row label='Timeout revision number'> | ||
{Number(packet.packet.timeoutHeight.revisionNumber)} | ||
</ActionDetails.Row> | ||
)} | ||
{!!packet.packet?.timeoutTimestamp && ( | ||
<ActionDetails.Row label='Timeout timestamp'> | ||
{getUtcTime(packet.packet.timeoutTimestamp)} | ||
</ActionDetails.Row> | ||
)} | ||
<ActionDetails.Row label='Signer'>{packet.signer}</ActionDetails.Row> | ||
{!!packet.proofHeight?.revisionHeight && ( | ||
<ActionDetails.Row label='Proof revision height'> | ||
{Number(packet.proofHeight.revisionHeight)} | ||
</ActionDetails.Row> | ||
)} | ||
{!!packet.proofHeight?.revisionNumber && ( | ||
<ActionDetails.Row label='Proof revision number'> | ||
{Number(packet.proofHeight.revisionNumber)} | ||
</ActionDetails.Row> | ||
)} | ||
<ActionDetails.Row label='Proof commitment'> | ||
<ActionDetails.TruncatedText> | ||
{uint8ArrayToBase64(packet.proofCommitment)} | ||
</ActionDetails.TruncatedText> | ||
</ActionDetails.Row> | ||
</ActionDetails> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
const UpdateClientComponent = ({ update }: { update: MsgUpdateClient }) => { | ||
return ( | ||
<ViewBox | ||
label='IBC Relay: Update Client' | ||
visibleContent={ | ||
<ActionDetails> | ||
<ActionDetails.Row label='Client id'>{update.clientId}</ActionDetails.Row> | ||
<ActionDetails.Row label='Signer'>{update.signer}</ActionDetails.Row> | ||
</ActionDetails> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export const IbcRelayComponent = ({ value }: { value: IbcRelay }) => { | ||
if (value.rawAction?.is(MsgRecvPacket.typeName)) { | ||
const packet = new MsgRecvPacket(); | ||
value.rawAction.unpackTo(packet); | ||
return <MsgResvComponent packet={packet} />; | ||
} | ||
|
||
if (value.rawAction?.is(MsgUpdateClient.typeName)) { | ||
const update = new MsgUpdateClient(); | ||
value.rawAction.unpackTo(update); | ||
return <UpdateClientComponent update={update} />; | ||
} | ||
|
||
return <UnimplementedView label='IBC Relay' />; | ||
}; |
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