forked from cerc-io/plugeth
Fixed samplecoin
This commit is contained in:
parent
ee04c6ff67
commit
f1da6f0564
@ -19,8 +19,7 @@ window.eth = {
|
||||
|
||||
// Create transaction
|
||||
//
|
||||
// Creates a transaction with the current account
|
||||
// If no recipient is set, the Ethereum API will see it as a contract creation
|
||||
// Transact between two state objects
|
||||
transact: function(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() {
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -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])
|
||||
postData(data._seed, tx)
|
||||
|
||||
break
|
||||
case "create":
|
||||
postData(data._seed, null)
|
||||
|
@ -9,13 +9,14 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
var jefcoinAddr = "3dff537f51350239abc95c76a5864aa605259e7d"
|
||||
var mAddr = ""
|
||||
|
||||
function createTransaction() {
|
||||
var addr = document.querySelector("#addr").value;
|
||||
var amount = document.querySelector("#amount").value;
|
||||
|
||||
var data = "0x" + addr + "\n" + amount
|
||||
eth.transact("", jefcoinAddr, 0, "10000000", "250", data, function(tx) {
|
||||
var data = (("0x"+addr).pad(32) + amount.pad(32)).unbin()
|
||||
eth.transact(mAddr, jefcoinAddr, 0, "10000000", "250", data, function(tx) {
|
||||
debug("received tx hash:", tx)
|
||||
})
|
||||
}
|
||||
@ -23,13 +24,15 @@ function createTransaction() {
|
||||
function init() {
|
||||
eth.set({width: 500})
|
||||
|
||||
eth.getKey(function(key) {
|
||||
eth.getStorageAt(jefcoinAddr, key, function(storage) {
|
||||
eth.getKey(function(keyPair) {
|
||||
mAddr = keyPair.privateKey;
|
||||
|
||||
eth.getStorageAt(jefcoinAddr, keyPair.address, function(storage) {
|
||||
document.querySelector("#current-amount").innerHTML = storage;
|
||||
});
|
||||
|
||||
eth.watch(jefcoinAddr, function(stateObject) {
|
||||
eth.getStorageAt(jefcoinAddr, key, function(storage) {
|
||||
eth.getStorageAt(jefcoinAddr, keyPair.address, function(storage) {
|
||||
document.querySelector("#current-amount").innerHTML = storage;
|
||||
});
|
||||
});
|
||||
@ -50,19 +53,18 @@ function init() {
|
||||
<div>Amount: <strong id="current-amount"></strong></div>
|
||||
|
||||
<div id="transactions">
|
||||
<form role="form">
|
||||
<div class="form-group">
|
||||
<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>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-default" onclick="createTransaction();">Send Tx</button>
|
||||
<button class="btn btn-default" onclick="createTransaction();">Send Tx</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="debug" style="border: 1px solid block"></div>
|
||||
</div>
|
||||
|
||||
<div id="debug" style="border: 1px solid black; min-height: 30px;"></div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
@ -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())
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user