diff options
author | Maran <maran.hidskes@gmail.com> | 2014-04-01 19:18:42 +0800 |
---|---|---|
committer | Maran <maran.hidskes@gmail.com> | 2014-04-01 19:18:42 +0800 |
commit | ee5e7f2b350202ed2d2e64265d18d0462bd21c91 (patch) | |
tree | 8ea2a6305d58e8d56b16e9869850961b61b7d25c /ethereal/ui/library.go | |
parent | a30f5730b384bf99d23f6e83b356e27a14f961d1 (diff) | |
parent | e403b28eea6959c1d0ed003d955df3dee586083b (diff) | |
download | go-tangerine-ee5e7f2b350202ed2d2e64265d18d0462bd21c91.tar go-tangerine-ee5e7f2b350202ed2d2e64265d18d0462bd21c91.tar.gz go-tangerine-ee5e7f2b350202ed2d2e64265d18d0462bd21c91.tar.bz2 go-tangerine-ee5e7f2b350202ed2d2e64265d18d0462bd21c91.tar.lz go-tangerine-ee5e7f2b350202ed2d2e64265d18d0462bd21c91.tar.xz go-tangerine-ee5e7f2b350202ed2d2e64265d18d0462bd21c91.tar.zst go-tangerine-ee5e7f2b350202ed2d2e64265d18d0462bd21c91.zip |
Fix merge conflict
Diffstat (limited to 'ethereal/ui/library.go')
-rw-r--r-- | ethereal/ui/library.go | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 05fffd579..6f8cb6f65 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" + "github.com/obscuren/mutan" "strings" ) @@ -14,6 +15,50 @@ type EthLib struct { txPool *ethchain.TxPool } +func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) string { + var hash []byte + var contractCreation bool + if len(recipient) == 0 { + contractCreation = true + } else { + var err error + hash, err = hex.DecodeString(recipient) + if err != nil { + return err.Error() + } + } + + keyPair := ethutil.Config.Db.GetKeys()[0] + value := ethutil.Big(valueStr) + gas := ethutil.Big(gasStr) + gasPrice := ethutil.Big(gasPriceStr) + var tx *ethchain.Transaction + // Compile and assemble the given data + if contractCreation { + asm, err := mutan.Compile(strings.NewReader(data), false) + if err != nil { + return err.Error() + } + + code := ethutil.Assemble(asm...) + tx = ethchain.NewContractCreationTx(value, gasPrice, code) + } else { + tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, []string{}) + } + tx.Nonce = lib.stateManager.GetAddrState(keyPair.Address()).Nonce + tx.Sign(keyPair.PrivateKey) + lib.txPool.QueueTransaction(tx) + + if contractCreation { + ethutil.Config.Log.Infof("Contract addr %x", tx.Hash()[12:]) + } else { + ethutil.Config.Log.Infof("Tx hash %x", tx.Hash()) + } + + return ethutil.Hex(tx.Hash()) +} + +/* func (lib *EthLib) CreateTx(receiver, a, data string) string { var hash []byte if len(receiver) == 0 { @@ -31,7 +76,7 @@ func (lib *EthLib) CreateTx(receiver, a, data string) string { amount := ethutil.Big(a) code := ethchain.Compile(strings.Split(data, "\n")) - tx := ethchain.NewTransaction(hash, amount, code) + tx := ethchain.NewTx(hash, amount, code) tx.Nonce = lib.stateManager.GetAddrState(keyPair.Address()).Nonce tx.Sign(keyPair.PrivateKey) @@ -46,6 +91,7 @@ func (lib *EthLib) CreateTx(receiver, a, data string) string { return ethutil.Hex(tx.Hash()) } +*/ func (lib *EthLib) GetBlock(hexHash string) *Block { hash, err := hex.DecodeString(hexHash) |