aboutsummaryrefslogtreecommitdiff
path: root/examples/payments/main.go
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-08-12 16:27:52 -0400
committerDeterminant <[email protected]>2019-08-12 16:27:52 -0400
commitfd39e6b30af5d855dce23899394e6ef80a2c0a41 (patch)
tree0c5b8690cc6f497657f8f65a5e7f97c4c4365fb9 /examples/payments/main.go
parentce505015e5f973c8f5d605aa468ad75fceeeb169 (diff)
...
Diffstat (limited to 'examples/payments/main.go')
-rw-r--r--examples/payments/main.go61
1 files changed, 39 insertions, 22 deletions
diff --git a/examples/payments/main.go b/examples/payments/main.go
index 24ba962..d5d10b4 100644
--- a/examples/payments/main.go
+++ b/examples/payments/main.go
@@ -1,43 +1,60 @@
package main
import (
+ //"time"
+ "os"
+ "os/signal"
+ "syscall"
+ "crypto/rand"
"math/big"
- "encoding/hex"
+ //"encoding/hex"
"github.com/ethereum/go-ethereum/core/types"
- "github.com/ethereum/go-ethereum/common"
+ //"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/Determinant/coreth/eth"
"github.com/Determinant/coreth"
- "github.com/ethereum/go-ethereum/log"
- "github.com/ethereum/go-ethereum/params"
- "time"
+ "github.com/ethereum/go-ethereum/log"
+ "github.com/ethereum/go-ethereum/params"
)
+func checkError(err error) {
+ if err != nil { panic(err) }
+}
+
func main() {
- log.Root().SetHandler(log.StdoutHandler)
+ log.Root().SetHandler(log.StderrHandler)
config := eth.DefaultConfig
- genAddr := common.Address{}
+ chainConfig := params.MainnetChainConfig
+
genBalance := big.NewInt(1000000000000000000)
+ genKey, _ := coreth.NewKey(rand.Reader)
+
config.Genesis = &core.Genesis{
Config: params.MainnetChainConfig,
- Nonce: 66,
- ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
- GasLimit: 5000,
+ Nonce: 0,
+ ExtraData: hexutil.MustDecode("0x00"),
+ GasLimit: 100000000,
Difficulty: big.NewInt(0),
- Alloc: core.GenesisAlloc{genAddr: {Balance: genBalance }},
+ Alloc: core.GenesisAlloc{ genKey.Address: { Balance: genBalance }},
}
- chain := coreth.NewETHChain(&config, nil, nil)
- to := common.Address{}
- nouce := 0
- amount := big.NewInt(0)
- gasLimit := 1000000000
- gasPrice := big.NewInt(0)
- deployCode, _ := hex.DecodeString("608060405234801561001057600080fd5b50600760008190555060cc806100276000396000f3fe6080604052600436106039576000357c0100000000000000000000000000000000000000000000000000000000900480631003e2d214603e575b600080fd5b348015604957600080fd5b50607360048036036020811015605e57600080fd5b81019080803590602001909291905050506089565b6040518082815260200191505060405180910390f35b60008160005401600081905550600054905091905056fea165627a7a7230582075069a1c11ef20dd272178c92ff7d593d7ef9c39b1a63e85588f9e45be9fb6420029")
- tx := types.NewTransaction(uint64(nouce), to, amount, uint64(gasLimit), gasPrice, deployCode)
+
+ chainID := chainConfig.ChainID
+ nonce := uint64(0)
+ value := big.NewInt(1000000000000)
+ gasLimit := 21000
+ gasPrice := big.NewInt(1000)
+ bob, err := coreth.NewKey(rand.Reader); checkError(err)
+ tx := types.NewTransaction(nonce, bob.Address, value, uint64(gasLimit), gasPrice, nil)
+ signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), genKey.PrivateKey); checkError(err)
+
+ chain := coreth.NewETHChain(&config, chainConfig, nil)
chain.Start()
- //_ = tx
- chain.AddLocalTxs([]*types.Transaction{tx})
- time.Sleep(10000 * time.Millisecond)
+ chain.AddLocalTxs([]*types.Transaction{signedTx})
+
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, os.Interrupt, syscall.SIGTERM)
+ signal.Notify(c, os.Interrupt, syscall.SIGINT)
+ <-c
chain.Stop()
}