github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/contracts/chequebook/gencode.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:33</date> 10 //</624342613473890304> 11 12 13 //+不建 14 15 // 16 //部署后。 17 package main 18 19 import ( 20 "fmt" 21 "io/ioutil" 22 "math/big" 23 24 "github.com/ethereum/go-ethereum/accounts/abi/bind" 25 "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" 26 "github.com/ethereum/go-ethereum/contracts/chequebook/contract" 27 "github.com/ethereum/go-ethereum/core" 28 "github.com/ethereum/go-ethereum/crypto" 29 ) 30 31 var ( 32 testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") 33 testAlloc = core.GenesisAlloc{ 34 crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(500000000000)}, 35 } 36 ) 37 38 func main() { 39 backend := backends.NewSimulatedBackend(testAlloc, uint64(100000000)) 40 auth := bind.NewKeyedTransactor(testKey) 41 42 //部署合同,获取代码。 43 addr, _, _, err := contract.DeployChequebook(auth, backend) 44 if err != nil { 45 panic(err) 46 } 47 backend.Commit() 48 code, err := backend.CodeAt(nil, addr, nil) 49 if err != nil { 50 panic(err) 51 } 52 if len(code) == 0 { 53 panic("empty code") 54 } 55 56 // 57 content := fmt.Sprintf(`package contract 58 59 //ContractDeployedCode用于检测自杀。这个常数需要 60 //合同代码更改时更新。 61 const ContractDeployedCode = "%#x" 62 `, code) 63 if err := ioutil.WriteFile("contract/code.go", []byte(content), 0644); err != nil { 64 panic(err) 65 } 66 } 67