Skip to content

Commit

Permalink
Re-use existing script-to-address logic
Browse files Browse the repository at this point in the history
  • Loading branch information
coderofstuff committed Sep 6, 2024
1 parent 3deaf0d commit 1695480
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions rpc/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ use kaspa_rpc_core::{
notify::connection::ChannelConnection,
Notification, RpcError, RpcResult,
};
use kaspa_txscript::opcodes::codes;
use kaspa_txscript::{extract_script_pub_key_address, pay_to_address_script};
use kaspa_utils::expiring_cache::ExpiringCache;
use kaspa_utils::sysinfo::SystemInfo;
Expand Down Expand Up @@ -789,27 +788,13 @@ NOTE: This error usually indicates an RPC conversion error between the node and
) -> RpcResult<GetUtxoReturnAddressResponse> {
let session = self.consensus_manager.consensus().session().await;

let mut return_address = None;

// Convert a SPK to an Address
if let Some(spk) = session.async_get_utxo_return_script_public_key(request.txid, request.accepting_block_daa_score).await {
let script = spk.script();

// Standard Address scripts are only either 34 or 35 in length:
if script.len() == 34 && script[0] == codes::OpData32 && script[33] == codes::OpCheckSig {
// This is a standard Schnorr Address
return_address = Some(RpcAddress::new(self.config.prefix(), kaspa_addresses::Version::PubKey, &script[1..33]));
} else if script.len() == 35 {
// Could be ECDSA address OR P2SH
if script[0] == codes::OpData33 && script[34] == codes::OpCheckSigECDSA {
// This is an standard ECDSA Address
return_address =
Some(RpcAddress::new(self.config.prefix(), kaspa_addresses::Version::PubKeyECDSA, &script[1..34]));
} else if script[0] == codes::OpBlake2b && script[1] == codes::OpData32 && script[34] == codes::OpEqual {
// This is a standard P2SH Address
return_address = Some(RpcAddress::new(self.config.prefix(), kaspa_addresses::Version::ScriptHash, &script[2..34]));
}
}
let return_address = if let Some(spk) =
session.async_get_utxo_return_script_public_key(request.txid, request.accepting_block_daa_score).await
{
extract_script_pub_key_address(&spk, self.config.prefix()).ok()
} else {
None
};

Ok(GetUtxoReturnAddressResponse { return_address })
Expand Down

0 comments on commit 1695480

Please sign in to comment.