From 2f5413bbcebcec7d4c766427cbbb7db69520549a Mon Sep 17 00:00:00 2001 From: Max Wolter Date: Sat, 13 Aug 2016 13:31:10 +0200 Subject: [PATCH] accounts/abi/bind: now using pending state of code for pending calls --- accounts/abi/bind/base.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/accounts/abi/bind/base.go b/accounts/abi/bind/base.go index 53144f2da1..03fe863372 100644 --- a/accounts/abi/bind/base.go +++ b/accounts/abi/bind/base.go @@ -119,17 +119,22 @@ func (c *BoundContract) Call(opts *CallOpts, result interface{}, method string, opts = new(CallOpts) } // Make sure we have a contract to operate on, and bail out otherwise - if (opts.Pending && atomic.LoadUint32(&c.pendingHasCode) == 0) || (!opts.Pending && atomic.LoadUint32(&c.latestHasCode) == 0) { - if code, err := c.backend.CodeAt(opts.Context, c.address, nil); err != nil { - return err - } else if len(code) == 0 { - return ErrNoCode - } - if opts.Pending { - atomic.StoreUint32(&c.pendingHasCode, 1) - } else { - atomic.StoreUint32(&c.latestHasCode, 1) - } + var code []byte + var err error + if opts.Pending && atomic.LoadUint32(&c.pendingHasCode) == 0 { + code, err = c.backend.PendingCodeAt(opts.Context, c.address) + } else if !opts.Pending && atomic.LoadUint32(&c.latestHasCode) == 0 { + code, err = c.backend.CodeAt(opts.Context, c.address, nil) + } + if err != nil { + return err + } else if len(code) == 0 { + return ErrNoCode + } + if opts.Pending { + atomic.StoreUint32(&c.pendingHasCode, 1) + } else { + atomic.StoreUint32(&c.latestHasCode, 1) } // Pack the input, call and unpack the results input, err := c.abi.Pack(method, params...)