本文整理匯總了Golang中github.com/gophergala2016/etherapis/etherapis/Godeps/_workspace/src/github.com/ethereum/go-ethereum/common.Address.Hash方法的典型用法代碼示例。如果您正苦於以下問題:Golang Address.Hash方法的具體用法?Golang Address.Hash怎麽用?Golang Address.Hash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gophergala2016/etherapis/etherapis/Godeps/_workspace/src/github.com/ethereum/go-ethereum/common.Address
的用法示例。
在下文中一共展示了Address.Hash方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewChannel
// Start Go API. Not important for this version
func (c *Channels) NewChannel(key *ecdsa.PrivateKey, to common.Address, amount, price *big.Int, cb func(*Channel)) (*types.Transaction, error) {
from := crypto.PubkeyToAddress(key.PublicKey)
data, err := c.abi.Pack("createChannel", to, price)
if err != nil {
return nil, err
}
statedb, err := c.blockchain.State()
if err != nil {
return nil, err
}
transaction, err := types.NewTransaction(statedb.GetNonce(from), contractAddress, amount, big.NewInt(250000), big.NewInt(50000000000), data).SignECDSA(key)
if err != nil {
return nil, err
}
evId := c.abi.Events["NewChannel"].Id()
filter := filters.New(c.db)
filter.SetAddresses([]common.Address{contractAddress})
filter.SetTopics([][]common.Hash{ // TODO refactor, helper
[]common.Hash{evId},
[]common.Hash{from.Hash()},
[]common.Hash{to.Hash()},
})
filter.SetBeginBlock(0)
filter.SetEndBlock(-1)
filter.LogsCallback = func(logs vm.Logs) {
// tere should really be only one log. TODO this part
log := logs[0]
// TODO: do to and from validation here
/*
from := log.Topics[1]
to := log.Topics[2]
*/
channelId := common.BytesToHash(log.Data[0:31])
nonce := common.BytesToBig(log.Data[31:])
c.channelMu.Lock()
defer c.channelMu.Unlock()
channel, exist := c.channels[channelId]
if !exist {
channel = NewChannel(c, channelId, from, to, nonce)
c.channels[channelId] = channel
}
cb(channel)
}
c.filters.Add(filter)
return transaction, nil
}