github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/contracts/chequebook/gencode.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 // +build none 13 14 // This program generates contract/code.go, which contains the chequebook code 15 // after deployment. 16 package main 17 18 import ( 19 "fmt" 20 "io/ioutil" 21 "math/big" 22 23 "github.com/Sberex/go-sberex/accounts/abi/bind" 24 "github.com/Sberex/go-sberex/accounts/abi/bind/backends" 25 "github.com/Sberex/go-sberex/contracts/chequebook/contract" 26 "github.com/Sberex/go-sberex/core" 27 "github.com/Sberex/go-sberex/crypto" 28 ) 29 30 var ( 31 testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") 32 testAlloc = core.GenesisAlloc{ 33 crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(500000000000)}, 34 } 35 ) 36 37 func main() { 38 backend := backends.NewSimulatedBackend(testAlloc) 39 auth := bind.NewKeyedTransactor(testKey) 40 41 // Deploy the contract, get the code. 42 addr, _, _, err := contract.DeployChequebook(auth, backend) 43 if err != nil { 44 panic(err) 45 } 46 backend.Commit() 47 code, err := backend.CodeAt(nil, addr, nil) 48 if err != nil { 49 panic(err) 50 } 51 if len(code) == 0 { 52 panic("empty code") 53 } 54 55 // Write the output file. 56 content := fmt.Sprintf(`package contract 57 58 // ContractDeployedCode is used to detect suicides. This constant needs to be 59 // updated when the contract code is changed. 60 const ContractDeployedCode = "%#x" 61 `, code) 62 if err := ioutil.WriteFile("contract/code.go", []byte(content), 0644); err != nil { 63 panic(err) 64 } 65 }