github.com/jiajun1992/watercarver@v0.0.0-20191031150618-dfc2b17c0c4a/go-ethereum/accounts/abi/bind/backends/simulated.go (about) 1 // Copyright 2015 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package backends 18 19 import ( 20 "bytes" 21 "context" 22 "errors" 23 "fmt" 24 "github.com/ethereum/go-ethereum/ctcrypto" 25 crypto2 "github.com/ethereum/go-ethereum/ctcrypto/crypto" 26 "github.com/ethereum/go-ethereum/ctcrypto/crypto/ringct" 27 "math/big" 28 "sync" 29 "time" 30 31 "github.com/ethereum/go-ethereum" 32 "github.com/ethereum/go-ethereum/accounts/abi/bind" 33 "github.com/ethereum/go-ethereum/common" 34 "github.com/ethereum/go-ethereum/common/math" 35 "github.com/ethereum/go-ethereum/consensus/ethash" 36 "github.com/ethereum/go-ethereum/core" 37 "github.com/ethereum/go-ethereum/core/bloombits" 38 "github.com/ethereum/go-ethereum/core/rawdb" 39 "github.com/ethereum/go-ethereum/core/state" 40 "github.com/ethereum/go-ethereum/core/types" 41 "github.com/ethereum/go-ethereum/core/vm" 42 "github.com/ethereum/go-ethereum/eth/filters" 43 "github.com/ethereum/go-ethereum/ethdb" 44 "github.com/ethereum/go-ethereum/event" 45 "github.com/ethereum/go-ethereum/params" 46 "github.com/ethereum/go-ethereum/rpc" 47 ) 48 49 // This nil assignment ensures compile time that SimulatedBackend implements bind.ContractBackend. 50 var _ bind.ContractBackend = (*SimulatedBackend)(nil) 51 52 var ( 53 errBlockNumberUnsupported = errors.New("simulatedBackend cannot access blocks other than the latest block") 54 errGasEstimationFailed = errors.New("gas required exceeds allowance or always failing transaction") 55 ) 56 57 // SimulatedBackend implements bind.ContractBackend, simulating a blockchain in 58 // the background. Its main purpose is to allow easily testing contract bindings. 59 type SimulatedBackend struct { 60 database ethdb.Database // In memory database to store our testing data 61 blockchain *core.BlockChain // Ethereum blockchain to handle the consensus 62 63 mu sync.Mutex 64 pendingBlock *types.Block // Currently pending block that will be imported on request 65 pendingState *state.StateDB // Currently pending state that will be the active on on request 66 67 events *filters.EventSystem // Event system for filtering log events live 68 69 config *params.ChainConfig 70 } 71 72 // NewSimulatedBackendWithDatabase creates a new binding backend based on the given database 73 // and uses a simulated blockchain for testing purposes. 74 func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend { 75 genesis := core.Genesis{Config: params.AllEthashProtocolChanges, GasLimit: gasLimit, Alloc: alloc} 76 genesis.MustCommit(database) 77 blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{}, nil) 78 79 backend := &SimulatedBackend{ 80 database: database, 81 blockchain: blockchain, 82 config: genesis.Config, 83 events: filters.NewEventSystem(new(event.TypeMux), &filterBackend{database, blockchain}, false), 84 } 85 backend.rollback() 86 return backend 87 } 88 89 // NewSimulatedBackend creates a new binding backend using a simulated blockchain 90 // for testing purposes. 91 func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend { 92 return NewSimulatedBackendWithDatabase(rawdb.NewMemoryDatabase(), alloc, gasLimit) 93 } 94 95 // Close terminates the underlying blockchain's update loop. 96 func (b *SimulatedBackend) Close() error { 97 b.blockchain.Stop() 98 return nil 99 } 100 101 // Commit imports all the pending transactions as a single block and starts a 102 // fresh new state. 103 func (b *SimulatedBackend) Commit() { 104 b.mu.Lock() 105 defer b.mu.Unlock() 106 107 if _, err := b.blockchain.InsertChain([]*types.Block{b.pendingBlock}); err != nil { 108 panic(err) // This cannot happen unless the simulator is wrong, fail in that case 109 } 110 b.rollback() 111 } 112 113 // Rollback aborts all pending transactions, reverting to the last committed state. 114 func (b *SimulatedBackend) Rollback() { 115 b.mu.Lock() 116 defer b.mu.Unlock() 117 118 b.rollback() 119 } 120 121 func (b *SimulatedBackend) rollback() { 122 blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), ethash.NewFaker(), b.database, 1, func(int, *core.BlockGen) {}) 123 statedb, _ := b.blockchain.State() 124 125 b.pendingBlock = blocks[0] 126 b.pendingState, _ = state.New(b.pendingBlock.Root(), statedb.Database()) 127 } 128 129 // CodeAt returns the code associated with a certain account in the blockchain. 130 func (b *SimulatedBackend) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) { 131 b.mu.Lock() 132 defer b.mu.Unlock() 133 134 if blockNumber != nil && blockNumber.Cmp(b.blockchain.CurrentBlock().Number()) != 0 { 135 return nil, errBlockNumberUnsupported 136 } 137 statedb, _ := b.blockchain.State() 138 return statedb.GetCode(contract), nil 139 } 140 141 // BalanceAt returns the wei balance of a certain account in the blockchain. 142 func (b *SimulatedBackend) BalanceAt(ctx context.Context, contract common.Address, blockNumber *big.Int) (*big.Int, error) { 143 b.mu.Lock() 144 defer b.mu.Unlock() 145 146 if blockNumber != nil && blockNumber.Cmp(b.blockchain.CurrentBlock().Number()) != 0 { 147 return nil, errBlockNumberUnsupported 148 } 149 statedb, _ := b.blockchain.State() 150 return statedb.GetBalance(contract), nil 151 } 152 153 // BalanceAt returns the wei balance of a certain account in the blockchain. 154 func (b *SimulatedBackend) CTBalanceAt(ctx context.Context, address common.Address, blockNumber *big.Int) (crypto2.Key, error) { 155 b.mu.Lock() 156 defer b.mu.Unlock() 157 158 if blockNumber != nil && blockNumber.Cmp(b.blockchain.CurrentBlock().Number()) != 0 { 159 return crypto2.Key{}, errBlockNumberUnsupported 160 } 161 statedb, _ := b.blockchain.State() 162 return statedb.GetCTBalance(address), nil 163 } 164 165 // NonceAt returns the nonce of a certain account in the blockchain. 166 func (b *SimulatedBackend) NonceAt(ctx context.Context, contract common.Address, blockNumber *big.Int) (uint64, error) { 167 b.mu.Lock() 168 defer b.mu.Unlock() 169 170 if blockNumber != nil && blockNumber.Cmp(b.blockchain.CurrentBlock().Number()) != 0 { 171 return 0, errBlockNumberUnsupported 172 } 173 statedb, _ := b.blockchain.State() 174 return statedb.GetNonce(contract), nil 175 } 176 177 // StorageAt returns the value of key in the storage of an account in the blockchain. 178 func (b *SimulatedBackend) StorageAt(ctx context.Context, contract common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) { 179 b.mu.Lock() 180 defer b.mu.Unlock() 181 182 if blockNumber != nil && blockNumber.Cmp(b.blockchain.CurrentBlock().Number()) != 0 { 183 return nil, errBlockNumberUnsupported 184 } 185 statedb, _ := b.blockchain.State() 186 val := statedb.GetState(contract, key) 187 return val[:], nil 188 } 189 190 // TransactionReceipt returns the receipt of a transaction. 191 func (b *SimulatedBackend) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { 192 receipt, _, _, _ := rawdb.ReadReceipt(b.database, txHash, b.config) 193 return receipt, nil 194 } 195 196 // TransactionByHash checks the pool of pending transactions in addition to the 197 // blockchain. The isPending return value indicates whether the transaction has been 198 // mined yet. Note that the transaction may not be part of the canonical chain even if 199 // it's not pending. 200 func (b *SimulatedBackend) TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error) { 201 b.mu.Lock() 202 defer b.mu.Unlock() 203 204 tx := b.pendingBlock.Transaction(txHash) 205 if tx != nil { 206 return tx, true, nil 207 } 208 tx, _, _, _ = rawdb.ReadTransaction(b.database, txHash) 209 if tx != nil { 210 return tx, false, nil 211 } 212 return nil, false, ethereum.NotFound 213 } 214 215 // PendingCodeAt returns the code associated with an account in the pending state. 216 func (b *SimulatedBackend) PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error) { 217 b.mu.Lock() 218 defer b.mu.Unlock() 219 220 return b.pendingState.GetCode(contract), nil 221 } 222 223 // CallContract executes a contract call. 224 func (b *SimulatedBackend) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { 225 b.mu.Lock() 226 defer b.mu.Unlock() 227 228 if blockNumber != nil && blockNumber.Cmp(b.blockchain.CurrentBlock().Number()) != 0 { 229 return nil, errBlockNumberUnsupported 230 } 231 state, err := b.blockchain.State() 232 if err != nil { 233 return nil, err 234 } 235 rval, _, _, err := b.callContract(ctx, call, b.blockchain.CurrentBlock(), state) 236 return rval, err 237 } 238 239 // PendingCallContract executes a contract call on the pending state. 240 func (b *SimulatedBackend) PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error) { 241 b.mu.Lock() 242 defer b.mu.Unlock() 243 defer b.pendingState.RevertToSnapshot(b.pendingState.Snapshot()) 244 245 rval, _, _, err := b.callContract(ctx, call, b.pendingBlock, b.pendingState) 246 return rval, err 247 } 248 249 // PendingNonceAt implements PendingStateReader.PendingNonceAt, retrieving 250 // the nonce currently pending for the account. 251 func (b *SimulatedBackend) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { 252 b.mu.Lock() 253 defer b.mu.Unlock() 254 255 return b.pendingState.GetOrNewStateObject(account).Nonce(), nil 256 } 257 258 // SuggestGasPrice implements ContractTransactor.SuggestGasPrice. Since the simulated 259 // chain doesn't have miners, we just return a gas price of 1 for any call. 260 func (b *SimulatedBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error) { 261 return big.NewInt(1), nil 262 } 263 264 // EstimateGas executes the requested code against the currently pending block/state and 265 // returns the used amount of gas. 266 func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error) { 267 b.mu.Lock() 268 defer b.mu.Unlock() 269 270 // Determine the lowest and highest possible gas limits to binary search in between 271 var ( 272 lo uint64 = params.TxGas - 1 273 hi uint64 274 cap uint64 275 ) 276 if call.Gas >= params.TxGas { 277 hi = call.Gas 278 } else { 279 hi = b.pendingBlock.GasLimit() 280 } 281 cap = hi 282 283 // Create a helper to check if a gas allowance results in an executable transaction 284 executable := func(gas uint64) bool { 285 call.Gas = gas 286 287 snapshot := b.pendingState.Snapshot() 288 _, _, failed, err := b.callContract(ctx, call, b.pendingBlock, b.pendingState) 289 b.pendingState.RevertToSnapshot(snapshot) 290 291 if err != nil || failed { 292 return false 293 } 294 return true 295 } 296 // Execute the binary search and hone in on an executable gas limit 297 for lo+1 < hi { 298 mid := (hi + lo) / 2 299 if !executable(mid) { 300 lo = mid 301 } else { 302 hi = mid 303 } 304 } 305 // Reject the transaction as invalid if it still fails at the highest allowance 306 if hi == cap { 307 if !executable(hi) { 308 return 0, errGasEstimationFailed 309 } 310 } 311 return hi, nil 312 } 313 314 // callContract implements common code between normal and pending contract calls. 315 // state is modified during execution, make sure to copy it if necessary. 316 func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallMsg, block *types.Block, statedb *state.StateDB) ([]byte, uint64, bool, error) { 317 // Ensure message is initialized properly. 318 if call.GasPrice == nil { 319 call.GasPrice = big.NewInt(1) 320 } 321 if call.Gas == 0 { 322 call.Gas = 50000000 323 } 324 if call.Value == nil { 325 call.Value = new(big.Int) 326 } 327 // Set infinite balance to the fake caller account. 328 from := statedb.GetOrNewStateObject(call.From) 329 from.SetBalance(math.MaxBig256) 330 // Execute the call. 331 msg := callmsg{call} 332 333 evmContext := core.NewEVMContext(msg, block.Header(), b.blockchain, nil) 334 // Create a new environment which holds all relevant information 335 // about the transaction and calling mechanisms. 336 vmenv := vm.NewEVM(evmContext, statedb, b.config, vm.Config{}) 337 gaspool := new(core.GasPool).AddGas(math.MaxUint64) 338 339 return core.NewStateTransition(vmenv, msg, gaspool).TransitionDb() 340 } 341 342 // SendTransaction updates the pending block to include the given transaction. 343 // It panics if the transaction is invalid. 344 func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error { 345 b.mu.Lock() 346 defer b.mu.Unlock() 347 348 sender, err := types.Sender(types.CTSigner{}, tx) 349 if err != nil { 350 panic(fmt.Errorf("invalid transaction: %v", err)) 351 } 352 nonce := b.pendingState.GetNonce(sender) 353 if tx.Nonce() != nonce { 354 panic(fmt.Errorf("invalid transaction nonce: got %d, want %d", tx.Nonce(), nonce)) 355 } 356 357 blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) { 358 for _, tx := range b.pendingBlock.Transactions() { 359 block.AddTxWithChain(b.blockchain, tx) 360 } 361 block.AddTxWithChain(b.blockchain, tx) 362 }) 363 statedb, _ := b.blockchain.State() 364 365 b.pendingBlock = blocks[0] 366 b.pendingState, _ = state.New(b.pendingBlock.Root(), statedb.Database()) 367 return nil 368 } 369 370 // SendTransaction updates the pending block to include the given transaction. 371 // It panics if the transaction is invalid. 372 func (b *SimulatedBackend) SendTransactions(ctx context.Context, txs []*types.Transaction, useBatchBulletproofsVer bool) error { 373 b.mu.Lock() 374 defer b.mu.Unlock() 375 376 blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) { 377 for _, tx := range b.pendingBlock.Transactions() { 378 block.AddTxWithChain(b.blockchain, tx) 379 } 380 if useBatchBulletproofsVer { 381 stateDB, err := b.blockchain.State() 382 if err == nil { 383 var bulletproofs []ringct.BulletProof 384 for i := range txs { 385 if len(txs[i].Bulletproof()) == 0 { 386 continue 387 } 388 bulletproof, err := ringct.ParseBulletProof(bytes.NewReader(txs[i].Bulletproof())) 389 if err == nil { 390 bulletproof.V = make([]crypto2.Key, 2) 391 ctValue := txs[i].CTValue() 392 bulletproof.V[0] = ctValue 393 sender, err := types.Sender(types.CTSigner{}, txs[i]) 394 if err == nil { 395 currentCTBalance := stateDB.GetCTBalance(sender) 396 var afterCTBalance crypto2.Key 397 crypto2.SubKeys(&afterCTBalance, ¤tCTBalance, &ctValue) 398 bulletproof.V[1] = afterCTBalance 399 400 bulletproof.V[0] = *crypto2.ScalarMultKey(&bulletproof.V[0], &crypto2.INV_EIGHT) 401 bulletproof.V[1] = *crypto2.ScalarMultKey(&bulletproof.V[1], &crypto2.INV_EIGHT) 402 bulletproofs = append(bulletproofs, bulletproof) 403 } 404 } 405 } 406 core.InitBulletproofsResultCache(bulletproofs) 407 } 408 } 409 for _, tx := range txs { 410 block.AddTxWithChain(b.blockchain, tx) 411 } 412 }) 413 statedb, _ := b.blockchain.State() 414 415 b.pendingBlock = blocks[0] 416 b.pendingState, _ = state.New(b.pendingBlock.Root(), statedb.Database()) 417 return nil 418 } 419 420 // FilterLogs executes a log filter operation, blocking during execution and 421 // returning all the results in one batch. 422 // 423 // TODO(karalabe): Deprecate when the subscription one can return past data too. 424 func (b *SimulatedBackend) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error) { 425 var filter *filters.Filter 426 if query.BlockHash != nil { 427 // Block filter requested, construct a single-shot filter 428 filter = filters.NewBlockFilter(&filterBackend{b.database, b.blockchain}, *query.BlockHash, query.Addresses, query.Topics) 429 } else { 430 // Initialize unset filter boundaried to run from genesis to chain head 431 from := int64(0) 432 if query.FromBlock != nil { 433 from = query.FromBlock.Int64() 434 } 435 to := int64(-1) 436 if query.ToBlock != nil { 437 to = query.ToBlock.Int64() 438 } 439 // Construct the range filter 440 filter = filters.NewRangeFilter(&filterBackend{b.database, b.blockchain}, from, to, query.Addresses, query.Topics) 441 } 442 // Run the filter and return all the logs 443 logs, err := filter.Logs(ctx) 444 if err != nil { 445 return nil, err 446 } 447 res := make([]types.Log, len(logs)) 448 for i, log := range logs { 449 res[i] = *log 450 } 451 return res, nil 452 } 453 454 // SubscribeFilterLogs creates a background log filtering operation, returning a 455 // subscription immediately, which can be used to stream the found events. 456 func (b *SimulatedBackend) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) { 457 // Subscribe to contract events 458 sink := make(chan []*types.Log) 459 460 sub, err := b.events.SubscribeLogs(query, sink) 461 if err != nil { 462 return nil, err 463 } 464 // Since we're getting logs in batches, we need to flatten them into a plain stream 465 return event.NewSubscription(func(quit <-chan struct{}) error { 466 defer sub.Unsubscribe() 467 for { 468 select { 469 case logs := <-sink: 470 for _, log := range logs { 471 select { 472 case ch <- *log: 473 case err := <-sub.Err(): 474 return err 475 case <-quit: 476 return nil 477 } 478 } 479 case err := <-sub.Err(): 480 return err 481 case <-quit: 482 return nil 483 } 484 } 485 }), nil 486 } 487 488 // AdjustTime adds a time shift to the simulated clock. 489 func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error { 490 b.mu.Lock() 491 defer b.mu.Unlock() 492 blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) { 493 for _, tx := range b.pendingBlock.Transactions() { 494 block.AddTx(tx) 495 } 496 block.OffsetTime(int64(adjustment.Seconds())) 497 }) 498 statedb, _ := b.blockchain.State() 499 500 b.pendingBlock = blocks[0] 501 b.pendingState, _ = state.New(b.pendingBlock.Root(), statedb.Database()) 502 503 return nil 504 } 505 506 // Blockchain returns the underlying blockchain. 507 func (b *SimulatedBackend) Blockchain() *core.BlockChain { 508 return b.blockchain 509 } 510 511 // callmsg implements core.Message to allow passing it as a transaction simulator. 512 type callmsg struct { 513 ethereum.CallMsg 514 } 515 516 func (m callmsg) From() common.Address { return m.CallMsg.From } 517 func (m callmsg) Nonce() uint64 { return 0 } 518 func (m callmsg) CheckNonce() bool { return false } 519 func (m callmsg) TransactionType() types.TransactionType { return types.TRANSACTION_ETH } 520 func (m callmsg) CTValue() crypto2.Key { return crypto2.Key{}} 521 func (m callmsg) Bulletproof() ringct.BulletProof { return ringct.BulletProof{} } 522 func (m callmsg) Challenge() []crypto2.Key { return []crypto2.Key{} } 523 func (m callmsg) ShuffleInputs() []crypto2.Key { return []crypto2.Key{} } 524 func (m callmsg) ShuffleOutputs() []crypto2.Key { return []crypto2.Key{} } 525 func (m callmsg) OutputsGas() []uint64 { return []uint64{} } 526 func (m callmsg) ShuffleProof() []byte { return []byte{} } 527 func (m callmsg) IndividualProofs() []ctcrypto.IndividualProof { return []ctcrypto.IndividualProof{} } 528 func (m callmsg) CTGas() uint64 { return 0} 529 func (m callmsg) To() *common.Address { return m.CallMsg.To } 530 func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice } 531 func (m callmsg) Gas() uint64 { return m.CallMsg.Gas } 532 func (m callmsg) Value() *big.Int { return m.CallMsg.Value } 533 func (m callmsg) Data() []byte { return m.CallMsg.Data } 534 535 // filterBackend implements filters.Backend to support filtering for logs without 536 // taking bloom-bits acceleration structures into account. 537 type filterBackend struct { 538 db ethdb.Database 539 bc *core.BlockChain 540 } 541 542 func (fb *filterBackend) ChainDb() ethdb.Database { return fb.db } 543 func (fb *filterBackend) EventMux() *event.TypeMux { panic("not supported") } 544 545 func (fb *filterBackend) HeaderByNumber(ctx context.Context, block rpc.BlockNumber) (*types.Header, error) { 546 if block == rpc.LatestBlockNumber { 547 return fb.bc.CurrentHeader(), nil 548 } 549 return fb.bc.GetHeaderByNumber(uint64(block.Int64())), nil 550 } 551 552 func (fb *filterBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { 553 return fb.bc.GetHeaderByHash(hash), nil 554 } 555 556 func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) { 557 number := rawdb.ReadHeaderNumber(fb.db, hash) 558 if number == nil { 559 return nil, nil 560 } 561 return rawdb.ReadReceipts(fb.db, hash, *number, fb.bc.Config()), nil 562 } 563 564 func (fb *filterBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) { 565 number := rawdb.ReadHeaderNumber(fb.db, hash) 566 if number == nil { 567 return nil, nil 568 } 569 receipts := rawdb.ReadReceipts(fb.db, hash, *number, fb.bc.Config()) 570 if receipts == nil { 571 return nil, nil 572 } 573 logs := make([][]*types.Log, len(receipts)) 574 for i, receipt := range receipts { 575 logs[i] = receipt.Logs 576 } 577 return logs, nil 578 } 579 580 func (fb *filterBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription { 581 return event.NewSubscription(func(quit <-chan struct{}) error { 582 <-quit 583 return nil 584 }) 585 } 586 func (fb *filterBackend) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription { 587 return fb.bc.SubscribeChainEvent(ch) 588 } 589 func (fb *filterBackend) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription { 590 return fb.bc.SubscribeRemovedLogsEvent(ch) 591 } 592 func (fb *filterBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription { 593 return fb.bc.SubscribeLogsEvent(ch) 594 } 595 596 func (fb *filterBackend) BloomStatus() (uint64, uint64) { return 4096, 0 } 597 func (fb *filterBackend) ServiceFilter(ctx context.Context, ms *bloombits.MatcherSession) { 598 panic("not supported") 599 }