voucher

package
v0.0.118 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

README

Voucher Package

The voucher package provides functionality to encode and decode voucher data structures using Ethereum's ABI ( Application Binary Interface) encoding. It specifically handles the encoding and decoding of IVoucherVoucher structures as defined by the clearsync Ethereum contract interface (see github.com/layer-3/clearsync/pkg/abi/ivoucher).

Usage

The package provides two main functions:

  1. Encode(voucher ivoucher.IVoucherVoucher) ([]byte, error): This function takes a IVoucherVoucher structure and returns its ABI-encoded byte slice. It returns an error if the encoding fails.

  2. Decode(voucher []byte) (ivoucher.IVoucherVoucher, error): This function decodes an ABI-encoded byte slice into a IVoucherVoucher structure. It returns an error if the decoding fails.

Example

Here's a basic example on how to use this package to encode and decode a IVoucherVoucher:

package main

import (
	"fmt"
	"log"

	"github.com/ethereum/go-ethereum/common"

	"github.com/layer-3/clearsync/pkg/abi/ivoucher"
	"github.com/layer-3/clearsync/pkg/voucher"
)

func main() {
	v := ivoucher.IVoucherVoucher{
		Target:          common.HexToAddress("0xabc123abc123abc123abc123abc123abc123abc1"),
		Action:          3,
		Beneficiary:     common.HexToAddress("0xdef456def456def456def456def456def456def4"),
		ExpireAt:          1715100785,
		ChainId:         59144,
		VoucherCodeHash: [32]byte{/*--snip--*/},
		EncodedParams:   []byte("paramData"),
	}

	// Encode
	encoded, err := voucher.Encode(v)
	if err != nil {
		log.Fatal("Failed to encode voucher: ", err)
	}
	fmt.Println("Encoded voucher:", common.Bytes2Hex(encoded))

	// Decode
	decoded, err := voucher.Decode(encoded)
	if err != nil {
		log.Fatal("Failed to decode voucher:", err)
		return
	}
	fmt.Println("Result:", decoded)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(voucher []byte) (ivoucher.IVoucherVoucher, error)

Decode decodes a byte slice into a Voucher struct according to Ethereum ABI.

func Encode

func Encode(voucher ivoucher.IVoucherVoucher) ([]byte, error)

Encode encodes the Voucher into a byte slice according to Ethereum ABI.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL