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
ecf81b95
Commit
ecf81b95
authored
Aug 08, 2018
by
Pavel Pavlov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- adding transaction to block
- adding block to chain - checking result
parent
1be933f6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
19 deletions
+116
-19
Program.cs
Sources/DeStream.DeStreamD.ForTest/Program.cs
+1
-16
TestClassHelper.cs
Sources/DeStream.DeStreamD.ForTest/TestClassHelper.cs
+115
-3
No files found.
Sources/DeStream.DeStreamD.ForTest/Program.cs
View file @
ecf81b95
...
...
@@ -73,29 +73,14 @@ namespace DeStream.DeStreamD.ForTest
var
walletManager
=
node
.
WalletManager
();
walletManager
.
Wallets
.
Add
(
result
.
wallet
);
//HdAddress addr = node.WalletManager().GetUnusedAddress(new WalletAccountReference("myWallet1", "account1"));
//HdAddress addr = result.wallet.AccountsRoot.ElementAt(0).Accounts.ElementAt(0).ExternalAddresses.ElementAt(0).Address;
//HdAddress addr = new HdAddress();
HdAddress
addr
=
result
.
wallet
.
AccountsRoot
.
ElementAt
(
0
).
Accounts
.
ElementAt
(
0
).
ExternalAddresses
.
ElementAt
(
0
);
Key
key
=
result
.
wallet
.
GetExtendedPrivateKeyForAddress
(
"password"
,
addr
).
PrivateKey
;
TestClassHelper
.
CreateTestBlock
(
node
,
key
);
// node.NodeService<IWalletFeePolicy>());
//(Wallet wallet, Block block, ChainedHeader chainedHeader) test = TestClassHelper.CreateFirstTransaction(nodeSettings, ref walletManager, node.NodeService<WalletSettings>(),
// node.NodeService<IWalletFeePolicy>());
//((WalletManager)node.NodeService<IWalletManager>()).Wallets.Add(test.wallet);
//((WalletManager)node.NodeService<IWalletManager>()).LoadKeysLookupLock();
//((WalletManager)node.NodeService<IWalletManager>()).WalletTipHash = test.block.Header.GetHash();
//((WalletManager)node.NodeService<IWalletManager>()).ProcessBlock(test.block, test.chainedHeader);
//walletManager.SaveWallets();
//walletManager.Wallets.Add(wallet);
var
test
=
node
.
WalletManager
().
GetSpendableTransactionsInWallet
(
"myWallet1"
).
Sum
(
s
=>
s
.
Transaction
.
Amount
);
int
qwe0
=
1
;
if
(
node
!=
null
)
await
node
.
RunAsync
();
...
...
Sources/DeStream.DeStreamD.ForTest/TestClassHelper.cs
View file @
ecf81b95
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Reflection
;
using
System.Text
;
using
System.Threading
;
using
DeStream.Stratis.Bitcoin.Configuration
;
...
...
@@ -222,9 +223,9 @@ namespace DeStream.DeStreamD.ForTest
//return wallet;
}
public
static
Money
Get
9
Billion
()
public
static
Money
Get
6
Billion
()
{
return
new
Money
(
9
000000000
);
return
new
Money
(
6
000000000
);
}
public
static
Block
CreateTestBlock
(
FullNode
fullNode
,
Key
key
)
...
...
@@ -242,7 +243,7 @@ namespace DeStream.DeStreamD.ForTest
block
.
Header
.
Bits
=
block
.
Header
.
GetWorkRequired
(
fullNode
.
Network
,
fullNode
.
Chain
.
Tip
);
block
.
Header
.
UpdateTime
(
DateTimeOffset
.
UtcNow
,
fullNode
.
Network
,
fullNode
.
Chain
.
Tip
);
var
coinbase
=
new
Transaction
();
coinbase
.
AddInput
(
TxIn
.
CreateCoinbase
(
fullNode
.
Chain
.
Height
+
1
));
//
coinbase.AddInput(TxIn.CreateCoinbase(fullNode.Chain.Height + 1));
coinbase
.
AddOutput
(
new
TxOut
(
Get9Billion
(),
dest
.
GetAddress
()));
block
.
AddTransaction
(
coinbase
);
if
(
passedTransactions
?.
Any
()
??
false
)
...
...
@@ -256,7 +257,28 @@ namespace DeStream.DeStreamD.ForTest
blocks
.
Add
(
block
);
uint256
blockHash
=
block
.
GetHash
();
var
newChain
=
new
ChainedHeader
(
block
.
Header
,
blockHash
,
fullNode
.
Chain
.
Tip
);
var
Genesis
=
(
ChainedHeader
)
fullNode
.
Chain
.
GetMemberValue
(
"Genesis"
);
var
Tip
=
(
ChainedHeader
)
fullNode
.
Chain
.
GetMemberValue
(
"tip"
);
ChainedHeader
test0
=
(
ChainedHeader
)
fullNode
.
Chain
.
GetMemberValue
(
"Genesis"
);
ChainedHeader
test1
=
(
ChainedHeader
)
fullNode
.
Chain
.
GetMemberValue
(
"Tip"
);
ChainedHeader
oldTip
=
fullNode
.
Chain
.
SetTip
(
newChain
);
test0
=
(
ChainedHeader
)
fullNode
.
Chain
.
GetMemberValue
(
"Genesis"
);
test1
=
(
ChainedHeader
)
fullNode
.
Chain
.
GetMemberValue
(
"Tip"
);
Dictionary
<
uint256
,
ChainedHeader
>
blocksById
=
(
Dictionary
<
uint256
,
ChainedHeader
>)
fullNode
.
Chain
.
GetMemberValue
(
"blocksById"
);
//fullNode.Chain.SetMemberValue("blocksById", (0,fullNode.Chain.Tip));
//fullNode.Chain.SetMemberValue("Genesis", fullNode.Chain.Tip);
test0
=
(
ChainedHeader
)
fullNode
.
Chain
.
GetMemberValue
(
"Genesis"
);
test1
=
(
ChainedHeader
)
fullNode
.
Chain
.
GetMemberValue
(
"Tip"
);
fullNode
.
ConsensusLoop
().
Puller
.
InjectBlock
(
blockHash
,
new
DownloadedBlock
{
Length
=
block
.
GetSerializedSize
(),
Block
=
block
},
CancellationToken
.
None
);
return
block
;
}
...
...
@@ -315,4 +337,94 @@ namespace DeStream.DeStreamD.ForTest
}
}
public
static
class
ReflectionExtensions
{
/// <summary>
/// Gets the public or private member using reflection.
/// </summary>
/// <param name="obj">The source target.</param>
/// <param name="memberName">Name of the field or property.</param>
/// <returns>the value of member</returns>
public
static
object
GetMemberValue
(
this
object
obj
,
string
memberName
)
{
var
memInf
=
GetMemberInfo
(
obj
,
memberName
);
if
(
memInf
==
null
)
throw
new
System
.
Exception
(
"memberName"
);
if
(
memInf
is
System
.
Reflection
.
PropertyInfo
)
return
memInf
.
As
<
System
.
Reflection
.
PropertyInfo
>().
GetValue
(
obj
,
null
);
if
(
memInf
is
System
.
Reflection
.
FieldInfo
)
return
memInf
.
As
<
System
.
Reflection
.
FieldInfo
>().
GetValue
(
obj
);
throw
new
System
.
Exception
();
}
/// <summary>
/// Gets the public or private member using reflection.
/// </summary>
/// <param name="obj">The target object.</param>
/// <param name="memberName">Name of the field or property.</param>
/// <returns>Old Value</returns>
public
static
object
SetMemberValue
(
this
object
obj
,
string
memberName
,
object
newValue
)
{
var
memInf
=
GetMemberInfo
(
obj
,
memberName
);
if
(
memInf
==
null
)
throw
new
System
.
Exception
(
"memberName"
);
var
oldValue
=
obj
.
GetMemberValue
(
memberName
);
if
(
memInf
is
System
.
Reflection
.
PropertyInfo
)
memInf
.
As
<
System
.
Reflection
.
PropertyInfo
>().
SetValue
(
obj
,
newValue
,
null
);
else
if
(
memInf
is
System
.
Reflection
.
FieldInfo
)
memInf
.
As
<
System
.
Reflection
.
FieldInfo
>().
SetValue
(
obj
,
newValue
);
else
throw
new
System
.
Exception
();
return
oldValue
;
}
/// <summary>
/// Gets the member info
/// </summary>
/// <param name="obj">source object</param>
/// <param name="memberName">name of member</param>
/// <returns>instanse of MemberInfo corresponsing to member</returns>
private
static
System
.
Reflection
.
MemberInfo
GetMemberInfo
(
object
obj
,
string
memberName
)
{
var
prps
=
new
System
.
Collections
.
Generic
.
List
<
System
.
Reflection
.
PropertyInfo
>();
prps
.
Add
(
obj
.
GetType
().
GetProperty
(
memberName
,
System
.
Reflection
.
BindingFlags
.
NonPublic
|
System
.
Reflection
.
BindingFlags
.
Public
|
System
.
Reflection
.
BindingFlags
.
Instance
|
System
.
Reflection
.
BindingFlags
.
FlattenHierarchy
));
prps
=
System
.
Linq
.
Enumerable
.
ToList
(
System
.
Linq
.
Enumerable
.
Where
(
prps
,
i
=>
!
ReferenceEquals
(
i
,
null
)));
if
(
prps
.
Count
!=
0
)
return
prps
[
0
];
var
flds
=
new
System
.
Collections
.
Generic
.
List
<
System
.
Reflection
.
FieldInfo
>();
flds
.
Add
(
obj
.
GetType
().
GetField
(
memberName
,
System
.
Reflection
.
BindingFlags
.
NonPublic
|
System
.
Reflection
.
BindingFlags
.
Instance
|
System
.
Reflection
.
BindingFlags
.
FlattenHierarchy
));
//to add more types of properties
flds
=
System
.
Linq
.
Enumerable
.
ToList
(
System
.
Linq
.
Enumerable
.
Where
(
flds
,
i
=>
!
ReferenceEquals
(
i
,
null
)));
if
(
flds
.
Count
!=
0
)
return
flds
[
0
];
return
null
;
}
[
System
.
Diagnostics
.
DebuggerHidden
]
private
static
T
As
<
T
>(
this
object
obj
)
{
return
(
T
)
obj
;
}
}
}
\ No newline at end of file
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