@@ -86,6 +86,8 @@ enum class LdkErrors {
8686 invoice_create_failed,
8787 init_scorer_failed,
8888 channel_close_fail,
89+ start_create_channel_fail,
90+ fund_channel_fail,
8991 channel_accept_fail,
9092 spend_outputs_fail,
9193 failed_signing_request,
@@ -126,6 +128,8 @@ enum class LdkCallbackResponses {
126128 ldk_restart,
127129 accept_channel_success,
128130 close_channel_success,
131+ start_create_channel_fail,
132+ fund_channel_success,
129133 file_write_success,
130134 backup_client_setup_success,
131135 backup_restore_success,
@@ -764,6 +768,54 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
764768 handleResolve(promise, LdkCallbackResponses .close_channel_success)
765769 }
766770
771+ @ReactMethod
772+ fun createChannel (counterPartyNodeId : String , channelValueSats : Double , pushSats : Double , promise : Promise ) {
773+ channelManager ? : return handleReject(promise, LdkErrors .init_channel_manager)
774+ keysManager ? : return handleReject(promise, LdkErrors .init_keys_manager)
775+
776+ val theirNetworkKey = counterPartyNodeId.hexa()
777+ val channelValueSatoshis = channelValueSats.toLong()
778+ val pushMsat = pushSats.toLong() * 1000
779+ val userChannelIdBytes = ByteArray (16 )
780+ Random ().nextBytes(userChannelIdBytes)
781+ val userChannelId = UInt128 (userChannelIdBytes)
782+
783+ val tempChannelId = ChannelId .temporary_from_entropy_source(keysManager!! .inner.as_EntropySource())
784+
785+ val res = channelManager!! .create_channel(
786+ theirNetworkKey,
787+ channelValueSatoshis,
788+ pushMsat,
789+ userChannelId,
790+ tempChannelId,
791+ UserConfig .with_default()
792+ )
793+
794+ if (! res.is_ok) {
795+ return handleReject(promise, LdkErrors .start_create_channel_fail)
796+ }
797+
798+ handleResolve(promise, LdkCallbackResponses .start_create_channel_fail)
799+ }
800+
801+ @ReactMethod
802+ fun fundChannel (temporaryChannelId : String , counterPartyNodeId : String , fundingTransaction : String , promise : Promise ) {
803+ channelManager ? : return handleReject(promise, LdkErrors .init_channel_manager)
804+
805+ val res = channelManager!! .funding_transaction_generated(
806+ ChannelId .of(temporaryChannelId.hexa()),
807+ counterPartyNodeId.hexa(),
808+ fundingTransaction.hexa()
809+ )
810+
811+ if (res.is_ok) {
812+ handleResolve(promise, LdkCallbackResponses .fund_channel_success)
813+ return
814+ }
815+
816+ handleReject(promise, LdkErrors .fund_channel_fail)
817+ }
818+
767819 @ReactMethod
768820 fun forceCloseAllChannels (broadcastLatestTx : Boolean , promise : Promise ) {
769821 channelManager ? : return handleReject(promise, LdkErrors .init_channel_manager)
0 commit comments