types

package
v0.16.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

nolint

nolint

Index

Constants

View Source
const (
	DefaultCodespace sdk.CodespaceType = "htlc"

	CodeInvalidAddress        sdk.CodeType = 100
	CodeInvalidAmount         sdk.CodeType = 101
	CodeInvalidHashLock       sdk.CodeType = 102
	CodeHashLockAlreadyExists sdk.CodeType = 103
	CodeInvalidTimeLock       sdk.CodeType = 104
	CodeInvalidSecret         sdk.CodeType = 105
	CodeStateIsNotOpen        sdk.CodeType = 106
	CodeStateIsNotExpired     sdk.CodeType = 107
)

Rand errors reserve 100 ~ 199.

View Source
const (
	// MsgRoute identifies transaction types
	MsgRoute = "htlc"

	// type for MsgCreateHTLC
	TypeMsgCreateHTLC = "create_htlc"

	// type for MsgClaimHTLC
	TypeMsgClaimHTLC = "claim_htlc"

	// type for MsgRefundHTLC
	TypeMsgRefundHTLC = "refund_htlc"

	SecretLength                    = 32    // the length for the secret
	HashLockLength                  = 32    // the length for the hash lock
	MaxLengthForAddressOnOtherChain = 128   // maximal length for the address on other chains
	MinTimeLock                     = 50    // minimal time span for HTLC
	MaxTimeLock                     = 25480 // maximal time span for HTLC
)
View Source
const (
	DefaultParamSpace = "htlc"
)
View Source
const (
	QueryHTLC = "htlc"
)

Variables

View Source
var (
	HTLCStateToStringMap = map[HTLCState]string{
		OPEN:      "open",
		COMPLETED: "completed",
		EXPIRED:   "expired",
		REFUNDED:  "refunded",
	}
	StringToHTLCStateMap = map[string]HTLCState{
		"open":      OPEN,
		"completed": COMPLETED,
		"expired":   EXPIRED,
		"refunded":  REFUNDED,
	}
)
View Source
var (
	TagSender               = "sender"
	TagReceiver             = "receiver"
	TagReceiverOnOtherChain = "receiver-on-other-chain"
	TagAmount               = "amount"
	TagHashLock             = "hash-lock"
	TagSecret               = "secret"
)

Functions

func ErrHashLockAlreadyExists

func ErrHashLockAlreadyExists(codespace sdk.CodespaceType, msg string) sdk.Error

func ErrInvalidAddress

func ErrInvalidAddress(codespace sdk.CodespaceType, msg string) sdk.Error

func ErrInvalidAmount

func ErrInvalidAmount(codespace sdk.CodespaceType, msg string) sdk.Error

func ErrInvalidHashLock

func ErrInvalidHashLock(codespace sdk.CodespaceType, msg string) sdk.Error

func ErrInvalidSecret

func ErrInvalidSecret(codespace sdk.CodespaceType, msg string) sdk.Error

func ErrInvalidTimeLock

func ErrInvalidTimeLock(codespace sdk.CodespaceType, msg string) sdk.Error

func ErrStateIsNotExpired

func ErrStateIsNotExpired(codespace sdk.CodespaceType, msg string) sdk.Error

func ErrStateIsNotOpen

func ErrStateIsNotOpen(codespace sdk.CodespaceType, msg string) sdk.Error

func ParamTypeTable

func ParamTypeTable() params.TypeTable

ParamTable for HTLC module

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

Register concrete types on codec

func ValidateParams

func ValidateParams(p Params) error

Types

type BankKeeper

type BankKeeper interface {
	AddCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, sdk.Tags, sdk.Error)

	SetTotalSupply(ctx sdk.Context, totalSupply sdk.Coin)

	GetTotalSupply(ctx sdk.Context, denom string) (coin sdk.Coin, found bool)

	IncreaseTotalSupply(ctx sdk.Context, amt sdk.Coin) sdk.Error

	BurnCoins(ctx sdk.Context, fromAddr sdk.AccAddress, amt sdk.Coins) (sdk.Tags, sdk.Error)

	SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) (sdk.Tags, sdk.Error)
}

expected bank keeper

type GenesisState

type GenesisState struct {
	PendingHTLCs map[string]HTLC // claimable HTLCs
}

GenesisState contains all HTLC state that must be provided at genesis

type HTLC

type HTLC struct {
	Sender               sdk.AccAddress `json:"sender"`                  // the initiator address
	To                   sdk.AccAddress `json:"to"`                      // the destination address
	ReceiverOnOtherChain string         `json:"receiver_on_other_chain"` // the claim receiving address on the other chain
	Amount               sdk.Coins      `json:"amount"`                  // the amount to be transferred
	Secret               []byte         `json:"secret"`                  // the random secret which is of 32 bytes
	Timestamp            uint64         `json:"timestamp"`               // the timestamp, if provided, used to generate the hash lock together with secret
	ExpireHeight         uint64         `json:"expire_height"`           // the block height by which the HTLC expires
	State                HTLCState      `json:"state"`                   // the state of the HTLC
}

HTLC represents an HTLC

func NewHTLC

func NewHTLC(
	sender sdk.AccAddress,
	to sdk.AccAddress,
	receiverOnOtherChain string,
	amount sdk.Coins,
	secret []byte,
	timestamp uint64,
	expireHeight uint64,
	state HTLCState,
) HTLC

NewHTLC constructs an HTLC

func (HTLC) GetHashLock

func (h HTLC) GetHashLock() []byte

GetHashLock calculates the hash lock

func (HTLC) HumanString

func (h HTLC) HumanString(converter sdk.CoinsConverter) string

HumanString implements human

func (HTLC) String

func (h HTLC) String() string

String implements fmt.Stringer

type HTLCState

type HTLCState byte

HTLCState represents the state of an HTLC

const (
	OPEN      HTLCState = 0x00 // claimable
	COMPLETED HTLCState = 0x01 // claimed
	EXPIRED   HTLCState = 0x02 // expired
	REFUNDED  HTLCState = 0x03 // refunded
)

func HTLCStateFromString

func HTLCStateFromString(str string) (HTLCState, error)

func (HTLCState) Format

func (state HTLCState) Format(s fmt.State, verb rune)

func (HTLCState) Marshal

func (state HTLCState) Marshal() ([]byte, error)

Marshal needed for protobuf compatibility

func (HTLCState) MarshalJSON

func (state HTLCState) MarshalJSON() ([]byte, error)

Marshals to JSON using string

func (HTLCState) String

func (state HTLCState) String() string

func (*HTLCState) Unmarshal

func (state *HTLCState) Unmarshal(data []byte) error

Unmarshal needed for protobuf compatibility

func (*HTLCState) UnmarshalJSON

func (state *HTLCState) UnmarshalJSON(data []byte) error

Unmarshals from JSON

type MsgClaimHTLC

type MsgClaimHTLC struct {
	Sender   sdk.AccAddress `json:"sender"`    // the initiator address
	HashLock []byte         `json:"hash_lock"` // the hash lock identifying the HTLC to be claimed
	Secret   []byte         `json:"secret"`    // the secret with which to claim
}

MsgClaimHTLC represents a msg for claiming an HTLC

func NewMsgClaimHTLC

func NewMsgClaimHTLC(
	sender sdk.AccAddress,
	hashLock []byte,
	secret []byte,
) MsgClaimHTLC

NewMsgClaimHTLC constructs a MsgClaimHTLC

func (MsgClaimHTLC) GetSignBytes

func (msg MsgClaimHTLC) GetSignBytes() []byte

Implements Msg.

func (MsgClaimHTLC) GetSigners

func (msg MsgClaimHTLC) GetSigners() []sdk.AccAddress

Implements Msg.

func (MsgClaimHTLC) Route

func (msg MsgClaimHTLC) Route() string

Implements Msg.

func (MsgClaimHTLC) Type

func (msg MsgClaimHTLC) Type() string

Implements Msg.

func (MsgClaimHTLC) ValidateBasic

func (msg MsgClaimHTLC) ValidateBasic() sdk.Error

Implements Msg.

type MsgCreateHTLC

type MsgCreateHTLC struct {
	Sender               sdk.AccAddress `json:"sender"`                  // the initiator address
	To                   sdk.AccAddress `json:"to"`                      // the destination address
	ReceiverOnOtherChain string         `json:"receiver_on_other_chain"` // the claim receiving address on the other chain
	Amount               sdk.Coins      `json:"amount"`                  // the amount to be transferred
	HashLock             []byte         `json:"hash_lock"`               // the hash lock generated from secret (and timestamp if provided)
	Timestamp            uint64         `json:"timestamp"`               // if provided, used to generate the hash lock together with secret
	TimeLock             uint64         `json:"time_lock"`               // the time span after which the HTLC will expire
}

MsgCreateHTLC represents a msg for creating an HTLC

func NewMsgCreateHTLC

func NewMsgCreateHTLC(
	sender sdk.AccAddress,
	to sdk.AccAddress,
	receiverOnOtherChain string,
	amount sdk.Coins,
	hashLock []byte,
	timestamp uint64,
	timeLock uint64,
) MsgCreateHTLC

NewMsgCreateHTLC constructs a MsgCreateHTLC

func (MsgCreateHTLC) GetSignBytes

func (msg MsgCreateHTLC) GetSignBytes() []byte

Implements Msg.

func (MsgCreateHTLC) GetSigners

func (msg MsgCreateHTLC) GetSigners() []sdk.AccAddress

Implements Msg.

func (MsgCreateHTLC) Route

func (msg MsgCreateHTLC) Route() string

Implements Msg.

func (MsgCreateHTLC) Type

func (msg MsgCreateHTLC) Type() string

Implements Msg.

func (MsgCreateHTLC) ValidateBasic

func (msg MsgCreateHTLC) ValidateBasic() sdk.Error

Implements Msg.

type MsgRefundHTLC

type MsgRefundHTLC struct {
	Sender   sdk.AccAddress `json:"sender"`    // the initiator address
	HashLock []byte         `json:"hash_lock"` // the hash lock identifying the HTLC to be refunded
}

MsgRefundHTLC represents a msg for refund an HTLC

func NewMsgRefundHTLC

func NewMsgRefundHTLC(
	sender sdk.AccAddress,
	hashLock []byte,
) MsgRefundHTLC

NewMsgClaimHTLC constructs a MsgClaimHTLC

func (MsgRefundHTLC) GetSignBytes

func (msg MsgRefundHTLC) GetSignBytes() []byte

Implements Msg.

func (MsgRefundHTLC) GetSigners

func (msg MsgRefundHTLC) GetSigners() []sdk.AccAddress

Implements Msg.

func (MsgRefundHTLC) Route

func (msg MsgRefundHTLC) Route() string

Implements Msg.

func (MsgRefundHTLC) Type

func (msg MsgRefundHTLC) Type() string

Implements Msg.

func (MsgRefundHTLC) ValidateBasic

func (msg MsgRefundHTLC) ValidateBasic() sdk.Error

Implements Msg.

type Params

type Params struct {
}

HTLC params

func DefaultParams

func DefaultParams() Params

default HTLC module params

func DefaultParamsForTest

func DefaultParamsForTest() Params

default HTLC module params for test

func (*Params) GetParamSpace

func (p *Params) GetParamSpace() string

Implements params.ParamSet

func (*Params) KeyValuePairs

func (p *Params) KeyValuePairs() params.KeyValuePairs

func (*Params) ReadOnly

func (p *Params) ReadOnly() bool

func (Params) String

func (p Params) String() string

func (*Params) StringFromBytes

func (p *Params) StringFromBytes(cdc *codec.Codec, key string, bytes []byte) (string, error)

func (*Params) Validate

func (p *Params) Validate(key string, value string) (interface{}, sdk.Error)

type QueryHTLCParams

type QueryHTLCParams struct {
	HashLock []byte
}

QueryHTLCParams is the query parameters for 'custom/htlc/htlc'

Jump to

Keyboard shortcuts

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