| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 	"encoding/json" | 
					
						
							| 
									
										
										
										
											2015-04-20 12:29:02 +02:00
										 |  |  | 	"errors" | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 	"math/big" | 
					
						
							| 
									
										
										
										
											2015-05-05 23:09:46 +02:00
										 |  |  | 	"strconv" | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	"time" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-20 16:56:17 +01:00
										 |  |  | 	"github.com/ethereum/ethash" | 
					
						
							| 
									
										
										
										
											2015-05-14 14:25:48 +02:00
										 |  |  | 	"github.com/ethereum/go-ethereum/accounts" | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	"github.com/ethereum/go-ethereum/cmd/utils" | 
					
						
							| 
									
										
										
										
											2015-03-16 22:56:05 +07:00
										 |  |  | 	"github.com/ethereum/go-ethereum/common" | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 	"github.com/ethereum/go-ethereum/common/compiler" | 
					
						
							|  |  |  | 	"github.com/ethereum/go-ethereum/common/natspec" | 
					
						
							|  |  |  | 	"github.com/ethereum/go-ethereum/common/resolver" | 
					
						
							| 
									
										
										
										
											2015-03-27 09:36:18 +01:00
										 |  |  | 	"github.com/ethereum/go-ethereum/core/state" | 
					
						
							| 
									
										
										
										
											2015-03-18 13:00:01 +01:00
										 |  |  | 	"github.com/ethereum/go-ethereum/core/types" | 
					
						
							| 
									
										
										
										
											2015-04-20 16:03:19 +02:00
										 |  |  | 	"github.com/ethereum/go-ethereum/core/vm" | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 	"github.com/ethereum/go-ethereum/crypto" | 
					
						
							| 
									
										
										
										
											2015-04-04 13:24:19 +02:00
										 |  |  | 	"github.com/ethereum/go-ethereum/logger/glog" | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	"github.com/ethereum/go-ethereum/rlp" | 
					
						
							|  |  |  | 	"github.com/ethereum/go-ethereum/rpc" | 
					
						
							|  |  |  | 	"github.com/ethereum/go-ethereum/xeth" | 
					
						
							| 
									
										
										
										
											2015-03-20 13:22:01 +01:00
										 |  |  | 	"github.com/robertkrimen/otto" | 
					
						
							| 
									
										
										
										
											2015-05-06 14:53:20 +02:00
										 |  |  | 	"gopkg.in/fatih/set.v0" | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  | node admin bindings | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) adminBindings() { | 
					
						
							| 
									
										
										
										
											2015-05-05 23:09:46 +02:00
										 |  |  | 	ethO, _ := js.re.Get("eth") | 
					
						
							|  |  |  | 	eth := ethO.Object() | 
					
						
							| 
									
										
										
										
											2015-05-06 14:53:20 +02:00
										 |  |  | 	eth.Set("pendingTransactions", js.pendingTransactions) | 
					
						
							| 
									
										
										
										
											2015-05-05 23:09:46 +02:00
										 |  |  | 	eth.Set("resend", js.resend) | 
					
						
							| 
									
										
										
										
											2015-05-20 04:38:20 +01:00
										 |  |  | 	eth.Set("sign", js.sign) | 
					
						
							| 
									
										
										
										
											2015-05-05 23:09:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	js.re.Set("admin", struct{}{}) | 
					
						
							|  |  |  | 	t, _ := js.re.Get("admin") | 
					
						
							|  |  |  | 	admin := t.Object() | 
					
						
							| 
									
										
										
										
											2015-04-30 16:15:29 +03:00
										 |  |  | 	admin.Set("addPeer", js.addPeer) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	admin.Set("startRPC", js.startRPC) | 
					
						
							| 
									
										
										
										
											2015-04-16 12:56:51 +02:00
										 |  |  | 	admin.Set("stopRPC", js.stopRPC) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	admin.Set("nodeInfo", js.nodeInfo) | 
					
						
							|  |  |  | 	admin.Set("peers", js.peers) | 
					
						
							|  |  |  | 	admin.Set("newAccount", js.newAccount) | 
					
						
							|  |  |  | 	admin.Set("unlock", js.unlock) | 
					
						
							|  |  |  | 	admin.Set("import", js.importChain) | 
					
						
							|  |  |  | 	admin.Set("export", js.exportChain) | 
					
						
							| 
									
										
										
										
											2015-04-04 13:24:19 +02:00
										 |  |  | 	admin.Set("verbosity", js.verbosity) | 
					
						
							| 
									
										
										
										
											2015-04-19 21:45:58 +02:00
										 |  |  | 	admin.Set("progress", js.downloadProgress) | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 	admin.Set("setSolc", js.setSolc) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	admin.Set("contractInfo", struct{}{}) | 
					
						
							|  |  |  | 	t, _ = admin.Get("contractInfo") | 
					
						
							|  |  |  | 	cinfo := t.Object() | 
					
						
							|  |  |  | 	// newRegistry officially not documented temporary option | 
					
						
							|  |  |  | 	cinfo.Set("start", js.startNatSpec) | 
					
						
							|  |  |  | 	cinfo.Set("stop", js.stopNatSpec) | 
					
						
							|  |  |  | 	cinfo.Set("newRegistry", js.newRegistry) | 
					
						
							|  |  |  | 	cinfo.Set("get", js.getContractInfo) | 
					
						
							|  |  |  | 	cinfo.Set("register", js.register) | 
					
						
							|  |  |  | 	cinfo.Set("registerUrl", js.registerUrl) | 
					
						
							|  |  |  | 	// cinfo.Set("verify", js.verify) | 
					
						
							| 
									
										
										
										
											2015-04-05 18:57:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	admin.Set("miner", struct{}{}) | 
					
						
							|  |  |  | 	t, _ = admin.Get("miner") | 
					
						
							|  |  |  | 	miner := t.Object() | 
					
						
							|  |  |  | 	miner.Set("start", js.startMining) | 
					
						
							|  |  |  | 	miner.Set("stop", js.stopMining) | 
					
						
							|  |  |  | 	miner.Set("hashrate", js.hashrate) | 
					
						
							|  |  |  | 	miner.Set("setExtra", js.setExtra) | 
					
						
							| 
									
										
										
										
											2015-05-09 12:04:00 +02:00
										 |  |  | 	miner.Set("setGasPrice", js.setGasPrice) | 
					
						
							| 
									
										
										
										
											2015-05-20 16:56:17 +01:00
										 |  |  | 	miner.Set("startAutoDAG", js.startAutoDAG) | 
					
						
							|  |  |  | 	miner.Set("stopAutoDAG", js.stopAutoDAG) | 
					
						
							|  |  |  | 	miner.Set("makeDAG", js.makeDAG) | 
					
						
							| 
									
										
										
										
											2015-04-14 12:49:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 13:14:06 +02:00
										 |  |  | 	admin.Set("txPool", struct{}{}) | 
					
						
							|  |  |  | 	t, _ = admin.Get("txPool") | 
					
						
							|  |  |  | 	txPool := t.Object() | 
					
						
							|  |  |  | 	txPool.Set("pending", js.allPendingTransactions) | 
					
						
							|  |  |  | 	txPool.Set("queued", js.allQueuedTransactions) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 12:49:30 +02:00
										 |  |  | 	admin.Set("debug", struct{}{}) | 
					
						
							|  |  |  | 	t, _ = admin.Get("debug") | 
					
						
							|  |  |  | 	debug := t.Object() | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 	js.re.Set("sleep", js.sleep) | 
					
						
							| 
									
										
										
										
											2015-04-21 10:47:40 +01:00
										 |  |  | 	debug.Set("backtrace", js.backtrace) | 
					
						
							| 
									
										
										
										
											2015-04-14 12:49:30 +02:00
										 |  |  | 	debug.Set("printBlock", js.printBlock) | 
					
						
							|  |  |  | 	debug.Set("dumpBlock", js.dumpBlock) | 
					
						
							| 
									
										
										
										
											2015-04-19 13:30:55 +02:00
										 |  |  | 	debug.Set("getBlockRlp", js.getBlockRlp) | 
					
						
							| 
									
										
										
										
											2015-04-20 12:29:02 +02:00
										 |  |  | 	debug.Set("setHead", js.setHead) | 
					
						
							| 
									
										
										
										
											2015-04-21 10:47:40 +01:00
										 |  |  | 	debug.Set("processBlock", js.debugBlock) | 
					
						
							| 
									
										
										
										
											2015-05-27 00:11:54 +02:00
										 |  |  | 	debug.Set("seedhash", js.seedHash) | 
					
						
							| 
									
										
										
										
											2015-06-03 13:14:06 +02:00
										 |  |  | 	debug.Set("insertBlock", js.insertBlockRlp) | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 	// undocumented temporary | 
					
						
							|  |  |  | 	debug.Set("waitForBlocks", js.waitForBlocks) | 
					
						
							| 
									
										
										
										
											2015-04-19 13:30:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | // generic helper to getBlock by Number/Height or Hex depending on autodetected input | 
					
						
							|  |  |  | // if argument is missing the current block is returned | 
					
						
							|  |  |  | // if block is not found or there is problem with decoding | 
					
						
							|  |  |  | // the appropriate value is returned and block is guaranteed to be nil | 
					
						
							| 
									
										
										
										
											2015-04-20 12:29:02 +02:00
										 |  |  | func (js *jsre) getBlock(call otto.FunctionCall) (*types.Block, error) { | 
					
						
							| 
									
										
										
										
											2015-04-19 13:30:55 +02:00
										 |  |  | 	var block *types.Block | 
					
						
							|  |  |  | 	if len(call.ArgumentList) > 0 { | 
					
						
							|  |  |  | 		if call.Argument(0).IsNumber() { | 
					
						
							|  |  |  | 			num, _ := call.Argument(0).ToInteger() | 
					
						
							|  |  |  | 			block = js.ethereum.ChainManager().GetBlockByNumber(uint64(num)) | 
					
						
							|  |  |  | 		} else if call.Argument(0).IsString() { | 
					
						
							|  |  |  | 			hash, _ := call.Argument(0).ToString() | 
					
						
							|  |  |  | 			block = js.ethereum.ChainManager().GetBlock(common.HexToHash(hash)) | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2015-04-20 12:29:02 +02:00
										 |  |  | 			return nil, errors.New("invalid argument for dump. Either hex string or number") | 
					
						
							| 
									
										
										
										
											2015-04-19 13:30:55 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		block = js.ethereum.ChainManager().CurrentBlock() | 
					
						
							| 
									
										
										
										
											2015-04-20 12:29:02 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-04-19 13:30:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 	if block == nil { | 
					
						
							|  |  |  | 		return nil, errors.New("block not found") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return block, nil | 
					
						
							| 
									
										
										
										
											2015-04-20 12:29:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-27 00:11:54 +02:00
										 |  |  | func (js *jsre) seedHash(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	if len(call.ArgumentList) > 0 { | 
					
						
							|  |  |  | 		if call.Argument(0).IsNumber() { | 
					
						
							|  |  |  | 			num, _ := call.Argument(0).ToInteger() | 
					
						
							|  |  |  | 			hash, err := ethash.GetSeedHash(uint64(num)) | 
					
						
							|  |  |  | 			if err != nil { | 
					
						
							|  |  |  | 				fmt.Println(err) | 
					
						
							|  |  |  | 				return otto.UndefinedValue() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			v, _ := call.Otto.ToValue(fmt.Sprintf("0x%x", hash)) | 
					
						
							|  |  |  | 			return v | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			fmt.Println("arg not a number") | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		fmt.Println("requires number argument") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return otto.UndefinedValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 13:14:06 +02:00
										 |  |  | func (js *jsre) allPendingTransactions(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	txs := js.ethereum.TxPool().GetTransactions() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ltxs := make([]*tx, len(txs)) | 
					
						
							|  |  |  | 	for i, tx := range txs { | 
					
						
							|  |  |  | 		// no need to check err | 
					
						
							|  |  |  | 		ltxs[i] = newTx(tx) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	v, _ := call.Otto.ToValue(ltxs) | 
					
						
							|  |  |  | 	return v | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) allQueuedTransactions(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	txs := js.ethereum.TxPool().GetQueuedTransactions() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ltxs := make([]*tx, len(txs)) | 
					
						
							|  |  |  | 	for i, tx := range txs { | 
					
						
							|  |  |  | 		// no need to check err | 
					
						
							|  |  |  | 		ltxs[i] = newTx(tx) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	v, _ := call.Otto.ToValue(ltxs) | 
					
						
							|  |  |  | 	return v | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-06 14:53:20 +02:00
										 |  |  | func (js *jsre) pendingTransactions(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	txs := js.ethereum.TxPool().GetTransactions() | 
					
						
							| 
									
										
										
										
											2015-05-05 23:09:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-06 14:53:20 +02:00
										 |  |  | 	// grab the accounts from the account manager. This will help with determening which | 
					
						
							|  |  |  | 	// transactions should be returned. | 
					
						
							|  |  |  | 	accounts, err := js.ethereum.AccountManager().Accounts() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							| 
									
										
										
										
											2015-05-05 23:09:46 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-06 14:53:20 +02:00
										 |  |  | 	// Add the accouns to a new set | 
					
						
							|  |  |  | 	accountSet := set.New() | 
					
						
							|  |  |  | 	for _, account := range accounts { | 
					
						
							| 
									
										
										
										
											2015-05-10 20:30:02 +02:00
										 |  |  | 		accountSet.Add(account.Address) | 
					
						
							| 
									
										
										
										
											2015-05-05 23:09:46 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-06 14:53:20 +02:00
										 |  |  | 	//ltxs := make([]*tx, len(txs)) | 
					
						
							|  |  |  | 	var ltxs []*tx | 
					
						
							|  |  |  | 	for _, tx := range txs { | 
					
						
							|  |  |  | 		if from, _ := tx.From(); accountSet.Has(from) { | 
					
						
							|  |  |  | 			ltxs = append(ltxs, newTx(tx)) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-05-05 23:09:46 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 	v, _ := call.Otto.ToValue(ltxs) | 
					
						
							|  |  |  | 	return v | 
					
						
							| 
									
										
										
										
											2015-05-05 23:09:46 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) resend(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	if len(call.ArgumentList) == 0 { | 
					
						
							|  |  |  | 		fmt.Println("first argument must be a transaction") | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	v, err := call.Argument(0).Export() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if tx, ok := v.(*tx); ok { | 
					
						
							|  |  |  | 		gl, gp := tx.GasLimit, tx.GasPrice | 
					
						
							|  |  |  | 		if len(call.ArgumentList) > 1 { | 
					
						
							| 
									
										
										
										
											2015-05-05 23:19:59 +02:00
										 |  |  | 			gp = call.Argument(1).String() | 
					
						
							| 
									
										
										
										
											2015-05-05 23:09:46 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if len(call.ArgumentList) > 2 { | 
					
						
							| 
									
										
										
										
											2015-05-05 23:19:59 +02:00
										 |  |  | 			gl = call.Argument(2).String() | 
					
						
							| 
									
										
										
										
											2015-05-05 23:09:46 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ret, err := js.xeth.Transact(tx.From, tx.To, tx.Nonce, tx.Value, gl, gp, tx.Data) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			fmt.Println(err) | 
					
						
							|  |  |  | 			return otto.FalseValue() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		js.ethereum.TxPool().RemoveTransactions(types.Transactions{tx.tx}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 		v, _ := call.Otto.ToValue(ret) | 
					
						
							|  |  |  | 		return v | 
					
						
							| 
									
										
										
										
											2015-05-05 23:09:46 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fmt.Println("first argument must be a transaction") | 
					
						
							|  |  |  | 	return otto.FalseValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-20 04:38:20 +01:00
										 |  |  | func (js *jsre) sign(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	if len(call.ArgumentList) != 2 { | 
					
						
							|  |  |  | 		fmt.Println("requires 2 arguments: eth.sign(signer, data)") | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	signer, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	data, err := call.Argument(1).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 	signed, err := js.xeth.Sign(signer, data, false) | 
					
						
							| 
									
										
										
										
											2015-05-20 04:38:20 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 	v, _ := call.Otto.ToValue(signed) | 
					
						
							|  |  |  | 	return v | 
					
						
							| 
									
										
										
										
											2015-05-20 04:38:20 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-20 16:03:19 +02:00
										 |  |  | func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	block, err := js.getBlock(call) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 13:14:06 +02:00
										 |  |  | 	tstart := time.Now() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-20 16:03:19 +02:00
										 |  |  | 	old := vm.Debug | 
					
						
							|  |  |  | 	vm.Debug = true | 
					
						
							|  |  |  | 	_, err = js.ethereum.BlockProcessor().RetryProcess(block) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2015-05-27 00:11:54 +02:00
										 |  |  | 		fmt.Println(err) | 
					
						
							| 
									
										
										
										
											2015-06-03 13:14:06 +02:00
										 |  |  | 		r, _ := call.Otto.ToValue(map[string]interface{}{"success": false, "time": time.Since(tstart).Seconds()}) | 
					
						
							|  |  |  | 		return r | 
					
						
							| 
									
										
										
										
											2015-04-20 16:03:19 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	vm.Debug = old | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 13:14:06 +02:00
										 |  |  | 	r, _ := call.Otto.ToValue(map[string]interface{}{"success": true, "time": time.Since(tstart).Seconds()}) | 
					
						
							|  |  |  | 	return r | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) insertBlockRlp(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	tstart := time.Now() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var block types.Block | 
					
						
							|  |  |  | 	if call.Argument(0).IsString() { | 
					
						
							|  |  |  | 		blockRlp, _ := call.Argument(0).ToString() | 
					
						
							|  |  |  | 		err := rlp.DecodeBytes(common.Hex2Bytes(blockRlp), &block) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			fmt.Println(err) | 
					
						
							|  |  |  | 			return otto.UndefinedValue() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	old := vm.Debug | 
					
						
							|  |  |  | 	vm.Debug = true | 
					
						
							|  |  |  | 	_, err := js.ethereum.BlockProcessor().RetryProcess(&block) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		r, _ := call.Otto.ToValue(map[string]interface{}{"success": false, "time": time.Since(tstart).Seconds()}) | 
					
						
							|  |  |  | 		return r | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	vm.Debug = old | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	r, _ := call.Otto.ToValue(map[string]interface{}{"success": true, "time": time.Since(tstart).Seconds()}) | 
					
						
							|  |  |  | 	return r | 
					
						
							| 
									
										
										
										
											2015-04-20 16:03:19 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-20 12:29:02 +02:00
										 |  |  | func (js *jsre) setHead(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	block, err := js.getBlock(call) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							| 
									
										
										
										
											2015-04-19 13:30:55 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-04-20 12:29:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	js.ethereum.ChainManager().SetHead(block) | 
					
						
							|  |  |  | 	return otto.UndefinedValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) downloadProgress(call otto.FunctionCall) otto.Value { | 
					
						
							| 
									
										
										
										
											2015-05-27 16:46:46 +03:00
										 |  |  | 	pending, cached := js.ethereum.Downloader().Stats() | 
					
						
							|  |  |  | 	v, _ := call.Otto.ToValue(map[string]interface{}{"pending": pending, "cached": cached}) | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 	return v | 
					
						
							| 
									
										
										
										
											2015-04-20 12:29:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	block, err := js.getBlock(call) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-04-19 13:30:55 +02:00
										 |  |  | 	encoded, _ := rlp.EncodeToBytes(block) | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 	v, _ := call.Otto.ToValue(fmt.Sprintf("%x", encoded)) | 
					
						
							|  |  |  | 	return v | 
					
						
							| 
									
										
										
										
											2015-04-05 18:57:03 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) setExtra(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	extra, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if len(extra) > 1024 { | 
					
						
							|  |  |  | 		fmt.Println("error: cannot exceed 1024 bytes") | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	js.ethereum.Miner().SetExtra([]byte(extra)) | 
					
						
							|  |  |  | 	return otto.UndefinedValue() | 
					
						
							| 
									
										
										
										
											2015-04-05 13:05:10 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 12:04:00 +02:00
										 |  |  | func (js *jsre) setGasPrice(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	gasPrice, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	js.ethereum.Miner().SetGasPrice(common.String2Big(gasPrice)) | 
					
						
							|  |  |  | 	return otto.UndefinedValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | func (js *jsre) hashrate(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	v, _ := call.Otto.ToValue(js.ethereum.Miner().HashRate()) | 
					
						
							|  |  |  | 	return v | 
					
						
							| 
									
										
										
										
											2015-04-04 22:16:29 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-20 16:56:17 +01:00
										 |  |  | func (js *jsre) makeDAG(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	blockNumber, err := call.Argument(1).ToInteger() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ethash.MakeDAG(uint64(blockNumber), "") | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) startAutoDAG(otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	js.ethereum.StartAutoDAG() | 
					
						
							|  |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) stopAutoDAG(otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	js.ethereum.StopAutoDAG() | 
					
						
							|  |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-04 22:16:29 +02:00
										 |  |  | func (js *jsre) backtrace(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	tracestr, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	glog.GetTraceLocation().Set(tracestr) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return otto.UndefinedValue() | 
					
						
							| 
									
										
										
										
											2015-04-04 13:24:19 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) verbosity(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	v, err := call.Argument(0).ToInteger() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	glog.SetV(int(v)) | 
					
						
							|  |  |  | 	return otto.UndefinedValue() | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) startMining(call otto.FunctionCall) otto.Value { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:47:34 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		threads int64 | 
					
						
							|  |  |  | 		err     error | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if len(call.ArgumentList) > 0 { | 
					
						
							|  |  |  | 		threads, err = call.Argument(0).ToInteger() | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			fmt.Println(err) | 
					
						
							|  |  |  | 			return otto.FalseValue() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2015-05-15 16:47:44 +02:00
										 |  |  | 		threads = int64(js.ethereum.MinerThreads) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-20 16:56:17 +01:00
										 |  |  | 	// switch on DAG autogeneration when miner starts | 
					
						
							|  |  |  | 	js.ethereum.StartAutoDAG() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 15:43:14 +02:00
										 |  |  | 	err = js.ethereum.StartMining(int(threads)) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) stopMining(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	js.ethereum.StopMining() | 
					
						
							| 
									
										
										
										
											2015-05-20 16:56:17 +01:00
										 |  |  | 	js.ethereum.StopAutoDAG() | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) startRPC(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	addr, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-04-22 14:55:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	port, err := call.Argument(1).ToInteger() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-22 14:55:01 +01:00
										 |  |  | 	corsDomain := js.corsDomain | 
					
						
							| 
									
										
										
										
											2015-04-21 18:08:47 +01:00
										 |  |  | 	if len(call.ArgumentList) > 2 { | 
					
						
							|  |  |  | 		corsDomain, err = call.Argument(2).ToString() | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			fmt.Println(err) | 
					
						
							|  |  |  | 			return otto.FalseValue() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-29 21:26:47 +02:00
										 |  |  | 	config := rpc.RpcConfig{ | 
					
						
							|  |  |  | 		ListenAddress: addr, | 
					
						
							|  |  |  | 		ListenPort:    uint(port), | 
					
						
							| 
									
										
										
										
											2015-04-21 18:08:47 +01:00
										 |  |  | 		CorsDomain:    corsDomain, | 
					
						
							| 
									
										
										
										
											2015-03-29 21:26:47 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	xeth := xeth.New(js.ethereum, nil) | 
					
						
							|  |  |  | 	err = rpc.Start(xeth, config) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 		fmt.Println(err) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-03-29 21:26:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	return otto.TrueValue() | 
					
						
							| 
									
										
										
										
											2015-04-16 12:56:51 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) stopRPC(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	if rpc.Stop() == nil { | 
					
						
							|  |  |  | 		return otto.TrueValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return otto.FalseValue() | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-30 16:15:29 +03:00
										 |  |  | func (js *jsre) addPeer(call otto.FunctionCall) otto.Value { | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	nodeURL, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-04-30 16:15:29 +03:00
										 |  |  | 	err = js.ethereum.AddPeer(nodeURL) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) unlock(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	addr, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	seconds, err := call.Argument(2).ToInteger() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-14 14:25:48 +02:00
										 |  |  | 	if seconds == 0 { | 
					
						
							|  |  |  | 		seconds = accounts.DefaultAccountUnlockDuration | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	arg := call.Argument(1) | 
					
						
							|  |  |  | 	var passphrase string | 
					
						
							|  |  |  | 	if arg.IsUndefined() { | 
					
						
							|  |  |  | 		fmt.Println("Please enter a passphrase now.") | 
					
						
							| 
									
										
										
										
											2015-05-18 12:24:30 -05:00
										 |  |  | 		passphrase, err = utils.PromptPassword("Passphrase: ", true) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 			fmt.Println(err) | 
					
						
							|  |  |  | 			return otto.FalseValue() | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		passphrase, err = arg.ToString() | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			fmt.Println(err) | 
					
						
							|  |  |  | 			return otto.FalseValue() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	am := js.ethereum.AccountManager() | 
					
						
							| 
									
										
										
										
											2015-04-02 21:14:25 +02:00
										 |  |  | 	err = am.TimedUnlock(common.HexToAddress(addr), passphrase, time.Duration(seconds)*time.Second) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Printf("Unlock account failed '%v'\n", err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) newAccount(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	arg := call.Argument(0) | 
					
						
							|  |  |  | 	var passphrase string | 
					
						
							|  |  |  | 	if arg.IsUndefined() { | 
					
						
							|  |  |  | 		fmt.Println("The new account will be encrypted with a passphrase.") | 
					
						
							|  |  |  | 		fmt.Println("Please enter a passphrase now.") | 
					
						
							| 
									
										
										
										
											2015-05-18 12:24:30 -05:00
										 |  |  | 		auth, err := utils.PromptPassword("Passphrase: ", true) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 			fmt.Println(err) | 
					
						
							|  |  |  | 			return otto.FalseValue() | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-05-18 12:24:30 -05:00
										 |  |  | 		confirm, err := utils.PromptPassword("Repeat Passphrase: ", false) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 			fmt.Println(err) | 
					
						
							|  |  |  | 			return otto.FalseValue() | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if auth != confirm { | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 			fmt.Println("Passphrases did not match.") | 
					
						
							|  |  |  | 			return otto.FalseValue() | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		passphrase = auth | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		var err error | 
					
						
							|  |  |  | 		passphrase, err = arg.ToString() | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			fmt.Println(err) | 
					
						
							|  |  |  | 			return otto.FalseValue() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	acct, err := js.ethereum.AccountManager().NewAccount(passphrase) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Printf("Could not create the account: %v", err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 	v, _ := call.Otto.ToValue(acct.Address.Hex()) | 
					
						
							|  |  |  | 	return v | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) nodeInfo(call otto.FunctionCall) otto.Value { | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 	v, _ := call.Otto.ToValue(js.ethereum.NodeInfo()) | 
					
						
							|  |  |  | 	return v | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) peers(call otto.FunctionCall) otto.Value { | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 	v, _ := call.Otto.ToValue(js.ethereum.PeersInfo()) | 
					
						
							|  |  |  | 	return v | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) importChain(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	if len(call.ArgumentList) == 0 { | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 		fmt.Println("require file name. admin.importChain(filename)") | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fn, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-04-22 10:59:27 +02:00
										 |  |  | 	if err := utils.ImportChain(js.ethereum.ChainManager(), fn); err != nil { | 
					
						
							|  |  |  | 		fmt.Println("Import error: ", err) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) exportChain(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	if len(call.ArgumentList) == 0 { | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 		fmt.Println("require file name: admin.exportChain(filename)") | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fn, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-03-18 14:04:19 +01:00
										 |  |  | 	if err := utils.ExportChain(js.ethereum.ChainManager(), fn); err != nil { | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 12:49:30 +02:00
										 |  |  | func (js *jsre) printBlock(call otto.FunctionCall) otto.Value { | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 	block, err := js.getBlock(call) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							| 
									
										
										
										
											2015-04-14 12:49:30 +02:00
										 |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fmt.Println(block) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return otto.UndefinedValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | func (js *jsre) dumpBlock(call otto.FunctionCall) otto.Value { | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | 	block, err := js.getBlock(call) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	statedb := state.New(block.Root(), js.ethereum.StateDb()) | 
					
						
							|  |  |  | 	dump := statedb.RawDump() | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 	v, _ := call.Otto.ToValue(dump) | 
					
						
							|  |  |  | 	return v | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) waitForBlocks(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	if len(call.ArgumentList) > 2 { | 
					
						
							|  |  |  | 		fmt.Println("requires 0, 1 or 2 arguments: admin.debug.waitForBlock(minHeight, timeout)") | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var n, timeout int64 | 
					
						
							|  |  |  | 	var timer <-chan time.Time | 
					
						
							|  |  |  | 	var height *big.Int | 
					
						
							|  |  |  | 	var err error | 
					
						
							|  |  |  | 	args := len(call.ArgumentList) | 
					
						
							|  |  |  | 	if args == 2 { | 
					
						
							|  |  |  | 		timeout, err = call.Argument(1).ToInteger() | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			fmt.Println(err) | 
					
						
							|  |  |  | 			return otto.UndefinedValue() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		timer = time.NewTimer(time.Duration(timeout) * time.Second).C | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if args >= 1 { | 
					
						
							|  |  |  | 		n, err = call.Argument(0).ToInteger() | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			fmt.Println(err) | 
					
						
							|  |  |  | 			return otto.UndefinedValue() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		height = big.NewInt(n) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if args == 0 { | 
					
						
							|  |  |  | 		height = js.xeth.CurrentBlock().Number() | 
					
						
							|  |  |  | 		height.Add(height, common.Big1) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wait := js.wait | 
					
						
							|  |  |  | 	js.wait <- height | 
					
						
							|  |  |  | 	select { | 
					
						
							|  |  |  | 	case <-timer: | 
					
						
							|  |  |  | 		// if times out make sure the xeth loop does not block | 
					
						
							|  |  |  | 		go func() { | 
					
						
							|  |  |  | 			select { | 
					
						
							|  |  |  | 			case wait <- nil: | 
					
						
							|  |  |  | 			case <-wait: | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}() | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	case height = <-wait: | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 	v, _ := call.Otto.ToValue(height.Uint64()) | 
					
						
							|  |  |  | 	return v | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) sleep(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	sec, err := call.Argument(0).ToInteger() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	time.Sleep(time.Duration(sec) * time.Second) | 
					
						
							|  |  |  | 	return otto.UndefinedValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) setSolc(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	if len(call.ArgumentList) != 1 { | 
					
						
							|  |  |  | 		fmt.Println("needs 1 argument: admin.contractInfo.setSolc(solcPath)") | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	solcPath, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	solc, err := js.xeth.SetSolc(solcPath) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fmt.Println(solc.Info()) | 
					
						
							|  |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) register(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	if len(call.ArgumentList) != 4 { | 
					
						
							|  |  |  | 		fmt.Println("requires 4 arguments: admin.contractInfo.register(fromaddress, contractaddress, contract, filename)") | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	sender, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	address, err := call.Argument(1).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	raw, err := call.Argument(2).Export() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	jsonraw, err := json.Marshal(raw) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var contract compiler.Contract | 
					
						
							|  |  |  | 	err = json.Unmarshal(jsonraw, &contract) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	filename, err := call.Argument(3).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	contenthash, err := compiler.ExtractInfo(&contract, filename) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// sender and contract address are passed as hex strings | 
					
						
							|  |  |  | 	codeb := js.xeth.CodeAtBytes(address) | 
					
						
							|  |  |  | 	codehash := common.BytesToHash(crypto.Sha3(codeb)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	registry := resolver.New(js.xeth) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_, err = registry.RegisterContentHash(common.HexToAddress(sender), codehash, contenthash) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 	v, _ := call.Otto.ToValue(contenthash.Hex()) | 
					
						
							|  |  |  | 	return v | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) registerUrl(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	if len(call.ArgumentList) != 3 { | 
					
						
							|  |  |  | 		fmt.Println("requires 3 arguments: admin.contractInfo.register(fromaddress, contenthash, filename)") | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	sender, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	contenthash, err := call.Argument(1).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	url, err := call.Argument(2).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	registry := resolver.New(js.xeth) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_, err = registry.RegisterUrl(common.HexToAddress(sender), common.HexToHash(contenthash), url) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) getContractInfo(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	if len(call.ArgumentList) != 1 { | 
					
						
							|  |  |  | 		fmt.Println("requires 1 argument: admin.contractInfo.register(contractaddress)") | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	addr, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	infoDoc, err := natspec.FetchDocsForContract(addr, js.xeth, ds) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var info compiler.ContractInfo | 
					
						
							|  |  |  | 	err = json.Unmarshal(infoDoc, &info) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.UndefinedValue() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-25 02:27:37 +02:00
										 |  |  | 	v, _ := call.Otto.ToValue(info) | 
					
						
							|  |  |  | 	return v | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) startNatSpec(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	js.ethereum.NatSpec = true | 
					
						
							|  |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-22 23:11:11 +01:00
										 |  |  | func (js *jsre) stopNatSpec(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 	js.ethereum.NatSpec = false | 
					
						
							|  |  |  | 	return otto.TrueValue() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (js *jsre) newRegistry(call otto.FunctionCall) otto.Value { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if len(call.ArgumentList) != 1 { | 
					
						
							|  |  |  | 		fmt.Println("requires 1 argument: admin.contractInfo.newRegistry(adminaddress)") | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	addr, err := call.Argument(0).ToString() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	registry := resolver.New(js.xeth) | 
					
						
							|  |  |  | 	err = registry.CreateContracts(common.HexToAddress(addr)) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return otto.FalseValue() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return otto.TrueValue() | 
					
						
							| 
									
										
										
										
											2015-03-15 13:43:48 +07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-05-06 14:53:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // internal transaction type which will allow us to resend transactions  using `eth.resend` | 
					
						
							|  |  |  | type tx struct { | 
					
						
							|  |  |  | 	tx *types.Transaction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	To       string | 
					
						
							|  |  |  | 	From     string | 
					
						
							|  |  |  | 	Nonce    string | 
					
						
							|  |  |  | 	Value    string | 
					
						
							|  |  |  | 	Data     string | 
					
						
							|  |  |  | 	GasLimit string | 
					
						
							|  |  |  | 	GasPrice string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func newTx(t *types.Transaction) *tx { | 
					
						
							|  |  |  | 	from, _ := t.From() | 
					
						
							|  |  |  | 	var to string | 
					
						
							|  |  |  | 	if t := t.To(); t != nil { | 
					
						
							|  |  |  | 		to = t.Hex() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return &tx{ | 
					
						
							|  |  |  | 		tx:       t, | 
					
						
							|  |  |  | 		To:       to, | 
					
						
							|  |  |  | 		From:     from.Hex(), | 
					
						
							|  |  |  | 		Value:    t.Amount.String(), | 
					
						
							|  |  |  | 		Nonce:    strconv.Itoa(int(t.Nonce())), | 
					
						
							|  |  |  | 		Data:     "0x" + common.Bytes2Hex(t.Data()), | 
					
						
							|  |  |  | 		GasLimit: t.GasLimit.String(), | 
					
						
							|  |  |  | 		GasPrice: t.GasPrice().String(), | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |