Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional configurability of ChannelHandshakeLimits force_announced_channel_preference #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ PODS:
- React-jsinspector (0.70.6)
- React-logger (0.70.6):
- glog
- react-native-ldk (0.0.76):
- react-native-ldk (0.0.77):
- React
- react-native-randombytes (3.6.1):
- React-Core
Expand Down Expand Up @@ -375,7 +375,7 @@ PODS:
- React-jsi (= 0.70.6)
- React-logger (= 0.70.6)
- React-perflogger (= 0.70.6)
- RNCAsyncStorage (1.17.11):
- RNCAsyncStorage (1.17.10):
- React-Core
- RNCClipboard (1.11.1):
- React-Core
Expand Down Expand Up @@ -593,7 +593,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: b4a65947391c658450151275aa406f2b8263178f
React-jsinspector: 60769e5a0a6d4b32294a2456077f59d0266f9a8b
React-logger: 1623c216abaa88974afce404dc8f479406bbc3a0
react-native-ldk: e042f888d7fa13cbbdde1a57fc0226867b7a15a1
react-native-ldk: 0d9f1a1c82b55140746c17fdcd85af0507bf7c09
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
react-native-tcp-socket: c1b7297619616b4c9caae6889bcb0aba78086989
React-perflogger: 8c79399b0500a30ee8152d0f9f11beae7fc36595
Expand All @@ -608,7 +608,7 @@ SPEC CHECKSUMS:
React-RCTVibration: c75ceef7aa60a33b2d5731ebe5800ddde40cefc4
React-runtimeexecutor: 15437b576139df27635400de0599d9844f1ab817
ReactCommon: 349be31adeecffc7986a0de875d7fb0dcf4e251c
RNCAsyncStorage: 8616bd5a58af409453ea4e1b246521bb76578d60
RNCAsyncStorage: 0c357f3156fcb16c8589ede67cc036330b6698ca
RNCClipboard: 2834e1c4af68697089cdd455ee4a4cdd198fa7dd
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
RNKeychain: ff836453cba46938e0e9e4c22e43d43fa2c90333
Expand Down
4 changes: 2 additions & 2 deletions lib/android/src/main/java/com/reactnativeldk/LdkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
}

@ReactMethod
fun initConfig(acceptInboundChannels: Boolean, manuallyAcceptInboundChannels: Boolean, announcedChannels: Boolean, minChannelHandshakeDepth: Double, promise: Promise) {
fun initConfig(acceptInboundChannels: Boolean, manuallyAcceptInboundChannels: Boolean, announcedChannels: Boolean, minChannelHandshakeDepth: Double, forceAnnouncedChannelPreference: Boolean, promise: Promise) {
if (userConfig !== null) {
return handleReject(promise, LdkErrors.already_init)
}
Expand All @@ -263,7 +263,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
userConfig!!._channel_handshake_config = channelHandshakeConfig

val channelHandshakeLimits = ChannelHandshakeLimits.with_default()
channelHandshakeLimits._force_announced_channel_preference = true
channelHandshakeLimits._force_announced_channel_preference = forceAnnouncedChannelPreference
channelHandshakeLimits._max_minimum_depth = minChannelHandshakeDepth.toInt()
userConfig!!._channel_handshake_limits = channelHandshakeLimits

Expand Down
1 change: 1 addition & 0 deletions lib/ios/Ldk.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ @interface RCT_EXTERN_MODULE(Ldk, NSObject)
manuallyAcceptInboundChannels:(BOOL *)manuallyAcceptInboundChannels
announcedChannels:(BOOL *)announcedChannels
minChannelHandshakeDepth:(NSInteger *)minChannelHandshakeDepth
forceAnnouncedChannelPreference:(BOOL *)forceAnnouncedChannelPreference
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(initNetworkGraph:(NSString *)genesisHash
Expand Down
4 changes: 2 additions & 2 deletions lib/ios/Ldk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class Ldk: NSObject {
}

@objc
func initConfig(_ acceptInboundChannels: Bool, manuallyAcceptInboundChannels: Bool, announcedChannels: Bool, minChannelHandshakeDepth: NSInteger, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
func initConfig(_ acceptInboundChannels: Bool, manuallyAcceptInboundChannels: Bool, announcedChannels: Bool, minChannelHandshakeDepth: NSInteger, forceAnnouncedChannelPreference: Bool, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
guard userConfig == nil else {
return handleReject(reject, .already_init)
}
Expand All @@ -236,7 +236,7 @@ class Ldk: NSObject {
userConfig!.set_channel_handshake_config(val: channelHandshakeConfig)

let channelHandshakeLimits = ChannelHandshakeLimits()
channelHandshakeLimits.set_force_announced_channel_preference(val: true)
channelHandshakeLimits.set_force_announced_channel_preference(val: forceAnnouncedChannelPreference)
userConfig!.set_channel_handshake_limits(val: channelHandshakeLimits)

return handleResolve(resolve, .config_init_success)
Expand Down
136 changes: 68 additions & 68 deletions lib/package.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
{
"name": "@synonymdev/react-native-ldk",
"title": "React Native LDK",
"version": "0.0.76",
"description": "React Native wrapper for LDK",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"README.md",
"android",
"ios",
"react-native-ldk.podspec",
"dist"
],
"keywords": [
"javascript",
"bitcoin",
"lightning",
"ldk"
],
"scripts": {
"build": "rm -rf dist && mkdir dist/ && tsc -p ./src",
"watch": "yarn run build -- -w",
"lint:check": "eslint . --ext .js,.jsx,.ts,.tsx",
"lint:fix": "eslint . --fix --ext .js,.jsx,.ts,.tsx",
"prepublish": "yarn lint:fix && yarn run build && npm --no-git-tag-version version patch",
"dev:save-ios-updates": "cp ../example/node_modules/@synonymdev/react-native-ldk/ios/*.{m,swift,h} ./ios && cp ../example/node_modules/@synonymdev/react-native-ldk/ios/Classes/*.swift ./ios/Classes/",
"dev:save-android-updates": "cp ../example/node_modules/@synonymdev/react-native-ldk/android/src/main/java/com/reactnativeldk/*.kt ./android/src/main/java/com/reactnativeldk/ && cp ../example/node_modules/@synonymdev/react-native-ldk/android/src/main/java/com/reactnativeldk/classes/*.kt ./android/src/main/java/com/reactnativeldk/classes/ && cp ../example/node_modules/@synonymdev/react-native-ldk/android/build.gradle ./android/",
"dev:update-example-dist": "yarn build && cp -R dist ../example/node_modules/@synonymdev/react-native-ldk",
"dev:example": "yarn dev:save-ios-updates && yarn dev:save-android-updates && yarn dev:update-example-dist"
},
"repository": {
"type": "git",
"url": "git+https://github.com/synonymdev/react-native-ldk.git",
"baseUrl": "https://github.com/synonymdev/react-native-ldk"
},
"author": "synonymdev",
"license": "MIT",
"licenseFilename": "LICENSE",
"peerDependencies": {
"react": "*",
"react-native": "*"
},
"devDependencies": {
"@react-native-community/eslint-config": "^2.0.0",
"@types/node": "^17.0.31",
"@types/react-native": "0.62.13",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^4.25.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard-with-typescript": "^21.0.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-standard": "^5.0.0",
"prettier": "^2.6.2",
"react": "^16.9.0",
"typescript": "^4.2.4"
},
"dependencies": {
"bitcoinjs-lib": "^6.0.2"
},
"bugs": {
"url": "https://github.com/synonymdev/react-native-ldk/issues"
},
"homepage": "https://github.com/synonymdev/react-native-ldk#readme"
"name": "@synonymdev/react-native-ldk",
"title": "React Native LDK",
"version": "0.0.77",
"description": "React Native wrapper for LDK",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"README.md",
"android",
"ios",
"react-native-ldk.podspec",
"dist"
],
"keywords": [
"javascript",
"bitcoin",
"lightning",
"ldk"
],
"scripts": {
"build": "rm -rf dist && mkdir dist/ && tsc -p ./src",
"watch": "yarn run build -- -w",
"lint:check": "eslint . --ext .js,.jsx,.ts,.tsx",
"lint:fix": "eslint . --fix --ext .js,.jsx,.ts,.tsx",
"prepublish": "yarn lint:fix && yarn run build && npm --no-git-tag-version version patch",
"dev:save-ios-updates": "cp ../example/node_modules/@synonymdev/react-native-ldk/ios/*.{m,swift,h} ./ios && cp ../example/node_modules/@synonymdev/react-native-ldk/ios/Classes/*.swift ./ios/Classes/",
"dev:save-android-updates": "cp ../example/node_modules/@synonymdev/react-native-ldk/android/src/main/java/com/reactnativeldk/*.kt ./android/src/main/java/com/reactnativeldk/ && cp ../example/node_modules/@synonymdev/react-native-ldk/android/src/main/java/com/reactnativeldk/classes/*.kt ./android/src/main/java/com/reactnativeldk/classes/ && cp ../example/node_modules/@synonymdev/react-native-ldk/android/build.gradle ./android/",
"dev:update-example-dist": "yarn build && cp -R dist ../example/node_modules/@synonymdev/react-native-ldk",
"dev:example": "yarn dev:save-ios-updates && yarn dev:save-android-updates && yarn dev:update-example-dist"
},
"repository": {
"type": "git",
"url": "git+https://github.com/synonymdev/react-native-ldk.git",
"baseUrl": "https://github.com/synonymdev/react-native-ldk"
},
"author": "synonymdev",
"license": "MIT",
"licenseFilename": "LICENSE",
"peerDependencies": {
"react": "*",
"react-native": "*"
},
"devDependencies": {
"@react-native-community/eslint-config": "^2.0.0",
"@types/node": "^17.0.31",
"@types/react-native": "0.62.13",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^4.25.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard-with-typescript": "^21.0.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-standard": "^5.0.0",
"prettier": "^2.6.2",
"react": "^16.9.0",
"typescript": "^4.2.4"
},
"dependencies": {
"bitcoinjs-lib": "^6.0.2"
},
"bugs": {
"url": "https://github.com/synonymdev/react-native-ldk/issues"
},
"homepage": "https://github.com/synonymdev/react-native-ldk#readme"
}
3 changes: 3 additions & 0 deletions lib/src/ldk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class LDK {
* @param manuallyAcceptInboundChannels
* @param announcedChannels
* @param minChannelHandshakeDepth
* @param forceAnnouncedChannelPreference
* @returns {Promise<Err<unknown> | Ok<Ok<string> | Err<string>>>}
*/
async initConfig(conf: TInitConfig): Promise<Result<string>> {
Expand All @@ -177,13 +178,15 @@ class LDK {
manuallyAcceptInboundChannels,
announcedChannels,
minChannelHandshakeDepth,
forceAnnouncedChannelPreference,
} = conf;
try {
const res = await NativeLDK.initConfig(
acceptInboundChannels,
manuallyAcceptInboundChannels,
announcedChannels,
minChannelHandshakeDepth,
forceAnnouncedChannelPreference,
);
this.writeDebugToLog('initConfig', conf);
return ok(res);
Expand Down
1 change: 1 addition & 0 deletions lib/src/lightning-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ class LightningManager {
manuallyAcceptInboundChannels: false,
announcedChannels: false,
minChannelHandshakeDepth: 1, //TODO Verify correct min
forceAnnouncedChannelPreference: false,
});
if (confRes.isErr()) {
return confRes;
Expand Down
1 change: 1 addition & 0 deletions lib/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export type TInitConfig = {
manuallyAcceptInboundChannels: boolean;
announcedChannels: boolean;
minChannelHandshakeDepth: number;
forceAnnouncedChannelPreference: boolean;
};

export enum ELdkLogLevels {
Expand Down