@@ -38,6 +38,10 @@ var consenter *example.Consenter
38
38
var accounts = []string {"account1" , "account2" , "account3" , "account4" }
39
39
40
40
func init () {
41
+
42
+ // Initialization will get a handle to the ledger at the specified path
43
+ // Note, if subledgers are supported in the future,
44
+ // the various ledgers could be created/managed at this level
41
45
os .RemoveAll (ledgerPath )
42
46
ledgerConf := kvledger .NewConf (ledgerPath , 0 )
43
47
var err error
@@ -52,12 +56,31 @@ func init() {
52
56
53
57
func main () {
54
58
defer finalLedger .Close ()
59
+
60
+ // Each of the functions here will emulate endorser, orderer,
61
+ // and committer by calling ledger APIs to similate the proposal,
62
+ // get simulation results, create a transaction, add it to a block,
63
+ // and then commit the block.
64
+
65
+ // Initialize account balances by setting each account to 100
55
66
initApp ()
67
+
56
68
printBalances ()
69
+
70
+ // Transfer money between accounts. Exercises happy path.
57
71
transferFunds ()
72
+
58
73
printBalances ()
74
+
75
+ // Attempt to transfer more money than account balance
76
+ // Exercises simulation failure
59
77
tryInvalidTransfer ()
78
+
79
+ // Attempt two transactions, the first one will have sufficient funds,
80
+ // the second one should fail since the account balance was updated
81
+ // (by the first tran) since simulation time. This exercises the MVCC check.
60
82
tryDoubleSpend ()
83
+
61
84
printBalances ()
62
85
}
63
86
@@ -79,7 +102,11 @@ func transferFunds() {
79
102
handleError (err , true )
80
103
tx2 , err := app .TransferFunds ("account3" , "account4" , 50 )
81
104
handleError (err , true )
105
+
106
+ // act as ordering service (consenter) to create a Raw Block from the Transaction
82
107
rawBlock := consenter .ConstructBlock (tx1 , tx2 )
108
+
109
+ // act as committing peer to commit the Raw Block
83
110
finalBlock , invalidTx , err := committer .CommitBlock (rawBlock )
84
111
handleError (err , true )
85
112
printBlocksInfo (rawBlock , finalBlock , invalidTx )
0 commit comments