Fixed samplecoin

pull/84/head
obscuren 11 years ago
parent ee04c6ff67
commit f1da6f0564
  1. 5
      ethereal/assets/ethereum.js
  2. 1
      ethereal/assets/qml/webapp.qml
  3. 28
      ethereal/assets/samplecoin/samplecoin.html
  4. 27
      utils/ethereum.go
  5. 10
      utils/types.go

@ -19,8 +19,7 @@ window.eth = {
// Create transaction // Create transaction
// //
// Creates a transaction with the current account // Transact between two state objects
// If no recipient is set, the Ethereum API will see it as a contract creation
transact: function(sec, recipient, value, gas, gasPrice, data, cb) { transact: function(sec, recipient, value, gas, gasPrice, data, cb) {
postData({call: "transact", args: [sec, recipient, value, gas, gasPrice, data]}, cb); postData({call: "transact", args: [sec, recipient, value, gas, gasPrice, data]}, cb);
}, },
@ -202,7 +201,7 @@ String.prototype.unbin = function() {
String.prototype.hex2bin = function() { String.prototype.hex2bin = function() {
bytes = [] bytes = []
for(var i=2; i< this.length-1; i+=2){ for(var i=2; i< this.length-1; i+=2) {
bytes.push(parseInt(this.substr(i, 2), 16)); bytes.push(parseInt(this.substr(i, 2), 16));
} }

@ -60,6 +60,7 @@ ApplicationWindow {
var tx = eth.transact(data.args[0], data.args[1], data.args[2],data.args[3],data.args[4],data.args[5]) var tx = eth.transact(data.args[0], data.args[1], data.args[2],data.args[3],data.args[4],data.args[5])
postData(data._seed, tx) postData(data._seed, tx)
break break
case "create": case "create":
postData(data._seed, null) postData(data._seed, null)

@ -9,13 +9,14 @@
<script type="text/javascript"> <script type="text/javascript">
var jefcoinAddr = "3dff537f51350239abc95c76a5864aa605259e7d" var jefcoinAddr = "3dff537f51350239abc95c76a5864aa605259e7d"
var mAddr = ""
function createTransaction() { function createTransaction() {
var addr = document.querySelector("#addr").value; var addr = document.querySelector("#addr").value;
var amount = document.querySelector("#amount").value; var amount = document.querySelector("#amount").value;
var data = "0x" + addr + "\n" + amount var data = (("0x"+addr).pad(32) + amount.pad(32)).unbin()
eth.transact("", jefcoinAddr, 0, "10000000", "250", data, function(tx) { eth.transact(mAddr, jefcoinAddr, 0, "10000000", "250", data, function(tx) {
debug("received tx hash:", tx) debug("received tx hash:", tx)
}) })
} }
@ -23,13 +24,15 @@ function createTransaction() {
function init() { function init() {
eth.set({width: 500}) eth.set({width: 500})
eth.getKey(function(key) { eth.getKey(function(keyPair) {
eth.getStorageAt(jefcoinAddr, key, function(storage) { mAddr = keyPair.privateKey;
eth.getStorageAt(jefcoinAddr, keyPair.address, function(storage) {
document.querySelector("#current-amount").innerHTML = storage; document.querySelector("#current-amount").innerHTML = storage;
}); });
eth.watch(jefcoinAddr, function(stateObject) { eth.watch(jefcoinAddr, function(stateObject) {
eth.getStorageAt(jefcoinAddr, key, function(storage) { eth.getStorageAt(jefcoinAddr, keyPair.address, function(storage) {
document.querySelector("#current-amount").innerHTML = storage; document.querySelector("#current-amount").innerHTML = storage;
}); });
}); });
@ -50,19 +53,18 @@ function init() {
<div>Amount: <strong id="current-amount"></strong></div> <div>Amount: <strong id="current-amount"></strong></div>
<div id="transactions"> <div id="transactions">
<form role="form"> <div class="form-group">
<div class="form-group"> <input id="addr" class="form-control" type="text" placeholder="Receiver address"></input><br>
<input id="addr" class="form-control" type="text" placeholder="Receiver address"></input><br> <input id="amount" class="form-control" type="text" placeholder="Amount"></input><br>
<input id="amount" class="form-control" type="text" placeholder="Amount"></input><br> </div>
</div>
<button class="btn btn-default" onclick="createTransaction();">Send Tx</button> <button class="btn btn-default" onclick="createTransaction();">Send Tx</button>
</div> </div>
</div> </div>
<div id="debug" style="border: 1px solid block"></div>
</div> </div>
<div id="debug" style="border: 1px solid black; min-height: 30px;"></div>
</body> </body>
</html> </html>

@ -1,6 +1,7 @@
package utils package utils
import ( import (
"fmt"
"github.com/ethereum/eth-go" "github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil" "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())} return &PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())}
} }
func (lib *PEthereum) GetKey() string { func (lib *PEthereum) GetKey() *PKey {
return ethutil.Hex(ethutil.Config.Db.GetKeys()[0].Address()) 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 { 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) hash = ethutil.FromHex(recipient)
} }
keyPair, err := ethchain.NewKeyPairFromSec([]byte(key)) keyPair, err := ethchain.NewKeyPairFromSec([]byte(ethutil.FromHex(key)))
if err != nil { if err != nil {
return "", err return "", err
} }
@ -81,15 +87,12 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in
tx = ethchain.NewContractCreationTx(value, gas, gasPrice, mainScript, initScript) tx = ethchain.NewContractCreationTx(value, gas, gasPrice, mainScript, initScript)
} else { } else {
/* // Just in case it was submitted as a 0x prefixed string
lines := strings.Split(dataStr, "\n") if initStr[0:2] == "0x" {
var data []byte initStr = initStr[2:len(initStr)]
for _, line := range lines { }
data = append(data, ethutil.BigToBytes(ethutil.Big(line), 256)...) fmt.Println("DATA:", initStr)
} tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, ethutil.FromHex(initStr))
*/
tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, []byte(initStr))
} }
acc := lib.stateManager.GetAddrState(keyPair.Address()) acc := lib.stateManager.GetAddrState(keyPair.Address())

@ -34,9 +34,16 @@ func NewPTx(tx *ethchain.Transaction) *PTx {
} }
type PKey struct { 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 { type PKeyRing struct {
Keys []interface{} Keys []interface{}
} }
@ -44,6 +51,7 @@ type PKeyRing struct {
func NewPKeyRing(keys []interface{}) *PKeyRing { func NewPKeyRing(keys []interface{}) *PKeyRing {
return &PKeyRing{Keys: keys} return &PKeyRing{Keys: keys}
} }
*/
type PStateObject struct { type PStateObject struct {
object *ethchain.StateObject object *ethchain.StateObject

Loading…
Cancel
Save