github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/chain/contracts/chequebook/api.go (about)

     1  package chequebook
     2  
     3  import (
     4  	"errors"
     5  	"math/big"
     6  
     7  	"github.com/neatio-net/neatio/utilities/common"
     8  )
     9  
    10  const Version = "1.0"
    11  
    12  var errNoChequebook = errors.New("no chequebook")
    13  
    14  type Api struct {
    15  	chequebookf func() *Chequebook
    16  }
    17  
    18  func NewApi(ch func() *Chequebook) *Api {
    19  	return &Api{ch}
    20  }
    21  
    22  func (self *Api) Balance() (string, error) {
    23  	ch := self.chequebookf()
    24  	if ch == nil {
    25  		return "", errNoChequebook
    26  	}
    27  	return ch.Balance().String(), nil
    28  }
    29  
    30  func (self *Api) Issue(beneficiary common.Address, amount *big.Int) (cheque *Cheque, err error) {
    31  	ch := self.chequebookf()
    32  	if ch == nil {
    33  		return nil, errNoChequebook
    34  	}
    35  	return ch.Issue(beneficiary, amount)
    36  }
    37  
    38  func (self *Api) Cash(cheque *Cheque) (txhash string, err error) {
    39  	ch := self.chequebookf()
    40  	if ch == nil {
    41  		return "", errNoChequebook
    42  	}
    43  	return ch.Cash(cheque)
    44  }
    45  
    46  func (self *Api) Deposit(amount *big.Int) (txhash string, err error) {
    47  	ch := self.chequebookf()
    48  	if ch == nil {
    49  		return "", errNoChequebook
    50  	}
    51  	return ch.Deposit(amount)
    52  }