types

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BaseTypes = map[string]interface{}{
	"string": func(_ string, _ shim.ChaincodeStubInterface, in string) (string, error) {
		return in, nil
	},
	"int": func(_ int, _ shim.ChaincodeStubInterface, in string) (int, error) {
		return strconv.Atoi(in)
	},
	"bool": func(_ bool, _ shim.ChaincodeStubInterface, in string) (bool, error) {
		return in != "" && strings.ToLower(in) != "false", nil
	},
	"int64": func(_ int64, _ shim.ChaincodeStubInterface, in string) (int64, error) {
		return strconv.ParseInt(in, 10, 64)
	},
	"uint32": func(_ uint32, _ shim.ChaincodeStubInterface, in string) (uint32, error) {
		v, err := strconv.ParseUint(in, 10, 32)
		if err != nil {
			return 0, err
		}
		return uint32(v), nil
	},
	"uint64": func(_ uint64, _ shim.ChaincodeStubInterface, in string) (uint64, error) {
		v, err := strconv.ParseUint(in, 10, 64)
		if err != nil {
			return 0, err
		}
		return v, nil
	},
	"float64": func(_ float64, _ shim.ChaincodeStubInterface, in string) (float64, error) {
		return strconv.ParseFloat(in, 64)
	},
	"*big.Int": func(_ *big.Int, _ shim.ChaincodeStubInterface, in string) (*big.Int, error) {
		value, ok := new(big.Int).SetString(in, 10)
		if !ok {
			return nil, fmt.Errorf("couldn't convert %s to bigint", in)
		}
		if value.Cmp(big.NewInt(0)) < 0 {
			return nil, fmt.Errorf("value %s should be positive", in)
		}
		return value, nil
	},
	"[]uint8": func(_ []uint8, stub shim.ChaincodeStubInterface, in string) ([]uint8, error) {
		return base58.Decode(in), nil
	},
}

BaseTypes is a map of base types

Functions

func ConvertToAsset

func ConvertToAsset(in []*MultiSwapAsset) ([]*pb.Asset, error)

ConvertToAsset converts MultiSwapAsset to Asset

func IsValidAddressLen

func IsValidAddressLen(val []byte) bool

IsValidAddressLen checks if address length is valid

Types

type Address

type Address pb.Address

Address is a wrapper for address

func AddrFromBase58Check

func AddrFromBase58Check(in string) (*Address, error)

AddrFromBase58Check creates address from base58 string

func AddrFromBytes

func AddrFromBytes(in []byte) *Address

AddrFromBytes creates address from bytes

func (*Address) Bytes

func (a *Address) Bytes() []byte

Bytes returns address bytes

func (*Address) ConvertToCall

func (a *Address) ConvertToCall(_ shim.ChaincodeStubInterface, in string) (*Address, error)

ConvertToCall converts string to address

func (*Address) Equal

func (a *Address) Equal(b *Address) bool

Equal compares two addresses

func (*Address) IsUserIDSame

func (a *Address) IsUserIDSame(b *Address) bool

IsUserIDSame checks if userIDs are the same

func (*Address) MarshalJSON

func (a *Address) MarshalJSON() ([]byte, error)

MarshalJSON marshals address to json

func (*Address) PrepareToSave

func (a *Address) PrepareToSave(stub shim.ChaincodeStubInterface, in string) (string, error)

PrepareToSave checks if address is blacklisted

func (*Address) String

func (a *Address) String() string

String returns address string

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals address from json

type Hex

type Hex []byte

Hex is a wrapper for []byte

func (Hex) ConvertToCall

func (h Hex) ConvertToCall(_ shim.ChaincodeStubInterface, in string) (Hex, error)

ConvertToCall converts string to hex

type MultiSwapAsset

type MultiSwapAsset struct {
	Group  string `json:"group,omitempty"`
	Amount string `json:"amount,omitempty"`
}

MultiSwapAsset is a wrapper for asset

type MultiSwapAssets

type MultiSwapAssets struct {
	Assets []*MultiSwapAsset
}

MultiSwapAssets is a wrapper for asset

func (MultiSwapAssets) ConvertToCall

ConvertToCall converts string to MultiSwapAssets

type Sender

type Sender struct {
	// contains filtered or unexported fields
}

Sender is a wrapper for address

func NewSenderFromAddr

func NewSenderFromAddr(addr *Address) *Sender

NewSenderFromAddr creates sender from address

func (*Sender) Address

func (s *Sender) Address() *Address

Address returns address

func (*Sender) Equal

func (s *Sender) Equal(addr *Address) bool

Equal compares two senders

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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