diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-02 19:35:12 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-02 19:35:12 +0800 |
commit | f1da6f0564696f4fb5a6c04d1b9e24ed12432d63 (patch) | |
tree | 692b4c99cad7ceed5013dd03aca1bfccc2fa1260 /utils | |
parent | ee04c6ff6790a9b39ea96a630a60bdcf7f261b97 (diff) | |
download | dexon-f1da6f0564696f4fb5a6c04d1b9e24ed12432d63.tar.gz dexon-f1da6f0564696f4fb5a6c04d1b9e24ed12432d63.tar.zst dexon-f1da6f0564696f4fb5a6c04d1b9e24ed12432d63.zip |
Fixed samplecoin
Diffstat (limited to 'utils')
-rw-r--r-- | utils/ethereum.go | 27 | ||||
-rw-r--r-- | utils/types.go | 10 |
2 files changed, 24 insertions, 13 deletions
diff --git a/utils/ethereum.go b/utils/ethereum.go index c383c4c91..526795894 100644 --- a/utils/ethereum.go +++ b/utils/ethereum.go @@ -1,6 +1,7 @@ package utils import ( + "fmt" "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" @@ -28,8 +29,13 @@ func (lib *PEthereum) GetBlock(hexHash string) *PBlock { return &PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} } -func (lib *PEthereum) GetKey() string { - return ethutil.Hex(ethutil.Config.Db.GetKeys()[0].Address()) +func (lib *PEthereum) GetKey() *PKey { + keyPair, err := ethchain.NewKeyPairFromSec(ethutil.Config.Db.GetKeys()[0].PrivateKey) + if err != nil { + return nil + } + + return NewPKey(keyPair) } func (lib *PEthereum) GetStateObject(address string) *PStateObject { @@ -59,7 +65,7 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in hash = ethutil.FromHex(recipient) } - keyPair, err := ethchain.NewKeyPairFromSec([]byte(key)) + keyPair, err := ethchain.NewKeyPairFromSec([]byte(ethutil.FromHex(key))) if err != nil { return "", err } @@ -81,15 +87,12 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in tx = ethchain.NewContractCreationTx(value, gas, gasPrice, mainScript, initScript) } else { - /* - lines := strings.Split(dataStr, "\n") - var data []byte - for _, line := range lines { - data = append(data, ethutil.BigToBytes(ethutil.Big(line), 256)...) - } - */ - - tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, []byte(initStr)) + // Just in case it was submitted as a 0x prefixed string + if initStr[0:2] == "0x" { + initStr = initStr[2:len(initStr)] + } + fmt.Println("DATA:", initStr) + tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, ethutil.FromHex(initStr)) } acc := lib.stateManager.GetAddrState(keyPair.Address()) diff --git a/utils/types.go b/utils/types.go index 44264aa5e..0bbc61627 100644 --- a/utils/types.go +++ b/utils/types.go @@ -34,9 +34,16 @@ func NewPTx(tx *ethchain.Transaction) *PTx { } type PKey struct { - Address string + Address string + PrivateKey string + PublicKey string } +func NewPKey(key *ethchain.KeyPair) *PKey { + return &PKey{ethutil.Hex(key.Address()), ethutil.Hex(key.PrivateKey), ethutil.Hex(key.PublicKey)} +} + +/* type PKeyRing struct { Keys []interface{} } @@ -44,6 +51,7 @@ type PKeyRing struct { func NewPKeyRing(keys []interface{}) *PKeyRing { return &PKeyRing{Keys: keys} } +*/ type PStateObject struct { object *ethchain.StateObject |