本文整理匯總了Golang中github.com/ethereum/go-ethereum/common.ToHex函數的典型用法代碼示例。如果您正苦於以下問題:Golang ToHex函數的具體用法?Golang ToHex怎麽用?Golang ToHex使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ToHex函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewReciept
func NewReciept(contractCreation bool, creationAddress, hash, address []byte) *Receipt {
return &Receipt{
contractCreation,
common.ToHex(creationAddress),
common.ToHex(hash),
common.ToHex(address),
}
}
示例2: Storage
func (self *Object) Storage() (storage map[string]string) {
storage = make(map[string]string)
it := self.StateObject.Trie().Iterator()
for it.Next() {
var data []byte
rlp.Decode(bytes.NewReader(it.Value), &data)
storage[common.ToHex(self.Trie().GetKey(it.Key))] = common.ToHex(data)
}
return
}
示例3: NewWhisperMessage
// NewWhisperMessage converts an internal message into an API version.
func NewWhisperMessage(message *whisper.Message) WhisperMessage {
return WhisperMessage{
ref: message,
Payload: common.ToHex(message.Payload),
From: common.ToHex(crypto.FromECDSAPub(message.Recover())),
To: common.ToHex(crypto.FromECDSAPub(message.To)),
Sent: message.Sent.Unix(),
TTL: int64(message.TTL / time.Second),
Hash: common.ToHex(message.Hash.Bytes()),
}
}
示例4: getWorkPackage
func getWorkPackage(difficulty *big.Int) string {
if currWork == nil {
return getErrorResponse("Current work unavailable")
}
// Our response object
response := &ResponseArray{
Id: currWork.Id,
Jsonrpc: currWork.Jsonrpc,
Result: currWork.Result[:],
}
// Calculte requested difficulty
diff := new(big.Int).Div(pow256, difficulty)
diffBytes := string(common.ToHex(diff.Bytes()))
// Adjust the difficulty for the miner
response.Result[2] = diffBytes
// Convert respone object to JSON
b, _ := json.Marshal(response)
return string(b)
}
示例5: EachStorage
func (self *XEth) EachStorage(addr string) string {
var values []KeyVal
object := self.State().SafeGet(addr)
it := object.Trie().Iterator()
for it.Next() {
values = append(values, KeyVal{common.ToHex(object.Trie().GetKey(it.Key)), common.ToHex(it.Value)})
}
valuesJson, err := json.Marshal(values)
if err != nil {
return ""
}
return string(valuesJson)
}
示例6: NewTx
func NewTx(tx *types.Transaction) *Transaction {
sender, err := tx.From()
if err != nil {
return nil
}
hash := tx.Hash().Hex()
var receiver string
if to := tx.To(); to != nil {
receiver = to.Hex()
} else {
from, _ := tx.From()
receiver = crypto.CreateAddress(from, tx.Nonce()).Hex()
}
createsContract := core.MessageCreatesContract(tx)
var data string
if createsContract {
data = strings.Join(core.Disassemble(tx.Data()), "\n")
} else {
data = common.ToHex(tx.Data())
}
return &Transaction{ref: tx, Hash: hash, Value: common.CurrencyToString(tx.Value()), Address: receiver, Contract: createsContract, Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender.Hex(), CreatesContract: createsContract, RawData: common.ToHex(tx.Data())}
}
示例7: EstimateGasLimit
// EstimateGasLimit implements ContractTransactor.EstimateGasLimit, delegating
// the gas estimation to the remote node.
func (b *rpcBackend) EstimateGasLimit(sender common.Address, contract *common.Address, value *big.Int, data []byte) (*big.Int, error) {
// Pack up the request into an RPC argument
args := struct {
From common.Address `json:"from"`
To *common.Address `json:"to"`
Value *rpc.HexNumber `json:"value"`
Data string `json:"data"`
}{
From: sender,
To: contract,
Data: common.ToHex(data),
Value: rpc.NewHexNumber(value),
}
// Execute the RPC call and retrieve the response
res, err := b.request("eth_estimateGas", []interface{}{args})
if err != nil {
return nil, err
}
var hex string
if err := json.Unmarshal(res, &hex); err != nil {
return nil, err
}
estimate, ok := new(big.Int).SetString(hex, 0)
if !ok {
return nil, fmt.Errorf("invalid estimate hex: %s", hex)
}
return estimate, nil
}
示例8: ContractCall
// ContractCall implements ContractCaller.ContractCall, delegating the execution of
// a contract call to the remote node, returning the reply to for local processing.
func (b *rpcBackend) ContractCall(contract common.Address, data []byte, pending bool) ([]byte, error) {
// Pack up the request into an RPC argument
args := struct {
To common.Address `json:"to"`
Data string `json:"data"`
}{
To: contract,
Data: common.ToHex(data),
}
// Execute the RPC call and retrieve the response
block := "latest"
if pending {
block = "pending"
}
res, err := b.request("eth_call", []interface{}{args, block})
if err != nil {
return nil, err
}
var hex string
if err := json.Unmarshal(res, &hex); err != nil {
return nil, err
}
// Convert the response back to a Go byte slice and return
return common.FromHex(hex), nil
}
示例9: NewBlock
// Creates a new QML Block from a chain block
func NewBlock(block *types.Block) *Block {
if block == nil {
return &Block{}
}
ptxs := make([]*Transaction, len(block.Transactions()))
/*
for i, tx := range block.Transactions() {
ptxs[i] = NewTx(tx)
}
*/
txlist := common.NewList(ptxs)
puncles := make([]*Block, len(block.Uncles()))
/*
for i, uncle := range block.Uncles() {
puncles[i] = NewBlock(types.NewBlockWithHeader(uncle))
}
*/
ulist := common.NewList(puncles)
return &Block{
ref: block, Size: block.Size().String(),
Number: int(block.NumberU64()), GasUsed: block.GasUsed().String(),
GasLimit: block.GasLimit().String(), Hash: block.Hash().Hex(),
Transactions: txlist, Uncles: ulist,
Time: block.Time(),
Coinbase: block.Coinbase().Hex(),
PrevHash: block.ParentHash().Hex(),
Bloom: common.ToHex(block.Bloom().Bytes()),
Raw: block.String(),
}
}
示例10: startEth
func startEth(ctx *cli.Context, eth *eth.Ethereum) {
// Start Ethereum itself
utils.StartEthereum(eth)
am := eth.AccountManager()
account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
if len(account) > 0 {
if account == "primary" {
accbytes, err := am.Primary()
if err != nil {
utils.Fatalf("no primary account: %v", err)
}
account = common.ToHex(accbytes)
}
unlockAccount(ctx, am, account)
}
// Start auxiliary services if enabled.
if ctx.GlobalBool(utils.RPCEnabledFlag.Name) {
if err := utils.StartRPC(eth, ctx); err != nil {
utils.Fatalf("Error starting RPC: %v", err)
}
}
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) {
if err := eth.StartMining(); err != nil {
utils.Fatalf("%v", err)
}
}
}
示例11: SecretToAddress
func (self *XEth) SecretToAddress(key string) string {
pair, err := crypto.NewKeyPairFromSec(common.FromHex(key))
if err != nil {
return ""
}
return common.ToHex(pair.Address())
}
示例12: Sha3
// Calculates the sha3 over req.Params.Data
func (self *web3Api) Sha3(req *shared.Request) (interface{}, error) {
args := new(Sha3Args)
if err := self.codec.Decode(req.Params, &args); err != nil {
return nil, err
}
return common.ToHex(crypto.Sha3(common.FromHex(args.Data))), nil
}
示例13: NewIdentity
// NewIdentity generates a new cryptographic identity for the client, and injects
// it into the known identities for message decryption.
func (s *PublicWhisperAPI) NewIdentity() (string, error) {
if s.w == nil {
return "", whisperOffLineErr
}
identity := s.w.NewIdentity()
return common.ToHex(crypto.FromECDSAPub(&identity.PublicKey)), nil
}
示例14: initUrlHint
func (self *testBackend) initUrlHint() {
self.contracts[UrlHintAddr[2:]] = make(map[string]string)
mapaddr := storageMapping(storageIdx2Addr(1), hash[:])
key := storageAddress(storageFixedArray(mapaddr, storageIdx2Addr(0)))
self.contracts[UrlHintAddr[2:]][key] = common.ToHex([]byte(url))
key = storageAddress(storageFixedArray(mapaddr, storageIdx2Addr(1)))
self.contracts[UrlHintAddr[2:]][key] = "0x0"
}
示例15: EstimateGasLimit
// EstimateGasLimit implements bind.ContractTransactor triing to estimate the gas
// needed to execute a specific transaction based on the current pending state of
// the backend blockchain. There is no guarantee that this is the true gas limit
// requirement as other transactions may be added or removed by miners, but it
// should provide a basis for setting a reasonable default.
func (b *ContractBackend) EstimateGasLimit(sender common.Address, contract *common.Address, value *big.Int, data []byte) (*big.Int, error) {
out, err := b.bcapi.EstimateGas(CallArgs{
From: sender,
To: contract,
Value: *rpc.NewHexNumber(value),
Data: common.ToHex(data),
})
return out.BigInt(), err
}