SetReceiptsData computes all the non-consensus fields of the receipts
(config *configs.ChainConfig, block *types.Block, receipts types.Receipts)
| 917 | |
| 918 | // SetReceiptsData computes all the non-consensus fields of the receipts |
| 919 | func SetReceiptsData(config *configs.ChainConfig, block *types.Block, receipts types.Receipts) error { |
| 920 | signer := types.MakeSigner(config) |
| 921 | |
| 922 | transactions, logIndex := block.Transactions(), uint(0) |
| 923 | if len(transactions) != len(receipts) { |
| 924 | return errors.New("transaction and receipt count mismatch") |
| 925 | } |
| 926 | |
| 927 | for j := 0; j < len(receipts); j++ { |
| 928 | // The transaction hash can be retrieved from the transaction itself |
| 929 | receipts[j].TxHash = transactions[j].Hash() |
| 930 | |
| 931 | // The contract address can be derived from the transaction itself |
| 932 | if transactions[j].To() == nil { |
| 933 | // Deriving the signer is expensive, only do if it's actually needed |
| 934 | from, _ := types.Sender(signer, transactions[j]) |
| 935 | receipts[j].ContractAddress = crypto.CreateAddress(from, transactions[j].Nonce()) |
| 936 | } |
| 937 | // The used gas can be calculated based on previous receipts |
| 938 | if j == 0 { |
| 939 | receipts[j].GasUsed = receipts[j].CumulativeGasUsed |
| 940 | } else { |
| 941 | receipts[j].GasUsed = receipts[j].CumulativeGasUsed - receipts[j-1].CumulativeGasUsed |
| 942 | } |
| 943 | // The derived log fields can simply be set from the block and transaction |
| 944 | for k := 0; k < len(receipts[j].Logs); k++ { |
| 945 | receipts[j].Logs[k].BlockNumber = block.NumberU64() |
| 946 | receipts[j].Logs[k].BlockHash = block.Hash() |
| 947 | receipts[j].Logs[k].TxHash = receipts[j].TxHash |
| 948 | receipts[j].Logs[k].TxIndex = uint(j) |
| 949 | receipts[j].Logs[k].Index = logIndex |
| 950 | logIndex++ |
| 951 | } |
| 952 | } |
| 953 | return nil |
| 954 | } |
| 955 | |
| 956 | // InsertReceiptChain attempts to complete an already existing header chain with |
| 957 | // transaction and receipt data. |
no test coverage detected