Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
destream-blockchain
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DeStream-public
destream-blockchain
Commits
6f126a35
Commit
6f126a35
authored
Dec 27, 2018
by
Sergei Zubov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify wallet resync
Ensure that correct data about spending transaction is present in JSON
parent
9c1440c9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
4 deletions
+80
-4
DeStreamWalletManager.cs
.../Stratis.Bitcoin.Features.Wallet/DeStreamWalletManager.cs
+77
-1
WalletManager.cs
Sources/Stratis.Bitcoin.Features.Wallet/WalletManager.cs
+3
-3
No files found.
Sources/Stratis.Bitcoin.Features.Wallet/DeStreamWalletManager.cs
View file @
6f126a35
using
System.Linq
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging
;
using
NBitcoin
;
using
NBitcoin
;
using
Stratis.Bitcoin.Configuration
;
using
Stratis.Bitcoin.Configuration
;
...
@@ -41,5 +43,79 @@ namespace Stratis.Bitcoin.Features.Wallet
...
@@ -41,5 +43,79 @@ namespace Stratis.Bitcoin.Features.Wallet
this
.
network
.
GetGenesis
());
this
.
network
.
GetGenesis
());
}
}
}
}
protected
override
void
AddSpendingTransactionToWallet
(
Transaction
transaction
,
IEnumerable
<
TxOut
>
paidToOutputs
,
uint256
spendingTransactionId
,
int
?
spendingTransactionIndex
,
int
?
blockHeight
=
null
,
Block
block
=
null
)
{
Guard
.
NotNull
(
transaction
,
nameof
(
transaction
));
Guard
.
NotNull
(
paidToOutputs
,
nameof
(
paidToOutputs
));
this
.
logger
.
LogTrace
(
"({0}:'{1}',{2}:'{3}',{4}:{5},{6}:'{7}')"
,
nameof
(
transaction
),
transaction
.
GetHash
(),
nameof
(
spendingTransactionId
),
spendingTransactionId
,
nameof
(
spendingTransactionIndex
),
spendingTransactionIndex
,
nameof
(
blockHeight
),
blockHeight
);
// Get the transaction being spent.
TransactionData
spentTransaction
=
this
.
keysLookup
.
Values
.
Distinct
().
SelectMany
(
v
=>
v
.
Transactions
)
.
SingleOrDefault
(
t
=>
t
.
Id
==
spendingTransactionId
&&
t
.
Index
==
spendingTransactionIndex
);
if
(
spentTransaction
==
null
)
{
// Strange, why would it be null?
this
.
logger
.
LogTrace
(
"(-)[TX_NULL]"
);
return
;
}
this
.
logger
.
LogTrace
(
spentTransaction
.
SpendingDetails
==
null
?
$"Spending UTXO '
{
spendingTransactionId
}
-
{
spendingTransactionIndex
}
' is new."
:
$"Spending transaction ID '
{
spendingTransactionId
}
' is being confirmed, updating."
);
var
payments
=
new
List
<
PaymentDetails
>();
foreach
(
TxOut
paidToOutput
in
paidToOutputs
)
{
// Figure out how to retrieve the destination address.
string
destinationAddress
=
string
.
Empty
;
ScriptTemplate
scriptTemplate
=
paidToOutput
.
ScriptPubKey
.
FindTemplate
(
this
.
network
);
switch
(
scriptTemplate
.
Type
)
{
// Pay to PubKey can be found in outputs of staking transactions.
case
TxOutType
.
TX_PUBKEY
:
PubKey
pubKey
=
PayToPubkeyTemplate
.
Instance
.
ExtractScriptPubKeyParameters
(
paidToOutput
.
ScriptPubKey
);
destinationAddress
=
pubKey
.
GetAddress
(
this
.
network
).
ToString
();
break
;
// Pay to PubKey hash is the regular, most common type of output.
case
TxOutType
.
TX_PUBKEYHASH
:
destinationAddress
=
paidToOutput
.
ScriptPubKey
.
GetDestinationAddress
(
this
.
network
).
ToString
();
break
;
case
TxOutType
.
TX_NONSTANDARD
:
case
TxOutType
.
TX_SCRIPTHASH
:
case
TxOutType
.
TX_MULTISIG
:
case
TxOutType
.
TX_NULL_DATA
:
case
TxOutType
.
TX_SEGWIT
:
break
;
}
payments
.
Add
(
new
PaymentDetails
{
DestinationScriptPubKey
=
paidToOutput
.
ScriptPubKey
,
DestinationAddress
=
destinationAddress
,
Amount
=
paidToOutput
.
Value
});
}
var
spendingDetails
=
new
SpendingDetails
{
TransactionId
=
transaction
.
GetHash
(),
Payments
=
payments
,
CreationTime
=
DateTimeOffset
.
FromUnixTimeSeconds
(
block
?.
Header
.
Time
??
transaction
.
Time
),
BlockHeight
=
blockHeight
,
Hex
=
this
.
walletSettings
.
SaveTransactionHex
?
transaction
.
ToHex
()
:
null
,
IsCoinStake
=
transaction
.
IsCoinStake
==
false
?
(
bool
?)
null
:
true
};
spentTransaction
.
SpendingDetails
=
spendingDetails
;
spentTransaction
.
MerkleProof
=
null
;
this
.
logger
.
LogTrace
(
"(-)"
);
}
}
}
}
}
\ No newline at end of file
Sources/Stratis.Bitcoin.Features.Wallet/WalletManager.cs
View file @
6f126a35
...
@@ -61,7 +61,7 @@ namespace Stratis.Bitcoin.Features.Wallet
...
@@ -61,7 +61,7 @@ namespace Stratis.Bitcoin.Features.Wallet
private
readonly
INodeLifetime
nodeLifetime
;
private
readonly
INodeLifetime
nodeLifetime
;
/// <summary>Instance logger.</summary>
/// <summary>Instance logger.</summary>
pr
ivate
readonly
ILogger
logger
;
pr
otected
readonly
ILogger
logger
;
/// <summary>An object capable of storing <see cref="Wallet"/>s to the file system.</summary>
/// <summary>An object capable of storing <see cref="Wallet"/>s to the file system.</summary>
private
readonly
FileStorage
<
Wallet
>
fileStorage
;
private
readonly
FileStorage
<
Wallet
>
fileStorage
;
...
@@ -73,7 +73,7 @@ namespace Stratis.Bitcoin.Features.Wallet
...
@@ -73,7 +73,7 @@ namespace Stratis.Bitcoin.Features.Wallet
private
readonly
IDateTimeProvider
dateTimeProvider
;
private
readonly
IDateTimeProvider
dateTimeProvider
;
/// <summary>The settings for the wallet feature.</summary>
/// <summary>The settings for the wallet feature.</summary>
pr
ivate
readonly
WalletSettings
walletSettings
;
pr
otected
readonly
WalletSettings
walletSettings
;
public
uint256
WalletTipHash
{
get
;
set
;
}
public
uint256
WalletTipHash
{
get
;
set
;
}
...
@@ -987,7 +987,7 @@ namespace Stratis.Bitcoin.Features.Wallet
...
@@ -987,7 +987,7 @@ namespace Stratis.Bitcoin.Features.Wallet
/// <param name="spendingTransactionIndex">The index of the output in the transaction being referenced, if this is a spending transaction.</param>
/// <param name="spendingTransactionIndex">The index of the output in the transaction being referenced, if this is a spending transaction.</param>
/// <param name="blockHeight">Height of the block.</param>
/// <param name="blockHeight">Height of the block.</param>
/// <param name="block">The block containing the transaction to add.</param>
/// <param name="block">The block containing the transaction to add.</param>
pr
ivate
void
AddSpendingTransactionToWallet
(
Transaction
transaction
,
IEnumerable
<
TxOut
>
paidToOutputs
,
pr
otected
virtual
void
AddSpendingTransactionToWallet
(
Transaction
transaction
,
IEnumerable
<
TxOut
>
paidToOutputs
,
uint256
spendingTransactionId
,
int
?
spendingTransactionIndex
,
int
?
blockHeight
=
null
,
Block
block
=
null
)
uint256
spendingTransactionId
,
int
?
spendingTransactionIndex
,
int
?
blockHeight
=
null
,
Block
block
=
null
)
{
{
Guard
.
NotNull
(
transaction
,
nameof
(
transaction
));
Guard
.
NotNull
(
transaction
,
nameof
(
transaction
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment