Search Apps Documentation Source Content File Folder Download Copy Actions Download

oft.gno

1.75 Kb · 67 lines
 1package lziface
 2
 3import (
 4	"encoding/binary"
 5
 6	"gno.land/p/samcrew/deps/onbloc/uint256"
 7)
 8
 9const OFT_SEND_TO_OFFSET = 32
10const OFT_SEND_AMOUNT_SD_OFFSET = 40
11
12type OFTMsg []byte
13
14func OFTMsgEncode(to [32]byte, amountSD uint64, composeMsg []byte) ([]byte, bool) {
15	res := make([]byte, OFT_SEND_AMOUNT_SD_OFFSET+len(composeMsg))
16	copy(res, to[:])
17	binary.BigEndian.PutUint64(res[OFT_SEND_TO_OFFSET:], amountSD)
18	copy(res[OFT_SEND_AMOUNT_SD_OFFSET:], composeMsg)
19	return res, len(composeMsg) != 0
20}
21
22/**
23 * @dev Checks if the OFT message is composed.
24 * @param _msg The OFT message.
25 * @return A boolean indicating whether the message is composed.
26 */
27func (msg OFTMsg) IsComposed() bool {
28	return len(msg) > OFT_SEND_AMOUNT_SD_OFFSET
29}
30
31/**
32 * @dev Retrieves the recipient address from the OFT message.
33 * @param _msg The OFT message.
34 * @return The recipient address.
35 */
36func (msg OFTMsg) SendTo() [32]byte {
37	res := [32]byte{}
38	copy(res[:], msg)
39	return res
40}
41
42/**
43 * @dev Retrieves the amount in shared decimals from the OFT message.
44 * @param _msg The OFT message.
45 * @return The amount in shared decimals.
46 */
47func (msg OFTMsg) AmountSD() uint64 {
48	return binary.BigEndian.Uint64(msg[OFT_SEND_TO_OFFSET:])
49}
50
51/**
52 * @dev Retrieves the composed message from the OFT message.
53 * @param _msg The OFT message.
54 * @return The composed message.
55 */
56func (msg OFTMsg) ComposeMsg() []byte {
57	return msg[OFT_SEND_AMOUNT_SD_OFFSET:]
58}
59
60/**
61 * @dev Struct representing OFT receipt information.
62 */
63type OFTReceipt struct {
64	AmountSentLD *uint256.Uint // Amount of tokens ACTUALLY debited from the sender in local decimals.
65	// @dev In non-default implementations, the amountReceivedLD COULD differ from this value.
66	AmountReceivedLD *uint256.Uint // Amount of tokens to be received on the remote side.
67}