mirror of https://github.com/ethereum/go-ethereum
commit
60f9966cd8
@ -1,69 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
<title>jeffcoin</title> |
||||
<script type="text/javascript"> |
||||
var jefcoinAddr = "3dff537f51350239abc95c76a5864aa605259e7d" |
||||
|
||||
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) { |
||||
debug("received tx hash:", tx) |
||||
}) |
||||
} |
||||
|
||||
// Any test related actions here please |
||||
function tests() { |
||||
eth.getKey(function(keys) { |
||||
debug(keys) |
||||
}) |
||||
} |
||||
|
||||
function init() { |
||||
eth.getKey(function(key) { |
||||
eth.getStorageAt(jefcoinAddr, key, function(storage) { |
||||
document.querySelector("#currentAmount").innerHTML = "Amount: " + storage; |
||||
}); |
||||
|
||||
eth.watch(jefcoinAddr, function(stateObject) { |
||||
eth.getStorageAt(jefcoinAddr, key, function(storage) { |
||||
document.querySelector("#currentAmount").innerHTML = "Amount: " + storage; |
||||
}); |
||||
}); |
||||
|
||||
eth.getBalanceAt(key, function(balance) { |
||||
debug("balance", balance); |
||||
}) |
||||
}); |
||||
} |
||||
|
||||
</script> |
||||
<style type="text/css"> |
||||
input[type="text"] { |
||||
width: 300px; |
||||
} |
||||
</style> |
||||
</head> |
||||
|
||||
<body onload="init();"> |
||||
<h1>Jeff Coin</h1> |
||||
|
||||
<img src="icon.png"> |
||||
<div id="currentAmount"></div> |
||||
|
||||
<div id="transactions"> |
||||
<input id="addr" type="text" placeholder="Receiver address"></input><br> |
||||
<input id="amount" type="text" placeholder="Amount"></input><br> |
||||
<button onclick="createTransaction();">Send Tx</button> |
||||
</div> |
||||
|
||||
<div><button onclick="tests();">Tests</button></div> |
||||
|
||||
|
||||
<div id="debug" style="border: 1px solid block"></div> |
||||
|
||||
</body> |
||||
</html> |
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 85 KiB |
@ -0,0 +1,34 @@ |
||||
/* Space out content a bit */ |
||||
body { |
||||
padding-top: 20px; |
||||
padding-bottom: 20px; |
||||
} |
||||
|
||||
/* Everything but the jumbotron gets side spacing for mobile first |
||||
* views */ |
||||
.header, |
||||
.marketing, |
||||
.footer { |
||||
padding-right: 15px; |
||||
padding-left: 15px; |
||||
} |
||||
|
||||
/* Custom page header */ |
||||
.header { |
||||
border-bottom: 1px solid #e5e5e5; |
||||
} |
||||
/* Make the masthead heading the same height as the navigation */ |
||||
.header h3 { |
||||
padding-bottom: 19px; |
||||
margin-top: 0; |
||||
margin-bottom: 0; |
||||
line-height: 40px; |
||||
} |
||||
|
||||
.jumbotron { |
||||
text-align: center; |
||||
border-bottom: 1px solid #e5e5e5; |
||||
|
||||
margin: 0 auto; |
||||
width: 300px; |
||||
} |
@ -0,0 +1,70 @@ |
||||
<html> |
||||
<head> |
||||
<title>jeffcoin</title> |
||||
|
||||
<link rel="stylesheet" href="bootstrap.min.css"> |
||||
<link rel="stylesheet" href="bootstrap-theme.min.css"> |
||||
<link rel="stylesheet" href="samplecoin.css"> |
||||
<meta name="viewport" content="minimum-scale=1; maximum-scale=1; initial-scale=1;"> |
||||
|
||||
<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).pad(32) + amount.pad(32)).unbin() |
||||
eth.transact(mAddr, jefcoinAddr, 0, "10000000", "250", data, function(tx) { |
||||
debug("received tx hash:", tx) |
||||
}) |
||||
} |
||||
|
||||
function init() { |
||||
eth.set({width: 500}) |
||||
|
||||
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, keyPair.address, function(storage) { |
||||
document.querySelector("#current-amount").innerHTML = storage; |
||||
}); |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
</script> |
||||
</head> |
||||
|
||||
<body onload="init();"> |
||||
<div class="container"> |
||||
<div class="header"> |
||||
<h3 class="text-muted">JeffCoin</h3> |
||||
</div> |
||||
|
||||
<div class="jumbotron "> |
||||
<img src="icon.png"> |
||||
<div>Amount: <strong id="current-amount"></strong></div> |
||||
|
||||
<div id="transactions"> |
||||
<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> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<div id="debug" style="border: 1px solid black; min-height: 30px;"></div> |
||||
|
||||
</body> |
||||
</html> |
||||
|
@ -1,55 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
<title>jeffcoin</title> |
||||
<script type="text/javascript"> |
||||
var jefcoinAddr = "3dff537f51350239abc95c76a5864aa605259e7d" |
||||
|
||||
function createTransaction() { |
||||
var addr = document.querySelector("#addr").value; |
||||
var amount = document.querySelector("#amount").value; |
||||
|
||||
var data = "0x" + addr + "\n" + amount |
||||
eth.createTx(jefcoinAddr, 0, "10000000", "250", data, function(tx) { |
||||
debug("received tx hash:", tx) |
||||
}) |
||||
} |
||||
|
||||
function init() { |
||||
eth.getKey(function(key) { |
||||
eth.getStorage(jefcoinAddr, key, function(storage) { |
||||
document.querySelector("#currentAmount").innerHTML = "Amount: " + storage; |
||||
}); |
||||
|
||||
eth.on("block:new", function() { |
||||
eth.getStorage(jefcoinAddr, key, function(storage) { |
||||
document.querySelector("#currentAmount").innerHTML = "Amount: " + storage; |
||||
}); |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
</script> |
||||
<style type="text/css"> |
||||
input[type="text"] { |
||||
width: 300px; |
||||
} |
||||
</style> |
||||
</head> |
||||
|
||||
<body onload="init();"> |
||||
<h1>Jeff Coin</h1> |
||||
|
||||
<img src="icon.png"> |
||||
<div id="currentAmount"></div> |
||||
|
||||
<div id="transactions"> |
||||
<input id="addr" type="text" placeholder="Receiver address"></input><br> |
||||
<input id="amount" type="text" placeholder="Amount"></input><br> |
||||
<button onclick="createTransaction();">Send Tx</button> |
||||
</div> |
||||
|
||||
<div id="debug" style="border: 1px solid block"></div> |
||||
|
||||
</body> |
||||
</html> |
||||
|
@ -0,0 +1,110 @@ |
||||
package utils |
||||
|
||||
import ( |
||||
"fmt" |
||||
"github.com/ethereum/eth-go" |
||||
"github.com/ethereum/eth-go/ethchain" |
||||
"github.com/ethereum/eth-go/ethutil" |
||||
) |
||||
|
||||
type PEthereum struct { |
||||
stateManager *ethchain.StateManager |
||||
blockChain *ethchain.BlockChain |
||||
txPool *ethchain.TxPool |
||||
} |
||||
|
||||
func NewPEthereum(eth *eth.Ethereum) *PEthereum { |
||||
return &PEthereum{ |
||||
eth.StateManager(), |
||||
eth.BlockChain(), |
||||
eth.TxPool(), |
||||
} |
||||
} |
||||
|
||||
func (lib *PEthereum) GetBlock(hexHash string) *PBlock { |
||||
hash := ethutil.FromHex(hexHash) |
||||
|
||||
block := lib.blockChain.GetBlock(hash) |
||||
|
||||
return &PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} |
||||
} |
||||
|
||||
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 { |
||||
stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address)) |
||||
if stateObject != nil { |
||||
return NewPStateObject(stateObject) |
||||
} |
||||
|
||||
// See GetStorage for explanation on "nil"
|
||||
return NewPStateObject(nil) |
||||
} |
||||
|
||||
func (lib *PEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { |
||||
return lib.createTx(key, recipient, valueStr, gasStr, gasPriceStr, dataStr, "") |
||||
} |
||||
|
||||
func (lib *PEthereum) Create(key, valueStr, gasStr, gasPriceStr, initStr, bodyStr string) (string, error) { |
||||
return lib.createTx(key, "", valueStr, gasStr, gasPriceStr, initStr, bodyStr) |
||||
} |
||||
|
||||
func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, initStr, scriptStr string) (string, error) { |
||||
var hash []byte |
||||
var contractCreation bool |
||||
if len(recipient) == 0 { |
||||
contractCreation = true |
||||
} else { |
||||
hash = ethutil.FromHex(recipient) |
||||
} |
||||
|
||||
keyPair, err := ethchain.NewKeyPairFromSec([]byte(ethutil.FromHex(key))) |
||||
if err != nil { |
||||
return "", err |
||||
} |
||||
|
||||
value := ethutil.Big(valueStr) |
||||
gas := ethutil.Big(gasStr) |
||||
gasPrice := ethutil.Big(gasPriceStr) |
||||
var tx *ethchain.Transaction |
||||
// Compile and assemble the given data
|
||||
if contractCreation { |
||||
initScript, err := Compile(initStr) |
||||
if err != nil { |
||||
return "", err |
||||
} |
||||
mainScript, err := Compile(scriptStr) |
||||
if err != nil { |
||||
return "", err |
||||
} |
||||
|
||||
tx = ethchain.NewContractCreationTx(value, gas, gasPrice, mainScript, initScript) |
||||
} else { |
||||
// 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()) |
||||
tx.Nonce = acc.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()), nil |
||||
} |
Loading…
Reference in new issue