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

Support Bitcoin Core v22 RPC for JSON export #6123

Merged
merged 3 commits into from Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 3 additions & 8 deletions core/src/main/java/bisq/core/dao/node/full/RpcService.java
Expand Up @@ -352,14 +352,9 @@ private static RawTx getTxFromRawTransaction(RawDtoTransaction rawDtoTx,
}
}
}
String address = null;
try {
address = new Script(Hex.decode(scriptPubKey.getHex()))
.getToAddress(Config.baseCurrencyNetworkParameters()).toString();
} catch (Exception ex) {
// certain scripts e.g. OP_RETURN do not resolve to an address
// in that case do not provide an address to the RawTxOutput
}
// We don't support raw MS which are the only case where scriptPubKey.getAddresses()>1
String address = scriptPubKey.getAddresses() != null &&
scriptPubKey.getAddresses().size() == 1 ? scriptPubKey.getAddresses().get(0) : null;
PubKeyScript pubKeyScript = new PubKeyScript(scriptPubKey);
return new RawTxOutput(rawDtoTxOutput.getN(),
BigDecimal.valueOf(rawDtoTxOutput.getValue()).movePointRight(8).longValueExact(),
Expand Down
Expand Up @@ -19,17 +19,22 @@

import bisq.core.dao.state.model.blockchain.ScriptType;

import bisq.common.config.Config;
import bisq.common.util.Hex;

import org.bitcoinj.script.Script;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import java.util.List;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({"asm", "hex", "reqSigs", "type", "addresses"})
Expand All @@ -39,4 +44,33 @@ public class DtoPubKeyScript {
private Integer reqSigs;
private ScriptType type;
private List<String> addresses;
@JsonCreator
DtoPubKeyScript(
@JsonProperty("asm") String asm,
@JsonProperty("hex") String hex,
@JsonProperty("reqSigs") Integer reqSigs,
@JsonProperty("type") ScriptType type,
@JsonProperty("addresses") List<String> addresses) {
super();
this.asm = asm;
this.hex = hex;
this.reqSigs = reqSigs;
this.type = type;
this.addresses = addresses;
if (addresses == null) {
// >> addresses are not provided by bitcoin RPC from v22 onwards. <<
// However they are exported into the DAO classes (and therefore a component of the DAO state hash)
// so we must generate address from the hex script using BitcoinJ.
// (n.b. the DAO only ever uses/expects one address)
try {
String address = new Script(Hex.decode(hex))
.getToAddress(Config.baseCurrencyNetworkParameters()).toString();
this.addresses = List.of(address);
this.reqSigs = 1;
} catch (Exception ex) {
// certain scripts e.g. OP_RETURN do not resolve to an address
// in that case do not provide an address to the RawTxOutput
}
}
}
}