github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/contracts/chequebook/gencode.go (about) 1 // +build none 2 3 // This program generates contract/code.go, which contains the chequebook code 4 // after deployment. 5 package main 6 7 import ( 8 "fmt" 9 "io/ioutil" 10 "math/big" 11 12 "github.com/quickchainproject/quickchain/accounts/abi/bind" 13 "github.com/quickchainproject/quickchain/accounts/abi/bind/backends" 14 "github.com/quickchainproject/quickchain/contracts/chequebook/contract" 15 "github.com/quickchainproject/quickchain/core" 16 "github.com/quickchainproject/quickchain/crypto" 17 ) 18 19 var ( 20 testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") 21 testAlloc = core.GenesisAlloc{ 22 crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(500000000000)}, 23 } 24 ) 25 26 func main() { 27 backend := backends.NewSimulatedBackend(testAlloc) 28 auth := bind.NewKeyedTransactor(testKey) 29 30 // Deploy the contract, get the code. 31 addr, _, _, err := contract.DeployChequebook(auth, backend) 32 if err != nil { 33 panic(err) 34 } 35 backend.Commit() 36 code, err := backend.CodeAt(nil, addr, nil) 37 if err != nil { 38 panic(err) 39 } 40 if len(code) == 0 { 41 panic("empty code") 42 } 43 44 // Write the output file. 45 content := fmt.Sprintf(`package contract 46 47 // ContractDeployedCode is used to detect suicides. This constant needs to be 48 // updated when the contract code is changed. 49 const ContractDeployedCode = "%#x" 50 `, code) 51 if err := ioutil.WriteFile("contract/code.go", []byte(content), 0644); err != nil { 52 panic(err) 53 } 54 }