mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +00:00
add wallet owns flag to outputv2
This commit is contained in:
parent
dc64a06698
commit
5b9ade5f15
2 changed files with 28 additions and 3 deletions
|
@ -9,6 +9,8 @@ class OutputV2 {
|
||||||
late final String valueStringSats;
|
late final String valueStringSats;
|
||||||
late final List<String> addresses;
|
late final List<String> addresses;
|
||||||
|
|
||||||
|
late final bool walletOwns;
|
||||||
|
|
||||||
@ignore
|
@ignore
|
||||||
BigInt get value => BigInt.parse(valueStringSats);
|
BigInt get value => BigInt.parse(valueStringSats);
|
||||||
|
|
||||||
|
@ -18,14 +20,31 @@ class OutputV2 {
|
||||||
required String scriptPubKeyHex,
|
required String scriptPubKeyHex,
|
||||||
required String valueStringSats,
|
required String valueStringSats,
|
||||||
required List<String> addresses,
|
required List<String> addresses,
|
||||||
|
required bool walletOwns,
|
||||||
}) =>
|
}) =>
|
||||||
OutputV2()
|
OutputV2()
|
||||||
..scriptPubKeyHex = scriptPubKeyHex
|
..scriptPubKeyHex = scriptPubKeyHex
|
||||||
..valueStringSats = valueStringSats
|
..valueStringSats = valueStringSats
|
||||||
|
..walletOwns = walletOwns
|
||||||
..addresses = List.unmodifiable(addresses);
|
..addresses = List.unmodifiable(addresses);
|
||||||
|
|
||||||
|
OutputV2 copyWith({
|
||||||
|
String? scriptPubKeyHex,
|
||||||
|
String? valueStringSats,
|
||||||
|
List<String>? addresses,
|
||||||
|
bool? walletOwns,
|
||||||
|
}) {
|
||||||
|
return OutputV2.isarCantDoRequiredInDefaultConstructor(
|
||||||
|
scriptPubKeyHex: scriptPubKeyHex ?? this.scriptPubKeyHex,
|
||||||
|
valueStringSats: valueStringSats ?? this.valueStringSats,
|
||||||
|
addresses: addresses ?? this.addresses,
|
||||||
|
walletOwns: walletOwns ?? this.walletOwns,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static OutputV2 fromElectrumXJson(
|
static OutputV2 fromElectrumXJson(
|
||||||
Map<String, dynamic> json, {
|
Map<String, dynamic> json, {
|
||||||
|
required bool walletOwns,
|
||||||
required int decimalPlaces,
|
required int decimalPlaces,
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
|
@ -46,6 +65,7 @@ class OutputV2 {
|
||||||
decimalPlaces: decimalPlaces,
|
decimalPlaces: decimalPlaces,
|
||||||
),
|
),
|
||||||
addresses: addresses,
|
addresses: addresses,
|
||||||
|
walletOwns: walletOwns,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception("Failed to parse OutputV2 from $json");
|
throw Exception("Failed to parse OutputV2 from $json");
|
||||||
|
@ -84,6 +104,7 @@ class OutputV2 {
|
||||||
@override
|
@override
|
||||||
int get hashCode => Object.hash(
|
int get hashCode => Object.hash(
|
||||||
scriptPubKeyHex,
|
scriptPubKeyHex,
|
||||||
|
addresses,
|
||||||
valueStringSats,
|
valueStringSats,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -2099,6 +2099,7 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
final prevOut = OutputV2.fromElectrumXJson(
|
final prevOut = OutputV2.fromElectrumXJson(
|
||||||
prevOutJson,
|
prevOutJson,
|
||||||
decimalPlaces: coin.decimals,
|
decimalPlaces: coin.decimals,
|
||||||
|
walletOwns: false, // doesn't matter here as this is not saved
|
||||||
);
|
);
|
||||||
|
|
||||||
outpoint = OutpointV2.isarCantDoRequiredInDefaultConstructor(
|
outpoint = OutpointV2.isarCantDoRequiredInDefaultConstructor(
|
||||||
|
@ -2136,11 +2137,10 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
final output = OutputV2.fromElectrumXJson(
|
final output = OutputV2.fromElectrumXJson(
|
||||||
Map<String, dynamic>.from(outputJson as Map),
|
Map<String, dynamic>.from(outputJson as Map),
|
||||||
decimalPlaces: coin.decimals,
|
decimalPlaces: coin.decimals,
|
||||||
|
// don't know yet if wallet owns. Need addresses first
|
||||||
|
walletOwns: false,
|
||||||
);
|
);
|
||||||
outputs.add(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final output in outputs) {
|
|
||||||
// if output was to my wallet, add value to amount received
|
// if output was to my wallet, add value to amount received
|
||||||
if (receivingAddresses
|
if (receivingAddresses
|
||||||
.intersection(output.addresses.toSet())
|
.intersection(output.addresses.toSet())
|
||||||
|
@ -2153,6 +2153,10 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
wasReceivedInThisWallet = true;
|
wasReceivedInThisWallet = true;
|
||||||
changeAmountReceivedInThisWallet += output.value;
|
changeAmountReceivedInThisWallet += output.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outputs.add(wasReceivedInThisWallet
|
||||||
|
? output.copyWith(walletOwns: true)
|
||||||
|
: output);
|
||||||
}
|
}
|
||||||
|
|
||||||
final totalIn = inputs
|
final totalIn = inputs
|
||||||
|
|
Loading…
Reference in a new issue