+type DebitCert struct {
+ Holder string
+ Serial int64
+ Balance int64
+ Denomination string
+ Issuer string
+ Date int64
+ Difference int64
+ Draft string
+ Beneficiary string
+ AuthorizedBy string
+ Notes *string // optional
+ LastDebitSerial int64 // 0 if none
+ LastCreditSerial int64 // 0 if none
+ LastCert *string // nil if serial == 1
+ References []string
+}
+
+type CreditCert struct {
+ Holder string
+ Serial int64
+ Balance int64
+ Denomination string
+ Issuer string
+ Date int64
+ Difference int64
+ Draft string
+ Drawer string
+ DebitCert string
+ AuthorizedBy string
+ Notes *string // optional
+ LastDebitSerial int64 // 0 if none
+ LastCreditSerial int64 // 0 if none
+ LastCert *string // ? if serial == 1
+ References []string
+}
+
+type BounceCert struct {
+ Drawer string
+ Draft string
+ LastCert *string // optional
+ Balance int64 // 0 if none
+ Date int64
+ AuthorizedBy string
+ Notes *string // optional
+ References []string
+}
+
+func ToCert(v interface{}) (cert *Cert, err error) {
+ cert = new(Cert)
+ switch x := v.(type) {
+ case *DebitCert:
+ cert.IsDebit = true
+ cert.Beneficiary = &x.Beneficiary
+
+ cert.Holder = x.Holder
+ cert.Serial = x.Serial
+ cert.Balance = x.Balance
+ cert.Denomination = x.Denomination
+ cert.Issuer = x.Issuer
+ cert.Date = x.Date
+ cert.Difference = x.Difference
+ cert.Draft = x.Draft
+ cert.AuthorizedBy = x.AuthorizedBy
+ cert.Notes = x.Notes
+ cert.LastDebitSerial = x.LastDebitSerial
+ cert.LastCreditSerial = x.LastCreditSerial
+ cert.LastCert = x.LastCert
+ cert.References = x.References
+
+ case *CreditCert:
+ cert.IsDebit = false
+ cert.Drawer = &x.Drawer
+ cert.DebitCert = &x.DebitCert
+
+ cert.Holder = x.Holder
+ cert.Serial = x.Serial
+ cert.Balance = x.Balance
+ cert.Denomination = x.Denomination
+ cert.Issuer = x.Issuer
+ cert.Date = x.Date
+ cert.Difference = x.Difference
+ cert.Draft = x.Draft
+ cert.AuthorizedBy = x.AuthorizedBy
+ cert.Notes = x.Notes
+ cert.LastDebitSerial = x.LastDebitSerial
+ cert.LastCreditSerial = x.LastCreditSerial
+ cert.LastCert = x.LastCert
+ cert.References = x.References
+ default:
+ err = fmt.Errorf("ToCert: only debit or credit document can be converted to cert")