本文整理汇总了Golang中github.com/expanse-project/go-expanse/common.FromHex函数的典型用法代码示例。如果您正苦于以下问题:Golang FromHex函数的具体用法?Golang FromHex怎么用?Golang FromHex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FromHex函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Post
// Post injects a message into the whisper network for distribution.
func (self *Whisper) Post(payload string, to, from string, topics []string, priority, ttl uint32) error {
// Decode the topic strings
topicsDecoded := make([][]byte, len(topics))
for i, topic := range topics {
topicsDecoded[i] = common.FromHex(topic)
}
// Construct the whisper message and transmission options
message := whisper.NewMessage(common.FromHex(payload))
options := whisper.Options{
To: crypto.ToECDSAPub(common.FromHex(to)),
TTL: time.Duration(ttl) * time.Second,
Topics: whisper.NewTopics(topicsDecoded...),
}
if len(from) != 0 {
if key := self.Whisper.GetIdentity(crypto.ToECDSAPub(common.FromHex(from))); key != nil {
options.From = key
} else {
return fmt.Errorf("unknown identity to send from: %s", from)
}
}
// Wrap and send the message
pow := time.Duration(priority) * time.Millisecond
envelope, err := message.Wrap(pow, options)
if err != nil {
return err
}
if err := self.Whisper.Send(envelope); err != nil {
return err
}
return nil
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:32,代码来源:whisper.go
示例2: NewFilter
// NewWhisperFilter creates and registers a new message filter to watch for inbound whisper messages.
func (s *PublicWhisperAPI) NewFilter(args NewFilterArgs) (*rpc.HexNumber, error) {
if s.w == nil {
return nil, whisperOffLineErr
}
var id int
filter := Filter{
To: crypto.ToECDSAPub(common.FromHex(args.To)),
From: crypto.ToECDSAPub(common.FromHex(args.From)),
Topics: NewFilterTopics(args.Topics...),
Fn: func(message *Message) {
wmsg := NewWhisperMessage(message)
s.messagesMu.RLock() // Only read lock to the filter pool
defer s.messagesMu.RUnlock()
if s.messages[id] != nil {
s.messages[id].insert(wmsg)
}
},
}
id = s.w.Watch(filter)
s.messagesMu.Lock()
s.messages[id] = newWhisperFilter(id, s.w)
s.messagesMu.Unlock()
return rpc.NewHexNumber(id), nil
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:29,代码来源:api.go
示例3: Post
// Post injects a message into the whisper network for distribution.
func (s *PublicWhisperAPI) Post(args PostArgs) (bool, error) {
if s.w == nil {
return false, whisperOffLineErr
}
// construct whisper message with transmission options
message := NewMessage(common.FromHex(args.Payload))
options := Options{
To: crypto.ToECDSAPub(common.FromHex(args.To)),
TTL: time.Duration(args.TTL) * time.Second,
Topics: NewTopics(args.Topics...),
}
// set sender identity
if len(args.From) > 0 {
if key := s.w.GetIdentity(crypto.ToECDSAPub(common.FromHex(args.From))); key != nil {
options.From = key
} else {
return false, fmt.Errorf("unknown identity to send from: %s", args.From)
}
}
// Wrap and send the message
pow := time.Duration(args.Priority) * time.Millisecond
envelope, err := message.Wrap(pow, options)
if err != nil {
return false, err
}
return true, s.w.Send(envelope)
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:32,代码来源:api.go
示例4: checkLogs
func checkLogs(tlog []Log, logs vm.Logs) error {
if len(tlog) != len(logs) {
return fmt.Errorf("log length mismatch. Expected %d, got %d", len(tlog), len(logs))
} else {
for i, log := range tlog {
if common.HexToAddress(log.AddressF) != logs[i].Address {
return fmt.Errorf("log address expected %v got %x", log.AddressF, logs[i].Address)
}
if !bytes.Equal(logs[i].Data, common.FromHex(log.DataF)) {
return fmt.Errorf("log data expected %v got %x", log.DataF, logs[i].Data)
}
if len(log.TopicsF) != len(logs[i].Topics) {
return fmt.Errorf("log topics length expected %d got %d", len(log.TopicsF), logs[i].Topics)
} else {
for j, topic := range log.TopicsF {
if common.HexToHash(topic) != logs[i].Topics[j] {
return fmt.Errorf("log topic[%d] expected %v got %x", j, topic, logs[i].Topics[j])
}
}
}
genBloom := common.LeftPadBytes(types.LogsBloom(vm.Logs{logs[i]}).Bytes(), 256)
if !bytes.Equal(genBloom, common.Hex2Bytes(log.BloomF)) {
return fmt.Errorf("bloom mismatch")
}
}
}
return nil
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:32,代码来源:util.go
示例5: TestNull
func TestNull(t *testing.T) {
var trie Trie
key := make([]byte, 32)
value := common.FromHex("0x823140710bf13990e4500136726d8b55")
trie.Update(key, value)
value = trie.Get(key)
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:7,代码来源:trie_test.go
示例6: UnmarshalJSON
func (args *DbHexArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) < 2 {
return shared.NewInsufficientParamsError(len(obj), 2)
}
var objstr string
var ok bool
if objstr, ok = obj[0].(string); !ok {
return shared.NewInvalidTypeError("database", "not a string")
}
args.Database = objstr
if objstr, ok = obj[1].(string); !ok {
return shared.NewInvalidTypeError("key", "not a string")
}
args.Key = objstr
if len(obj) > 2 {
objstr, ok = obj[2].(string)
if !ok {
return shared.NewInvalidTypeError("value", "not a string")
}
args.Value = common.FromHex(objstr)
}
return nil
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:34,代码来源:db_args.go
示例7: TestLoadECDSAFile
func TestLoadECDSAFile(t *testing.T) {
keyBytes := common.FromHex(testPrivHex)
fileName0 := "test_key0"
fileName1 := "test_key1"
checkKey := func(k *ecdsa.PrivateKey) {
checkAddr(t, PubkeyToAddress(k.PublicKey), common.HexToAddress(testAddrHex))
loadedKeyBytes := FromECDSA(k)
if !bytes.Equal(loadedKeyBytes, keyBytes) {
t.Fatalf("private key mismatch: want: %x have: %x", keyBytes, loadedKeyBytes)
}
}
ioutil.WriteFile(fileName0, []byte(testPrivHex), 0600)
defer os.Remove(fileName0)
key0, err := LoadECDSA(fileName0)
if err != nil {
t.Fatal(err)
}
checkKey(key0)
// again, this time with SaveECDSA instead of manual save:
err = SaveECDSA(fileName1, key0)
if err != nil {
t.Fatal(err)
}
defer os.Remove(fileName1)
key1, err := LoadECDSA(fileName1)
if err != nil {
t.Fatal(err)
}
checkKey(key1)
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:34,代码来源:crypto_test.go
示例8: UnmarshalJSON
func (args *PostArgs) UnmarshalJSON(data []byte) (err error) {
var obj struct {
From string `json:"from"`
To string `json:"to"`
Topics []string `json:"topics"`
Payload string `json:"payload"`
Priority rpc.HexNumber `json:"priority"`
TTL rpc.HexNumber `json:"ttl"`
}
if err := json.Unmarshal(data, &obj); err != nil {
return err
}
args.From = obj.From
args.To = obj.To
args.Payload = obj.Payload
args.Priority = obj.Priority.Int64()
args.TTL = obj.TTL.Int64()
// decode topic strings
args.Topics = make([][]byte, len(obj.Topics))
for i, topic := range obj.Topics {
args.Topics[i] = common.FromHex(topic)
}
return nil
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:28,代码来源:api.go
示例9: PushTx
func (self *XEth) PushTx(encodedTx string) (string, error) {
tx := new(types.Transaction)
err := rlp.DecodeBytes(common.FromHex(encodedTx), tx)
if err != nil {
glog.V(logger.Error).Infoln(err)
return "", err
}
err = self.backend.TxPool().Add(tx)
if err != nil {
return "", err
}
if tx.To() == nil {
from, err := tx.From()
if err != nil {
return "", err
}
addr := crypto.CreateAddress(from, tx.Nonce())
glog.V(logger.Info).Infof("Tx(%x) created: %x\n", tx.Hash(), addr)
} else {
glog.V(logger.Info).Infof("Tx(%x) to: %x\n", tx.Hash(), tx.To())
}
return tx.Hash().Hex(), nil
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:27,代码来源:xeth.go
示例10: FromNumber
func (self *XEth) FromNumber(str string) string {
if common.IsHex(str) {
str = str[2:]
}
return common.BigD(common.FromHex(str)).String()
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:7,代码来源:xeth.go
示例11: FromAscii
func (self *XEth) FromAscii(str string) string {
if common.IsHex(str) {
str = str[2:]
}
return string(bytes.Trim(common.FromHex(str), "\x00"))
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:7,代码来源:xeth.go
示例12: RunState
func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, vm.Logs, *big.Int, error) {
var (
data = common.FromHex(tx["data"])
gas = common.Big(tx["gasLimit"])
price = common.Big(tx["gasPrice"])
value = common.Big(tx["value"])
nonce = common.Big(tx["nonce"]).Uint64()
)
var to *common.Address
if len(tx["to"]) > 2 {
t := common.HexToAddress(tx["to"])
to = &t
}
// Set pre compiled contracts
vm.Precompiled = vm.PrecompiledContracts()
vm.Debug = false
snapshot := statedb.Copy()
gaspool := new(core.GasPool).AddGas(common.Big(env["currentGasLimit"]))
key, _ := hex.DecodeString(tx["secretKey"])
addr := crypto.PubkeyToAddress(crypto.ToECDSA(key).PublicKey)
message := NewMessage(addr, to, data, value, gas, price, nonce)
vmenv := NewEnvFromMap(statedb, env, tx)
vmenv.origin = addr
ret, _, err := core.ApplyMessage(vmenv, message, gaspool)
if core.IsNonceErr(err) || core.IsInvalidTxErr(err) || core.IsGasLimitErr(err) {
statedb.Set(snapshot)
}
statedb.Commit()
return ret, vmenv.state.Logs(), vmenv.Gas, err
}
开发者ID:5mil,项目名称:go-expanse,代码行数:33,代码来源:state_test_util.go
示例13: 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("exp_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
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:27,代码来源:remote.go
示例14: 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
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:9,代码来源:web3.go
示例15: HasCode
// HasCode implements bind.ContractVerifier.HasCode by retrieving any code associated
// with the contract from the local API, and checking its size.
func (b *ContractBackend) HasCode(contract common.Address, pending bool) (bool, error) {
block := rpc.LatestBlockNumber
if pending {
block = rpc.PendingBlockNumber
}
out, err := b.bcapi.GetCode(contract, block)
return len(common.FromHex(out)) > 0, err
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:10,代码来源:bind.go
示例16: TestTransactionEncode
func TestTransactionEncode(t *testing.T) {
txb, err := rlp.EncodeToBytes(rightvrsTx)
if err != nil {
t.Fatalf("encode error: %v", err)
}
should := common.FromHex("f86103018207d094b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a8255441ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa08887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3")
if !bytes.Equal(txb, should) {
t.Errorf("encoded RLP mismatch, got %x", txb)
}
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:10,代码来源:transaction_test.go
示例17: Watch
// Watch installs a new message handler to run in case a matching packet arrives
// from the whisper network.
func (self *Whisper) Watch(to, from string, topics [][]string, fn func(WhisperMessage)) int {
// Decode the topic strings
topicsDecoded := make([][][]byte, len(topics))
for i, condition := range topics {
topicsDecoded[i] = make([][]byte, len(condition))
for j, topic := range condition {
topicsDecoded[i][j] = common.FromHex(topic)
}
}
// Assemble and inject the filter into the whisper client
filter := whisper.Filter{
To: crypto.ToECDSAPub(common.FromHex(to)),
From: crypto.ToECDSAPub(common.FromHex(from)),
Topics: whisper.NewFilterTopics(topicsDecoded...),
}
filter.Fn = func(message *whisper.Message) {
fn(NewWhisperMessage(message))
}
return self.Whisper.Watch(filter)
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:22,代码来源:whisper.go
示例18: DeployReleaseOracle
// DeployReleaseOracle deploys a new Expanse contract, binding an instance of ReleaseOracle to it.
func DeployReleaseOracle(auth *bind.TransactOpts, backend bind.ContractBackend, signers []common.Address) (common.Address, *types.Transaction, *ReleaseOracle, error) {
parsed, err := abi.JSON(strings.NewReader(ReleaseOracleABI))
if err != nil {
return common.Address{}, nil, nil, err
}
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(ReleaseOracleBin), backend, signers)
if err != nil {
return common.Address{}, nil, nil, err
}
return address, tx, &ReleaseOracle{ReleaseOracleCaller: ReleaseOracleCaller{contract: contract}, ReleaseOracleTransactor: ReleaseOracleTransactor{contract: contract}}, nil
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:12,代码来源:contract.go
示例19: SignTransaction
func (self *XEth) SignTransaction(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceStr, codeStr string) (*types.Transaction, error) {
if len(toStr) > 0 && toStr != "0x" && !isAddress(toStr) {
return nil, errors.New("Invalid address")
}
var (
from = common.HexToAddress(fromStr)
to = common.HexToAddress(toStr)
value = common.Big(valueStr)
gas *big.Int
price *big.Int
data []byte
contractCreation bool
)
if len(gasStr) == 0 {
gas = DefaultGas()
} else {
gas = common.Big(gasStr)
}
if len(gasPriceStr) == 0 {
price = self.DefaultGasPrice()
} else {
price = common.Big(gasPriceStr)
}
data = common.FromHex(codeStr)
if len(toStr) == 0 {
contractCreation = true
}
var nonce uint64
if len(nonceStr) != 0 {
nonce = common.Big(nonceStr).Uint64()
} else {
state := self.backend.TxPool().State()
nonce = state.GetNonce(from)
}
var tx *types.Transaction
if contractCreation {
tx = types.NewContractCreation(nonce, value, gas, price, data)
} else {
tx = types.NewTransaction(nonce, to, value, gas, price, data)
}
signed, err := self.sign(tx, from, false)
if err != nil {
return nil, err
}
return signed, nil
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:53,代码来源:xeth.go
示例20: Call
func (self *ethApi) Call(req *shared.Request) (interface{}, error) {
v, _, err := self.doCall(req.Params)
if err != nil {
return nil, err
}
// TODO unwrap the parent method's ToHex call
if v == "0x0" {
return newHexData([]byte{}), nil
} else {
return newHexData(common.FromHex(v)), nil
}
}
开发者ID:5mil,项目名称:go-expanse,代码行数:13,代码来源:eth.go
注:本文中的github.com/expanse-project/go-expanse/common.FromHex函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论