WIP: Fix send

This commit is contained in:
likho 2022-11-01 12:46:29 +02:00
parent 1949a61d5a
commit 4cac7645c8
2 changed files with 30 additions and 33 deletions
lib
services/coins/particl
utilities

View file

@ -430,7 +430,8 @@ class ParticlWallet extends CoinServiceAPI {
data: PaymentData( data: PaymentData(
redeem: P2WPKH( redeem: P2WPKH(
data: PaymentData(pubkey: node.publicKey), data: PaymentData(pubkey: node.publicKey),
network: _network) network: _network,
overridePrefix: particl.bech32!)
.data), .data),
network: _network) network: _network)
.data .data
@ -1200,7 +1201,7 @@ class ParticlWallet extends CoinServiceAPI {
@override @override
bool validateAddress(String address) { bool validateAddress(String address) {
return Address.validateAddress(address, _network); return Address.validateAddress(address, _network, particl.bech32!);
} }
@override @override
@ -1480,7 +1481,11 @@ class ParticlWallet extends CoinServiceAPI {
case DerivePathType.bip49: case DerivePathType.bip49:
address = P2SH( address = P2SH(
data: PaymentData( data: PaymentData(
redeem: P2WPKH(data: data, network: _network).data), redeem: P2WPKH(
data: data,
network: _network,
overridePrefix: particl.bech32!)
.data),
network: _network) network: _network)
.data .data
.address!; .address!;
@ -2223,9 +2228,6 @@ class ParticlWallet extends CoinServiceAPI {
Logging.instance.log("allTransactions length: ${allTransactions.length}", Logging.instance.log("allTransactions length: ${allTransactions.length}",
level: LogLevel.Info); level: LogLevel.Info);
Logging.instance
.log("allTransactions is: $allTransactions", level: LogLevel.Info);
final priceData = final priceData =
await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency); await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency);
Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero; Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero;
@ -2516,14 +2518,6 @@ class ParticlWallet extends CoinServiceAPI {
spendableOutputs.sort( spendableOutputs.sort(
(a, b) => b.status.confirmations.compareTo(a.status.confirmations)); (a, b) => b.status.confirmations.compareTo(a.status.confirmations));
Logging.instance.log("spendableOutputs.length: ${spendableOutputs.length}",
level: LogLevel.Info);
Logging.instance
.log("spendableOutputs: $spendableOutputs", level: LogLevel.Info);
Logging.instance.log("spendableSatoshiValue: $spendableSatoshiValue",
level: LogLevel.Info);
Logging.instance
.log("satoshiAmountToSend: $satoshiAmountToSend", level: LogLevel.Info);
// If the amount the user is trying to send is smaller than the amount that they have spendable, // If the amount the user is trying to send is smaller than the amount that they have spendable,
// then return 1, which indicates that they have an insufficient balance. // then return 1, which indicates that they have an insufficient balance.
if (spendableSatoshiValue < satoshiAmountToSend) { if (spendableSatoshiValue < satoshiAmountToSend) {
@ -2558,13 +2552,6 @@ class ParticlWallet extends CoinServiceAPI {
inputsBeingConsumed += 1; inputsBeingConsumed += 1;
} }
Logging.instance
.log("satoshisBeingUsed: $satoshisBeingUsed", level: LogLevel.Info);
Logging.instance
.log("inputsBeingConsumed: $inputsBeingConsumed", level: LogLevel.Info);
Logging.instance
.log('utxoObjectsToUse: $utxoObjectsToUse', level: LogLevel.Info);
// numberOfOutputs' length must always be equal to that of recipientsArray and recipientsAmtArray // numberOfOutputs' length must always be equal to that of recipientsArray and recipientsAmtArray
List<String> recipientsArray = [_recipientAddress]; List<String> recipientsArray = [_recipientAddress];
List<int> recipientsAmtArray = [satoshiAmountToSend]; List<int> recipientsAmtArray = [satoshiAmountToSend];
@ -2851,7 +2838,9 @@ class ParticlWallet extends CoinServiceAPI {
for (final output in tx["vout"] as List) { for (final output in tx["vout"] as List) {
final n = output["n"]; final n = output["n"];
if (n != null && n == utxosToUse[i].vout) { if (n != null && n == utxosToUse[i].vout) {
final address = output["scriptPubKey"]["address"] as String; Logging.instance.log("THIS OUTPUT IS ${output["scriptPubKey"]}",
level: LogLevel.Info, printFullLength: true);
final address = output["scriptPubKey"]["addresses"][0] as String;
if (!addressTxid.containsKey(address)) { if (!addressTxid.containsKey(address)) {
addressTxid[address] = <String>[]; addressTxid[address] = <String>[];
} }
@ -2870,6 +2859,9 @@ class ParticlWallet extends CoinServiceAPI {
// p2pkh / bip44 // p2pkh / bip44
final p2pkhLength = addressesP2PKH.length; final p2pkhLength = addressesP2PKH.length;
Logging.instance
.log("THE BIP44 LENGTH IS $p2pkhLength", level: LogLevel.Info);
if (p2pkhLength > 0) { if (p2pkhLength > 0) {
final receiveDerivations = await _fetchDerivations( final receiveDerivations = await _fetchDerivations(
chain: 0, chain: 0,
@ -2928,6 +2920,8 @@ class ParticlWallet extends CoinServiceAPI {
// p2sh / bip49 // p2sh / bip49
final p2shLength = addressesP2SH.length; final p2shLength = addressesP2SH.length;
Logging.instance
.log("THE BIP49 LENGTH IS $p2pkhLength", level: LogLevel.Info);
if (p2shLength > 0) { if (p2shLength > 0) {
final receiveDerivations = await _fetchDerivations( final receiveDerivations = await _fetchDerivations(
chain: 0, chain: 0,
@ -2946,7 +2940,8 @@ class ParticlWallet extends CoinServiceAPI {
data: PaymentData( data: PaymentData(
pubkey: Format.stringToUint8List( pubkey: Format.stringToUint8List(
receiveDerivation["pubKey"] as String)), receiveDerivation["pubKey"] as String)),
network: _network) network: _network,
overridePrefix: particl.bech32!)
.data; .data;
final redeemScript = p2wpkh.output; final redeemScript = p2wpkh.output;
@ -3027,19 +3022,20 @@ class ParticlWallet extends CoinServiceAPI {
// Add transaction output // Add transaction output
for (var i = 0; i < recipients.length; i++) { for (var i = 0; i < recipients.length; i++) {
txb.addOutput(recipients[i], satoshiAmounts[i]); txb.addOutput(recipients[i], satoshiAmounts[i], particl.bech32!);
} }
try { try {
// Sign the transaction accordingly // Sign the transaction accordingly
for (var i = 0; i < utxosToUse.length; i++) { for (var i = 0; i < utxosToUse.length; i++) {
final txid = utxosToUse[i].txid; final txid = utxosToUse[i].txid;
txb.sign( txb.sign(
vin: i, vin: i,
keyPair: utxoSigningData[txid]["keyPair"] as ECPair, keyPair: utxoSigningData[txid]["keyPair"] as ECPair,
witnessValue: utxosToUse[i].value, witnessValue: utxosToUse[i].value,
redeemScript: utxoSigningData[txid]["redeemScript"] as Uint8List?, redeemScript: utxoSigningData[txid]["redeemScript"] as Uint8List?,
); overridePrefix: particl.bech32!);
} }
} catch (e, s) { } catch (e, s) {
Logging.instance.log("Caught exception while signing transaction: $e\n$s", Logging.instance.log("Caught exception while signing transaction: $e\n$s",
@ -3047,7 +3043,8 @@ class ParticlWallet extends CoinServiceAPI {
rethrow; rethrow;
} }
final builtTx = txb.build(); final builtTx = txb.build(particl.bech32!);
print("BUILT TX IS $builtTx");
final vSize = builtTx.virtualSize(); final vSize = builtTx.virtualSize();
return {"hex": builtTx.toHex(), "vSize": vSize}; return {"hex": builtTx.toHex(), "vSize": vSize};

View file

@ -119,15 +119,15 @@ abstract class DefaultNodes {
); );
static NodeModel get particl => NodeModel( static NodeModel get particl => NodeModel(
host: "164.92.93.20", host: "particl.stackwallet.com",
port: 50002, port: 58002,
name: defaultName, name: defaultName,
id: _nodeId(Coin.particl), id: _nodeId(Coin.particl),
useSSL: true, useSSL: true,
enabled: true, enabled: true,
coinName: Coin.particl.name, coinName: Coin.particl.name,
isFailover: true, isFailover: true,
isDown: false); //TODO - UPDATE WITH CORRECT DETAILS isDown: false);
static NodeModel get bitcoinTestnet => NodeModel( static NodeModel get bitcoinTestnet => NodeModel(
host: "electrumx-testnet.cypherstack.com", host: "electrumx-testnet.cypherstack.com",