1- import { Hash , EventRecord } from "@polkadot/types/interfaces" ;
2- import { ApiTypes , AugmentedEvent } from "@polkadot/api/types" ;
3- import type { AnyTuple } from "@polkadot/types/types" ;
4- import { ApiPromise } from "@polkadot/api" ;
51import { KeyringPair } from "@polkadot/keyring/types" ;
62import { Bitcoin , BitcoinAmount , InterBtcAmount , MonetaryAmount } from "@interlay/monetary-js" ;
7- import { InterbtcPrimitivesVaultId } from "@polkadot/types/lookup" ;
8- import { ISubmittableResult } from "@polkadot/types/types" ;
3+ import { InterbtcPrimitivesVaultId } from "../../src/parachain" ;
94
10- import { newAccountId } from "../../src/utils" ;
5+
6+ import { getIssueRequestsFromExtrinsicResult , getRedeemRequestsFromExtrinsicResult , newAccountId } from "../../src/utils" ;
117import { BitcoinCoreClient } from "./bitcoin-core-client" ;
128import { stripHexPrefix } from "../../src/utils/encoding" ;
139import { Issue , IssueStatus , Redeem , RedeemStatus , WrappedCurrency } from "../../src/types" ;
@@ -28,48 +24,6 @@ export enum ExecuteRedeem {
2824 Auto ,
2925}
3026
31- /**
32- * @param events The EventRecord array returned after sending a transaction
33- * @param methodToCheck The name of the event method whose existence to check
34- * @returns The id associated with the transaction. If the EventRecord array does not
35- * contain required events, the function throws an error.
36- */
37- export function getRequestIdsFromEvents (
38- events : EventRecord [ ] ,
39- eventToFind : AugmentedEvent < ApiTypes , AnyTuple > ,
40- api : ApiPromise
41- ) : Hash [ ] {
42- const ids = new Array < Hash > ( ) ;
43- for ( const { event } of events ) {
44- if ( eventToFind . is ( event ) ) {
45- // the redeem id has type H256 and is the first item of the event data array
46- const id = api . createType ( "Hash" , event . data [ 0 ] ) ;
47- ids . push ( id ) ;
48- }
49- }
50-
51- if ( ids . length > 0 ) return ids ;
52- throw new Error ( "Transaction failed" ) ;
53- }
54-
55- export const getIssueRequestsFromExtrinsicResult = async (
56- interBtcApi : InterBtcApi ,
57- result : ISubmittableResult
58- ) : Promise < Array < Issue > > => {
59- const ids = getRequestIdsFromEvents ( result . events , interBtcApi . api . events . issue . RequestIssue , interBtcApi . api ) ;
60- const issueRequests = await interBtcApi . issue . getRequestsByIds ( ids ) ;
61- return issueRequests ;
62- } ;
63-
64- export const getRedeemRequestsFromExtrinsicResult = async (
65- interBtcApi : InterBtcApi ,
66- result : ISubmittableResult
67- ) : Promise < Array < Redeem > > => {
68- const ids = getRequestIdsFromEvents ( result . events , interBtcApi . api . events . redeem . RequestRedeem , interBtcApi . api ) ;
69- const redeemRequests = await interBtcApi . redeem . getRequestsByIds ( ids ) ;
70- return redeemRequests ;
71- } ;
72-
7327export async function issueSingle (
7428 interBtcApi : InterBtcApi ,
7529 bitcoinCoreClient : BitcoinCoreClient ,
0 commit comments