@@ -55,36 +55,46 @@ func NewStateProcessor(config *ChainConfig, bc *BlockChain) *StateProcessor {
5555// Process returns the receipts and logs accumulated during the process and
5656// returns the amount of gas that was used in the process. If any of the
5757// transactions failed to execute due to insufficient gas it will return an error.
58- func (p * StateProcessor ) Process (block * types.Block , publicState , privateState * state.StateDB , cfg vm.Config ) (types.Receipts , vm.Logs , * big.Int , error ) {
58+ func (p * StateProcessor ) Process (block * types.Block , publicState , privateState * state.StateDB , cfg vm.Config ) (types.Receipts , types. Receipts , vm.Logs , * big.Int , error ) {
5959 var (
60- receipts types.Receipts
61- totalUsedGas = big .NewInt (0 )
62- err error
63- header = block .Header ()
64- allLogs vm.Logs
65- gp = new (GasPool ).AddGas (block .GasLimit ())
60+ publicReceipts types.Receipts
61+ privateReceipts types.Receipts
62+ totalUsedGas = big .NewInt (0 )
63+ err error
64+ header = block .Header ()
65+ allLogs vm.Logs
66+ gp = new (GasPool ).AddGas (block .GasLimit ())
6667 )
6768
6869 for i , tx := range block .Transactions () {
6970 publicState .StartRecord (tx .Hash (), block .Hash (), i )
70- receipt , logs , _ , err := ApplyTransaction (p .config , p .bc , gp , publicState , privateState , header , tx , totalUsedGas , cfg )
71+ privateState .StartRecord (tx .Hash (), block .Hash (), i )
72+
73+ publicReceipt , privateReceipt , _ , err := ApplyTransaction (p .config , p .bc , gp , publicState , privateState , header , tx , totalUsedGas , cfg )
7174 if err != nil {
72- return nil , nil , totalUsedGas , err
75+ return nil , nil , nil , totalUsedGas , err
76+ }
77+ publicReceipts = append (publicReceipts , publicReceipt )
78+ allLogs = append (allLogs , publicReceipt .Logs ... )
79+
80+ // if the private receipt is nil this means the tx was public
81+ // and we do not need to apply the additional logic.
82+ if privateReceipt != nil {
83+ privateReceipts = append (privateReceipts , privateReceipt )
84+ allLogs = append (allLogs , privateReceipt .Logs ... )
7385 }
74- receipts = append (receipts , receipt )
75- allLogs = append (allLogs , logs ... )
7686 }
7787 AccumulateRewards (publicState , header , block .Uncles ())
7888
79- return receipts , allLogs , totalUsedGas , err
89+ return publicReceipts , privateReceipts , allLogs , totalUsedGas , err
8090}
8191
8292// ApplyTransaction attempts to apply a transaction to the given state database
8393// and uses the input parameters for its environment.
8494//
8595// ApplyTransactions returns the generated receipts and vm logs during the
8696// execution of the state transition phase.
87- func ApplyTransaction (config * ChainConfig , bc * BlockChain , gp * GasPool , publicState , privateState * state.StateDB , header * types.Header , tx * types.Transaction , usedGas * big.Int , cfg vm.Config ) (* types.Receipt , vm. Logs , * big.Int , error ) {
97+ func ApplyTransaction (config * ChainConfig , bc * BlockChain , gp * GasPool , publicState , privateState * state.StateDB , header * types.Header , tx * types.Transaction , usedGas * big.Int , cfg vm.Config ) (* types.Receipt , * types. Receipt , * big.Int , error ) {
8898 if ! tx .IsPrivate () {
8999 privateState = publicState
90100 }
@@ -100,19 +110,34 @@ func ApplyTransaction(config *ChainConfig, bc *BlockChain, gp *GasPool, publicSt
100110
101111 // Update the state with pending changes
102112 usedGas .Add (usedGas , gas )
103- receipt := types .NewReceipt (publicState .IntermediateRoot ().Bytes (), usedGas )
104- receipt .TxHash = tx .Hash ()
105- receipt .GasUsed = new (big.Int ).Set (gas )
113+ publicReceipt := types .NewReceipt (publicState .IntermediateRoot ().Bytes (), usedGas )
114+ publicReceipt .TxHash = tx .Hash ()
115+ publicReceipt .GasUsed = new (big.Int ).Set (gas )
106116 if MessageCreatesContract (tx ) {
107117 from , _ := tx .From ()
108- receipt .ContractAddress = crypto .CreateAddress (from , tx .Nonce ())
118+ publicReceipt .ContractAddress = crypto .CreateAddress (from , tx .Nonce ())
109119 }
110120
111121 logs := publicState .GetLogs (tx .Hash ())
112- receipt .Logs = logs
113- receipt .Bloom = types .CreateBloom (types.Receipts {receipt })
122+ publicReceipt .Logs = logs
123+ publicReceipt .Bloom = types .CreateBloom (types.Receipts {publicReceipt })
124+
125+ var privateReceipt * types.Receipt
126+ if tx .IsPrivate () {
127+ privateReceipt = types .NewReceipt (privateState .IntermediateRoot ().Bytes (), usedGas )
128+ privateReceipt .TxHash = tx .Hash ()
129+ privateReceipt .GasUsed = new (big.Int ).Set (gas )
130+ if MessageCreatesContract (tx ) {
131+ from , _ := tx .From ()
132+ privateReceipt .ContractAddress = crypto .CreateAddress (from , tx .Nonce ())
133+ }
134+
135+ logs := privateState .GetLogs (tx .Hash ())
136+ privateReceipt .Logs = logs
137+ privateReceipt .Bloom = types .CreateBloom (types.Receipts {privateReceipt })
138+ }
114139
115- return receipt , logs , gas , err
140+ return publicReceipt , privateReceipt , gas , err
116141}
117142
118143// AccumulateRewards credits the coinbase of the given block with the
0 commit comments