@@ -360,7 +360,7 @@ internal Transaction GetColdStakingSetupTransaction(IWalletTransactionHandler wa
360360 coldPubKeyHash = new BitcoinWitPubKeyAddress ( coldWalletAddress , wallet . Network ) . Hash . AsKeyId ( ) ;
361361 destination = ColdStakingScriptTemplate . Instance . GenerateScriptPubKey ( hotPubKeyHash , coldPubKeyHash ) ;
362362
363- if ( payToScript )
363+ if ( payToScript )
364364 {
365365 HdAddress address = coldAddress ?? hotAddress ;
366366 address . RedeemScript = destination ;
@@ -382,7 +382,7 @@ internal Transaction GetColdStakingSetupTransaction(IWalletTransactionHandler wa
382382 }
383383
384384 // Only normal accounts should be allowed.
385- if ( ! this . GetAccounts ( walletName ) . Any ( a => a . Name = = walletAccount ) )
385+ if ( this . GetAccounts ( walletName ) . All ( a => a . Name ! = walletAccount ) )
386386 {
387387 this . logger . LogTrace ( "(-)[COLDSTAKE_ACCOUNT_NOT_FOUND]" ) ;
388388 throw new WalletException ( $ "Can't find wallet account '{ walletAccount } '.") ;
@@ -403,20 +403,22 @@ internal Transaction GetColdStakingSetupTransaction(IWalletTransactionHandler wa
403403 {
404404 // In the case of P2SH and P2WSH, to avoid the possibility of lose of funds
405405 // we add an opreturn with the hot and cold key hashes to the setup transaction
406- // this will allow a user to recreate the redeem script of the output in case they lose
407- // access to one of the keys.
408- // The special marker will help a wallet that is tracking cold staking accounts to monitor
409- // the hot and cold keys, if a special marker is found then the keys are in the opreturn are checked
406+ // this will allow a user to recreate the redeem script of the output in case they lose
407+ // access to one of the keys.
408+ // The special marker will help a wallet that is tracking cold staking accounts to monitor
409+ // the hot and cold keys, if a special marker is found then the keys are in the opreturn are checked
410410 // against the current wallet, if found and validated the wallet will track that ScriptPubKey
411411
412412 var opreturnKeys = new List < byte > ( ) ;
413413 opreturnKeys . AddRange ( hotPubKeyHash . ToBytes ( ) ) ;
414414 opreturnKeys . AddRange ( coldPubKeyHash . ToBytes ( ) ) ;
415-
415+
416416 context . OpReturnRawData = opreturnKeys . ToArray ( ) ;
417- //context.OpReturnAmount = Money.Satoshis(1); // mandatory fee must be paid.
418-
419- // The P2SH and P2WSH hide the cold stake keys in the script hash so the wallet cannot track
417+ var template = this . network . StandardScriptsRegistry . GetScriptTemplates . OfType < TxNullDataTemplate > ( ) . First ( ) ;
418+ if ( template . MinRequiredSatoshiFee > 0 )
419+ context . OpReturnAmount = Money . Satoshis ( template . MinRequiredSatoshiFee ) ; // mandatory fee must be paid.
420+
421+ // The P2SH and P2WSH hide the cold stake keys in the script hash so the wallet cannot track
420422 // the ouputs based on the derived keys when the trx is subbmited to the network.
421423 // So we add the output script manually.
422424 }
@@ -611,7 +613,7 @@ public override void TransactionFoundInternal(Script script, Func<HdAccount, boo
611613 /// <summary>
612614 /// The purpose of this method is to try to identify the P2SH and P2WSH that are coldstake outputs for this wallet
613615 /// We look for an opreturn script that is created when seting up a P2SH and P2WSH cold stake trx
614- /// if we find any then try to find the keys and track the script before calling in to the main wallet.
616+ /// if we find any then try to find the keys and track the script before calling in to the main wallet.
615617 /// </summary>
616618 /// <inheritdoc/>
617619 public override bool ProcessTransaction ( Transaction transaction , int ? blockHeight = null , Block block = null , bool isPropagated = true )
@@ -628,7 +630,7 @@ public override bool ProcessTransaction(Transaction transaction, int? blockHeigh
628630 if ( data [ 0 ] . Length == 40 )
629631 {
630632 HdAddress address = null ;
631-
633+
632634 Span < byte > span = data [ 0 ] . AsSpan ( ) ;
633635 var hotPubKey = new KeyId ( span . Slice ( 0 , 20 ) . ToArray ( ) ) ;
634636 var coldPubKey = new KeyId ( span . Slice ( 20 , 20 ) . ToArray ( ) ) ;
@@ -642,11 +644,11 @@ public override bool ProcessTransaction(Transaction transaction, int? blockHeigh
642644 // Find the type of script for the opreturn (P2SH or P2WSH)
643645 foreach ( TxOut utxoInner in transaction . Outputs )
644646 {
645- if ( utxoInner . ScriptPubKey == destination . Hash . ScriptPubKey )
647+ if ( utxoInner . ScriptPubKey == destination . Hash . ScriptPubKey )
646648 {
647- if ( ! this . scriptToAddressLookup . TryGetValue ( destination . Hash . ScriptPubKey , out HdAddress _ ) )
649+ if ( ! this . scriptToAddressLookup . TryGetValue ( destination . Hash . ScriptPubKey , out HdAddress _ ) )
648650 this . scriptToAddressLookup [ destination . Hash . ScriptPubKey ] = address ;
649-
651+
650652 break ;
651653 }
652654
@@ -673,9 +675,9 @@ protected override void AddAddressToIndex(HdAddress address)
673675 {
674676 base . AddAddressToIndex ( address ) ;
675677
676- if ( address . RedeemScript != null )
678+ if ( address . RedeemScript != null )
677679 {
678- // The redeem script has no indication on the script type (P2SH or P2WSH),
680+ // The redeem script has no indication on the script type (P2SH or P2WSH),
679681 // so we track both, add both to the indexer then.
680682
681683 if ( ! this . scriptToAddressLookup . TryGetValue ( address . RedeemScript . Hash . ScriptPubKey , out HdAddress _ ) )
@@ -686,4 +688,4 @@ protected override void AddAddressToIndex(HdAddress address)
686688 }
687689 }
688690 }
689- }
691+ }
0 commit comments