/
memo.go
51 lines (38 loc) · 1.54 KB
/
memo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package txnbuild
import (
"fmt"
"github.com/stellar/go/xdr"
)
// MemoText is used to send human messages of up to 28 bytes of ASCII/UTF-8.
type MemoText string
// MemoID is an identifier representing the transaction originator.
type MemoID uint64
// MemoHash is a hash representing a reference to another transaction.
type MemoHash [32]byte
// MemoReturn is a hash representing the hash of the transaction the sender is refunding.
type MemoReturn [32]byte
// MemoTextMaxLength is the maximum number of bytes allowed for a text memo.
const MemoTextMaxLength = 28
// Memo represents the superset of all memo types.
type Memo interface {
ToXDR() (xdr.Memo, error)
}
// ToXDR for MemoText returns an XDR object representation of a Memo of the same type.
func (mt MemoText) ToXDR() (xdr.Memo, error) {
if len(mt) > MemoTextMaxLength {
return xdr.Memo{}, fmt.Errorf("Memo text can't be longer than %d bytes", MemoTextMaxLength)
}
return xdr.NewMemo(xdr.MemoTypeMemoText, string(mt))
}
// ToXDR for MemoID returns an XDR object representation of a Memo of the same type.
func (mid MemoID) ToXDR() (xdr.Memo, error) {
return xdr.NewMemo(xdr.MemoTypeMemoId, xdr.Uint64(mid))
}
// ToXDR for MemoHash returns an XDR object representation of a Memo of the same type.
func (mh MemoHash) ToXDR() (xdr.Memo, error) {
return xdr.NewMemo(xdr.MemoTypeMemoHash, xdr.Hash(mh))
}
// ToXDR for MemoReturn returns an XDR object representation of a Memo of the same type.
func (mr MemoReturn) ToXDR() (xdr.Memo, error) {
return xdr.NewMemo(xdr.MemoTypeMemoReturn, xdr.Hash(mr))
}