11import { FiberClient } from "../client.js" ;
22import { Channel , Hash256 , Script } from "../types.js" ;
3+ import {
4+ decimalToU128 ,
5+ decimalToU64 ,
6+ u128ToDecimal ,
7+ u64ToDecimal ,
8+ } from "../utils/number.js" ;
39
410export class ChannelModule {
511 constructor ( private client : FiberClient ) { }
@@ -9,35 +15,71 @@ export class ChannelModule {
915 */
1016 async openChannel ( params : {
1117 peer_id : string ;
12- funding_amount : bigint ;
18+ funding_amount : string ;
1319 public ?: boolean ;
1420 funding_udt_type_script ?: Script ;
1521 shutdown_script ?: Script ;
16- commitment_delay_epoch ?: bigint ;
17- commitment_fee_rate ?: bigint ;
18- funding_fee_rate ?: bigint ;
19- tlc_expiry_delta ?: bigint ;
20- tlc_min_value ?: bigint ;
21- tlc_fee_proportional_millionths ?: bigint ;
22- max_tlc_value_in_flight ?: bigint ;
23- max_tlc_number_in_flight ?: bigint ;
22+ commitment_delay_epoch ?: string ;
23+ commitment_fee_rate ?: string ;
24+ funding_fee_rate ?: string ;
25+ tlc_expiry_delta ?: string ;
26+ tlc_min_value ?: string ;
27+ tlc_fee_proportional_millionths ?: string ;
28+ max_tlc_value_in_flight ?: string ;
29+ max_tlc_number_in_flight ?: string ;
2430 } ) : Promise < Hash256 > {
25- return this . client . call ( "open_channel" , [ params ] ) ;
31+ const u128Params = {
32+ ...params ,
33+ funding_amount : decimalToU128 ( params . funding_amount ) ,
34+ commitment_delay_epoch : params . commitment_delay_epoch
35+ ? decimalToU128 ( params . commitment_delay_epoch )
36+ : undefined ,
37+ commitment_fee_rate : params . commitment_fee_rate
38+ ? decimalToU128 ( params . commitment_fee_rate )
39+ : undefined ,
40+ funding_fee_rate : params . funding_fee_rate
41+ ? decimalToU64 ( params . funding_fee_rate )
42+ : undefined ,
43+ tlc_expiry_delta : params . tlc_expiry_delta
44+ ? decimalToU64 ( params . tlc_expiry_delta )
45+ : undefined ,
46+ tlc_min_value : params . tlc_min_value
47+ ? decimalToU128 ( params . tlc_min_value )
48+ : undefined ,
49+ tlc_fee_proportional_millionths : params . tlc_fee_proportional_millionths
50+ ? decimalToU128 ( params . tlc_fee_proportional_millionths )
51+ : undefined ,
52+ max_tlc_value_in_flight : params . max_tlc_value_in_flight
53+ ? decimalToU64 ( params . max_tlc_value_in_flight )
54+ : undefined ,
55+ } ;
56+ return this . client . call ( "open_channel" , [ u128Params ] ) ;
2657 }
2758
2859 /**
2960 * Accept a channel
3061 */
3162 async acceptChannel ( params : {
3263 temporary_channel_id : string ;
33- funding_amount : bigint ;
34- max_tlc_value_in_flight : bigint ;
35- max_tlc_number_in_flight : bigint ;
36- tlc_min_value : bigint ;
37- tlc_fee_proportional_millionths : bigint ;
38- tlc_expiry_delta : bigint ;
64+ funding_amount : string ;
65+ max_tlc_value_in_flight : string ;
66+ max_tlc_number_in_flight : string ;
67+ tlc_min_value : string ;
68+ tlc_fee_proportional_millionths : string ;
69+ tlc_expiry_delta : string ;
3970 } ) : Promise < void > {
40- return this . client . call ( "accept_channel" , [ params ] ) ;
71+ const u128Params = {
72+ ...params ,
73+ funding_amount : decimalToU128 ( params . funding_amount ) ,
74+ max_tlc_value_in_flight : decimalToU128 ( params . max_tlc_value_in_flight ) ,
75+ max_tlc_number_in_flight : decimalToU128 ( params . max_tlc_number_in_flight ) ,
76+ tlc_min_value : decimalToU128 ( params . tlc_min_value ) ,
77+ tlc_fee_proportional_millionths : decimalToU128 (
78+ params . tlc_fee_proportional_millionths ,
79+ ) ,
80+ tlc_expiry_delta : decimalToU128 ( params . tlc_expiry_delta ) ,
81+ } ;
82+ return this . client . call ( "accept_channel" , [ u128Params ] ) ;
4183 }
4284
4385 /**
@@ -47,7 +89,6 @@ export class ChannelModule {
4789 * @returns Promise<void>
4890 */
4991 async abandonChannel ( channelId : Hash256 ) : Promise < void > {
50- console . log ( 11111 , channelId ) ;
5192 if ( ! channelId ) {
5293 throw new Error ( "Channel ID cannot be empty" ) ;
5394 }
@@ -89,7 +130,21 @@ export class ChannelModule {
89130 "list_channels" ,
90131 [ { } ] ,
91132 ) ;
92- return response . channels ;
133+ return response . channels . map ( ( channel ) => ( {
134+ ...channel ,
135+ local_balance : u128ToDecimal ( channel . local_balance ) ,
136+ remote_balance : u128ToDecimal ( channel . remote_balance ) ,
137+ offered_tlc_balance : u128ToDecimal ( channel . offered_tlc_balance ) ,
138+ received_tlc_balance : u128ToDecimal ( channel . received_tlc_balance ) ,
139+ tlc_expiry_delta : u128ToDecimal ( channel . tlc_expiry_delta ) ,
140+ tlc_fee_proportional_millionths : u128ToDecimal (
141+ channel . tlc_fee_proportional_millionths ,
142+ ) ,
143+ created_at : u64ToDecimal ( channel . created_at , true ) ,
144+ last_updated_at : channel . last_updated_at
145+ ? u64ToDecimal ( channel . last_updated_at , true )
146+ : "" ,
147+ } ) ) ;
93148 }
94149
95150 /**
0 commit comments