-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wallet: Elements Core (elementsd) support
Changes: - Elements Core (elementsd) Process Manager - ElementsRegtestSetup - Implemented RPC calls: - claimpegin - createwallet - finalizepsbt - generatetoaddress - getbalance - L-BTC - Liquid Assets - getnewaddress - getpeginaddress - getrawtransaction - gettxoutproof - issueasset - listtransactions - listunspent - listwallets - loadwallet - sendrawtransaction - sendtoaddress - L-BTC - Liquid Assets - signmessage - stop - unloadwallet - verifymessage - walletpassphrase
- Loading branch information
Showing
34 changed files
with
1,816 additions
and
9 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
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,37 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.wallets; | ||
|
||
import lombok.Getter; | ||
|
||
public enum WalletBackend { | ||
BITCOIND("Bitcoin Core"), | ||
ELEMENTSD("Elements Core"); | ||
|
||
@Getter | ||
private final String label; | ||
|
||
WalletBackend(String label) { | ||
this.label = label; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return label; | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
wallets/src/main/java/bisq/wallets/elementsd/ElementsdConfig.java
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,23 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.wallets.elementsd; | ||
|
||
import bisq.wallets.rpc.RpcConfig; | ||
|
||
public record ElementsdConfig(RpcConfig bitcoindRpcConfig, RpcConfig elementsdRpcConfig) { | ||
} |
94 changes: 94 additions & 0 deletions
94
wallets/src/main/java/bisq/wallets/elementsd/LiquidWallet.java
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,94 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.wallets.elementsd; | ||
|
||
import bisq.wallets.AddressType; | ||
import bisq.wallets.Wallet; | ||
import bisq.wallets.bitcoind.rpc.BitcoindWallet; | ||
import bisq.wallets.elementsd.rpc.ElementsdDaemon; | ||
import bisq.wallets.elementsd.rpc.ElementsdWallet; | ||
import bisq.wallets.exceptions.WalletInitializationFailedException; | ||
import bisq.wallets.model.Transaction; | ||
import bisq.wallets.model.Utxo; | ||
import bisq.wallets.rpc.RpcClient; | ||
import bisq.wallets.rpc.RpcClientFactory; | ||
import bisq.wallets.rpc.RpcConfig; | ||
|
||
import java.net.MalformedURLException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
public class LiquidWallet implements Wallet { | ||
private final Path walletPath; | ||
|
||
private final ElementsdDaemon daemon; | ||
private final ElementsdWallet wallet; | ||
|
||
public LiquidWallet(Path walletPath, RpcConfig rpcConfig) { | ||
this.walletPath = walletPath; | ||
|
||
try { | ||
RpcClient rpcClient = RpcClientFactory.create(rpcConfig); | ||
daemon = new ElementsdDaemon(rpcClient); | ||
wallet = new ElementsdWallet(rpcClient); | ||
} catch (MalformedURLException e) { | ||
throw new WalletInitializationFailedException("Couldn't initialize WalletService", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void initialize(String walletPassphrase) { | ||
daemon.createOrLoadWallet(walletPath, walletPassphrase); | ||
wallet.walletPassphrase(walletPassphrase, BitcoindWallet.DEFAULT_WALLET_TIMEOUT); | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
daemon.unloadWallet(walletPath); | ||
} | ||
|
||
@Override | ||
public double getBalance() { | ||
return wallet.getLBtcBalance(); | ||
} | ||
|
||
@Override | ||
public String getNewAddress(AddressType addressType, String label) { | ||
return wallet.getNewAddress(addressType, label); | ||
} | ||
|
||
@Override | ||
public String signMessage(String address, String message) { | ||
return wallet.signMessage(address, message); | ||
} | ||
|
||
@Override | ||
public List<? extends Transaction> listTransactions() { | ||
return wallet.listTransactions(1000); | ||
} | ||
|
||
@Override | ||
public List<? extends Utxo> listUnspent() { | ||
return wallet.listUnspent(); | ||
} | ||
|
||
@Override | ||
public String sendToAddress(String address, double amount) { | ||
return wallet.sendLBtcToAddress(address, amount); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
wallets/src/main/java/bisq/wallets/elementsd/process/ElementsdProcess.java
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,92 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.wallets.elementsd.process; | ||
|
||
import bisq.common.util.NetworkUtils; | ||
import bisq.wallets.NetworkType; | ||
import bisq.wallets.bitcoind.BitcoindProcess; | ||
import bisq.wallets.elementsd.ElementsdConfig; | ||
import bisq.wallets.elementsd.rpc.ElementsdDaemon; | ||
import bisq.wallets.exceptions.RpcCallFailureException; | ||
import bisq.wallets.process.ProcessConfig; | ||
import bisq.wallets.rpc.RpcClient; | ||
import bisq.wallets.rpc.RpcClientFactory; | ||
import bisq.wallets.rpc.RpcConfig; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
public class ElementsdProcess extends BitcoindProcess { | ||
private final ElementsdConfig elementsdConfig; | ||
|
||
public ElementsdProcess(ElementsdConfig elementsdConfig, Path dataDir) { | ||
super(elementsdConfig.elementsdRpcConfig(), dataDir); | ||
this.elementsdConfig = elementsdConfig; | ||
} | ||
|
||
@Override | ||
public ProcessConfig createProcessConfig() { | ||
RpcConfig bitcoindRpcConfig = elementsdConfig.bitcoindRpcConfig(); | ||
return new ProcessConfig( | ||
"elementsd", | ||
List.of( | ||
"-chain=" + getNetworkName(), | ||
"-datadir=" + dataDir.toAbsolutePath(), | ||
|
||
"-bind=127.0.0.1:" + NetworkUtils.findFreeSystemPort(), | ||
"-whitelist=127.0.0.1", | ||
|
||
"-rpcbind=127.0.0.1:" + rpcConfig.port(), | ||
"-rpcallowip=127.0.0.1", | ||
"-rpcuser=" + rpcConfig.user(), | ||
"-rpcpassword=" + rpcConfig.password(), | ||
|
||
"-mainchainrpchost=" + bitcoindRpcConfig.hostname(), | ||
"-mainchainrpcport=" + bitcoindRpcConfig.port(), | ||
"-mainchainrpcuser=" + bitcoindRpcConfig.user(), | ||
"-mainchainrpcpassword=" + bitcoindRpcConfig.password(), | ||
|
||
"-fallbackfee=0.00000001", | ||
"-txindex=1") | ||
); | ||
} | ||
|
||
@Override | ||
public void invokeStopRpcCall() throws IOException { | ||
try { | ||
RpcClient rpcClient = RpcClientFactory.create(rpcConfig); | ||
var chainBackend = new ElementsdDaemon(rpcClient); | ||
chainBackend.stop(); | ||
} catch (RpcCallFailureException e) { | ||
log.error("Failed to send stop command to elementsd.", e); | ||
} | ||
} | ||
|
||
private String getNetworkName() { | ||
NetworkType networkType = rpcConfig.networkType(); | ||
return switch (networkType) { | ||
case MAINNET -> ""; | ||
case REGTEST -> "elementsregtest"; | ||
case SIGNET -> "signet"; | ||
case TESTNET -> "liquidv1test"; | ||
}; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
wallets/src/main/java/bisq/wallets/elementsd/rpc/ElementsdDaemon.java
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,37 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.wallets.elementsd.rpc; | ||
|
||
import bisq.wallets.bitcoind.rpc.BitcoindDaemon; | ||
import bisq.wallets.bitcoind.rpc.calls.BitcoindGetTxOutProofRpcCall; | ||
import bisq.wallets.elementsd.rpc.calls.ElementsdStopRpcCall; | ||
import bisq.wallets.rpc.RpcClient; | ||
|
||
import java.util.List; | ||
|
||
public class ElementsdDaemon extends BitcoindDaemon { | ||
public ElementsdDaemon(RpcClient rpcClient) { | ||
super(rpcClient); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
var rpcCall = new ElementsdStopRpcCall(); | ||
rpcClient.invokeAndValidate(rpcCall); | ||
} | ||
} |
Oops, something went wrong.