github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/contracts/chequebook/api.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 //</624342613041876992> 11 12 13 package chequebook 14 15 import ( 16 "errors" 17 "math/big" 18 19 "github.com/ethereum/go-ethereum/common" 20 ) 21 22 const Version = "1.0" 23 24 var errNoChequebook = errors.New("no chequebook") 25 26 type Api struct { 27 chequebookf func() *Chequebook 28 } 29 30 func NewApi(ch func() *Chequebook) *Api { 31 return &Api{ch} 32 } 33 34 func (self *Api) Balance() (string, error) { 35 ch := self.chequebookf() 36 if ch == nil { 37 return "", errNoChequebook 38 } 39 return ch.Balance().String(), nil 40 } 41 42 func (self *Api) Issue(beneficiary common.Address, amount *big.Int) (cheque *Cheque, err error) { 43 ch := self.chequebookf() 44 if ch == nil { 45 return nil, errNoChequebook 46 } 47 return ch.Issue(beneficiary, amount) 48 } 49 50 func (self *Api) Cash(cheque *Cheque) (txhash string, err error) { 51 ch := self.chequebookf() 52 if ch == nil { 53 return "", errNoChequebook 54 } 55 return ch.Cash(cheque) 56 } 57 58 func (self *Api) Deposit(amount *big.Int) (txhash string, err error) { 59 ch := self.chequebookf() 60 if ch == nil { 61 return "", errNoChequebook 62 } 63 return ch.Deposit(amount) 64 } 65