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
660243c8
Commit
660243c8
authored
5 years ago
by
Sergei Zubov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add zero inputs for transfers to own addresses
parent
1425e56c
Pipeline
#638
failed with stages
in 45 seconds
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
11 deletions
+77
-11
DeStreamTransactionBuilder.cs
Sources/NBitcoin/DeStreamTransactionBuilder.cs
+35
-11
TransactionBuilder.cs
Sources/NBitcoin/TransactionBuilder.cs
+7
-0
DeStreamWalletTransactionHandler.cs
...tcoin.Features.Wallet/DeStreamWalletTransactionHandler.cs
+35
-0
No files found.
Sources/NBitcoin/DeStreamTransactionBuilder.cs
View file @
660243c8
...
@@ -33,22 +33,46 @@ namespace NBitcoin
...
@@ -33,22 +33,46 @@ namespace NBitcoin
// we add input with uint256.Zero hash that points to output with change
// we add input with uint256.Zero hash that points to output with change
int
changeIndex
=
ctx
.
Transaction
.
Outputs
.
FindIndex
(
p
=>
int
changeIndex
=
ctx
.
Transaction
.
Outputs
.
FindIndex
(
p
=>
p
.
ScriptPubKey
==
group
.
ChangeScript
[(
int
)
ctx
.
ChangeType
]);
p
.
ScriptPubKey
==
group
.
ChangeScript
[(
int
)
ctx
.
ChangeType
]);
if
(
changeIndex
==
-
1
)
return
result
;
var
outPoint
=
new
OutPoint
if
(
changeIndex
!=
-
1
)
{
{
Hash
=
uint256
.
Zero
,
var
outPoint
=
new
OutPoint
N
=
(
uint
)
changeIndex
{
};
Hash
=
uint256
.
Zero
,
N
=
(
uint
)
changeIndex
};
ctx
.
Transaction
.
AddInput
(
new
TxIn
ctx
.
Transaction
.
AddInput
(
new
TxIn
{
PrevOut
=
outPoint
});
group
.
Coins
.
Add
(
outPoint
,
new
Coin
(
uint256
.
Zero
,
outPoint
.
N
,
Money
.
Zero
,
group
.
ChangeScript
[(
int
)
ctx
.
ChangeType
]));
}
foreach
(
var
ownAddress
in
group
.
ownAddresses
)
{
{
PrevOut
=
outPoint
var
ownAddressOutputIndex
=
ctx
.
Transaction
.
Outputs
.
FindIndex
(
p
=>
});
string
.
Equals
(
p
.
ScriptPubKey
.
GetDestinationAddress
(
this
.
Network
).
ToString
(),
ownAddress
));
if
(
ownAddressOutputIndex
==
-
1
||
ownAddressOutputIndex
==
changeIndex
)
continue
;
var
outPoint
=
new
OutPoint
{
Hash
=
uint256
.
Zero
,
N
=
(
uint
)
ownAddressOutputIndex
};
ctx
.
Transaction
.
AddInput
(
new
TxIn
{
PrevOut
=
outPoint
});
group
.
Coins
.
Add
(
outPoint
,
new
Coin
(
uint256
.
Zero
,
outPoint
.
N
,
group
.
Coins
.
Add
(
outPoint
,
new
Coin
(
uint256
.
Zero
,
outPoint
.
N
,
Money
.
Zero
,
@group
.
ChangeScript
[(
int
)
ctx
.
ChangeType
]));
Money
.
Zero
,
ctx
.
Transaction
.
Outputs
[
ownAddressOutputIndex
].
ScriptPubKey
));
}
return
result
;
return
result
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Sources/NBitcoin/TransactionBuilder.cs
View file @
660243c8
...
@@ -495,6 +495,7 @@ namespace NBitcoin
...
@@ -495,6 +495,7 @@ namespace NBitcoin
internal
List
<
Builder
>
IssuanceBuilders
=
new
List
<
Builder
>();
internal
List
<
Builder
>
IssuanceBuilders
=
new
List
<
Builder
>();
internal
Dictionary
<
AssetId
,
List
<
Builder
>>
BuildersByAsset
=
new
Dictionary
<
AssetId
,
List
<
Builder
>>();
internal
Dictionary
<
AssetId
,
List
<
Builder
>>
BuildersByAsset
=
new
Dictionary
<
AssetId
,
List
<
Builder
>>();
internal
Script
[]
ChangeScript
=
new
Script
[
3
];
internal
Script
[]
ChangeScript
=
new
Script
[
3
];
internal
IEnumerable
<
string
>
ownAddresses
{
get
;
set
;
}
internal
void
Shuffle
()
internal
void
Shuffle
()
{
{
Shuffle
(
this
.
Builders
);
Shuffle
(
this
.
Builders
);
...
@@ -1074,6 +1075,12 @@ namespace NBitcoin
...
@@ -1074,6 +1075,12 @@ namespace NBitcoin
return
this
;
return
this
;
}
}
public
TransactionBuilder
SetOwnAddresses
(
IEnumerable
<
string
>
ownAddresses
)
{
this
.
CurrentGroup
.
ownAddresses
=
ownAddresses
;
return
this
;
}
public
TransactionBuilder
SetCoinSelector
(
ICoinSelector
selector
)
public
TransactionBuilder
SetCoinSelector
(
ICoinSelector
selector
)
{
{
if
(
selector
==
null
)
if
(
selector
==
null
)
...
...
This diff is collapsed.
Click to expand it.
Sources/Stratis.Bitcoin.Features.Wallet/DeStreamWalletTransactionHandler.cs
View file @
660243c8
...
@@ -30,6 +30,18 @@ namespace Stratis.Bitcoin.Features.Wallet
...
@@ -30,6 +30,18 @@ namespace Stratis.Bitcoin.Features.Wallet
}
}
}
}
protected
override
void
InitializeTransactionBuilder
(
TransactionBuildContext
context
)
{
base
.
InitializeTransactionBuilder
(
context
);
this
.
AddOwnAddresses
(
context
);
}
private
void
AddOwnAddresses
(
TransactionBuildContext
context
)
{
context
.
TransactionBuilder
.
SetOwnAddresses
(
(
this
.
walletManager
as
IDeStreamWalletManager
).
GetOwnAddresses
(
context
.
AccountReference
));
}
/// <inheritdoc />
/// <inheritdoc />
protected
override
void
AddFee
(
TransactionBuildContext
context
)
protected
override
void
AddFee
(
TransactionBuildContext
context
)
{
{
...
@@ -140,6 +152,29 @@ namespace Stratis.Bitcoin.Features.Wallet
...
@@ -140,6 +152,29 @@ namespace Stratis.Bitcoin.Features.Wallet
seedExtKey
.
Derive
(
new
KeyPath
(
context
.
ChangeAddress
.
HdPath
)).
GetWif
(
wallet
.
Network
);
seedExtKey
.
Derive
(
new
KeyPath
(
context
.
ChangeAddress
.
HdPath
)).
GetWif
(
wallet
.
Network
);
signingKeys
.
Add
(
changeAddressPrivateKey
);
signingKeys
.
Add
(
changeAddressPrivateKey
);
var
transfersToSelf
=
context
.
Recipients
.
Where
(
p
=>
(
this
.
walletManager
as
IDeStreamWalletManager
).
GetOwnAddresses
(
context
.
AccountReference
)
.
Contains
(
p
.
ScriptPubKey
.
GetDestinationAddress
(
this
.
network
).
ToString
())
&&
context
.
UnspentOutputs
.
All
(
q
=>
p
.
ScriptPubKey
!=
q
.
Address
.
ScriptPubKey
));
foreach
(
var
ownAddress
in
transfersToSelf
)
{
var
ownHdAddress
=
this
.
walletManager
.
GetAccounts
(
context
.
AccountReference
.
WalletName
)
.
Single
(
q
=>
q
.
Name
==
context
.
AccountReference
.
AccountName
).
GetCombinedAddresses
()
.
Single
(
p
=>
string
.
Equals
(
ownAddress
.
ScriptPubKey
.
GetDestinationAddress
(
this
.
network
).
ToString
(),
p
.
Address
));
var
ownAddressPrivateKey
=
seedExtKey
.
Derive
(
new
KeyPath
(
ownHdAddress
.
HdPath
)).
GetWif
(
wallet
.
Network
);
signingKeys
.
Add
(
ownAddressPrivateKey
);
}
// signingKeys.UnionWith(context.Recipients.Where(p =>
// (this.walletManager as IDeStreamWalletManager).GetOwnAddresses(context.AccountReference)
// .Contains(p.ScriptPubKey.GetDestinationAddress(this.network).ToString()) &&
// context.UnspentOutputs.All(q => p.ScriptPubKey != q.Address.ScriptPubKey)).Select(r =>
// seedExtKey.Derive(new KeyPath(this.walletManager.GetAccounts(context.AccountReference.WalletName)
// .Single(q => q.Name == context.AccountReference.AccountName).GetCombinedAddresses()
// .Single(p =>
// string.Equals(r.ScriptPubKey.GetDestinationAddress(this.network).ToString(), p.Address))
// .HdPath)).GetWif(wallet.Network)));
context
.
TransactionBuilder
.
AddKeys
(
signingKeys
.
ToArray
());
context
.
TransactionBuilder
.
AddKeys
(
signingKeys
.
ToArray
());
}
}
...
...
This diff is collapsed.
Click to expand it.
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