-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improved print events for bridge functions
- Loading branch information
1 parent
c3741ed
commit 3027586
Showing
5 changed files
with
189 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'bridge-ui': minor | ||
--- | ||
|
||
Added better `print` events to major contract calls, which allows for better off-chain monitoring. |
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 |
---|---|---|
|
@@ -39,3 +39,4 @@ yarn-error.log* | |
|
||
settings/Testnet.toml | ||
.clarinet | ||
history.txt |
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,93 @@ | ||
import { contracts } from './clarigen/single'; | ||
import type { TypedAbiFunction } from '@clarigen/core'; | ||
|
||
type ResponseType<T> = T extends TypedAbiFunction<unknown[], infer R> ? R : never; | ||
|
||
type BridgeFunctions = typeof contracts['bridge']['functions']; | ||
|
||
type InboundSwapResponse = NonNullable<ResponseType<BridgeFunctions['getInboundSwap']>>; | ||
|
||
type InboundSwapMeta = NonNullable<ResponseType<BridgeFunctions['getInboundMeta']>>; | ||
|
||
type OutboundSwapResponse = NonNullable<ResponseType<BridgeFunctions['getOutboundSwap']>>; | ||
|
||
export type InboundSwapFull = InboundSwapResponse & InboundSwapMeta; | ||
|
||
export type EscrowPrint = InboundSwapFull & { | ||
topic: 'escrow'; | ||
txid: Uint8Array; | ||
}; | ||
|
||
export type FinalizeInboundPrint = InboundSwapResponse & { | ||
topic: 'finalize-inbound'; | ||
preimage: Uint8Array; | ||
txid: Uint8Array; | ||
}; | ||
|
||
export type RevokeInboundPrint = InboundSwapResponse & { | ||
topic: 'revoke-inbound'; | ||
txid: Uint8Array; | ||
}; | ||
|
||
export type InitiateOutboundPrint = OutboundSwapResponse & { | ||
topic: 'initiate-outbound'; | ||
'swap-id': BigInt; | ||
}; | ||
|
||
export type FinalizeOutboundPrint = OutboundSwapResponse & { | ||
topic: 'finalize-outbound'; | ||
'swap-id': BigInt; | ||
txid: Uint8Array; | ||
}; | ||
|
||
export type RevokeOutboundPrint = OutboundSwapResponse & { | ||
topic: 'revoke-outbound'; | ||
'swap-id': BigInt; | ||
}; | ||
|
||
export type Prints = | ||
| EscrowPrint | ||
| FinalizeInboundPrint | ||
| RevokeInboundPrint | ||
| InitiateOutboundPrint | ||
| FinalizeOutboundPrint | ||
| RevokeOutboundPrint; | ||
|
||
export const isEscrowPrint = (val: Prints): val is EscrowPrint => val.topic === 'escrow'; | ||
export const isFinalizeInboundPrint = (val: Prints): val is FinalizeInboundPrint => | ||
val.topic === 'finalize-inbound'; | ||
export const isRevokeInboundPrint = (val: Prints): val is RevokeInboundPrint => | ||
val.topic === 'revoke-inbound'; | ||
export const isInitiateOutboundPrint = (val: Prints): val is InitiateOutboundPrint => | ||
val.topic === 'initiate-outbound'; | ||
export const isFinalizeOutboundPrint = (val: Prints): val is FinalizeOutboundPrint => | ||
val.topic === 'finalize-outbound'; | ||
export const isRevokeOutboundPrint = (val: Prints): val is RevokeOutboundPrint => | ||
val.topic === 'revoke-outbound'; | ||
|
||
export function getEventWithPrint<T extends Prints>(prints: Prints[], topic: T['topic']): T { | ||
const [found] = prints.filter(p => p.topic === topic); | ||
if (typeof found === 'undefined') { | ||
throw new Error(`No print with topic '${topic}'`); | ||
} | ||
return found as T; | ||
} | ||
|
||
export function getEscrowPrint(prints: Prints[]) { | ||
return getEventWithPrint<EscrowPrint>(prints, 'escrow'); | ||
} | ||
export function getFinalizeInboundPrint(prints: Prints[]) { | ||
return getEventWithPrint<FinalizeInboundPrint>(prints, 'finalize-inbound'); | ||
} | ||
export function getRevokeInboundPrint(prints: Prints[]) { | ||
return getEventWithPrint<RevokeInboundPrint>(prints, 'revoke-inbound'); | ||
} | ||
export function getInitiateOutboundPrint(prints: Prints[]) { | ||
return getEventWithPrint<InitiateOutboundPrint>(prints, 'initiate-outbound'); | ||
} | ||
export function getFinalizeOutboundPrint(prints: Prints[]) { | ||
return getEventWithPrint<FinalizeOutboundPrint>(prints, 'finalize-outbound'); | ||
} | ||
export function getRevokeOutboundPrint(prints: Prints[]) { | ||
return getEventWithPrint<RevokeOutboundPrint>(prints, 'revoke-outbound'); | ||
} |
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