htlc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2019 License: GPL-3.0 Imports: 6 Imported by: 0

README

HTLC module

Redeem Flow

Alice creates a HTLC that will pay 25wire to Bob if he can produce the preimage of the SHA256 hash 6815f3c300383519de8e437497e2c3e97852fe8d717a5419d5aafb00cb43c494 within 20 blocks.

$ regcli tx htlc add 25wire 6815f3c300383519de8e437497e2c3e97852fe8d717a5419d5aafb00cb43c494 20 $(regcli keys show bob --address) --from=$(regcli keys show alice --address) --chain-id=wireline

Check balances. Note that Alice's balance has decreased by 25wire, now locked in the HTLC.

$ regcli query account $(regcli keys show alice --address) --indent --chain-id=wireline
$ regcli query account $(regcli keys show bob --address) --indent --chain-id=wireline

Bob redeems the HTLC by presenting the preimage mango within 20 blocks.

$ regcli tx htlc redeem mango --from=$(regcli keys show bob --address) --chain-id=wireline

Check balances. Note that Bob's balance has increased by 25wire.

$ regcli query account $(regcli keys show alice --address) --indent --chain-id=wireline
$ regcli query account $(regcli keys show bob --address) --indent --chain-id=wireline

Timeout Flow

Alice creates a HTLC that will pay 25wire to Bob if he can produce the preimage of the SHA256 hash CB4595E84361629F0BB6A3EAA79220E553A8360191433538FF0E0C41F44E30DB within 20 blocks.

$ regcli tx htlc add 25wire CB4595E84361629F0BB6A3EAA79220E553A8360191433538FF0E0C41F44E30DB 20 $(regcli keys show bob --address) --from=$(regcli keys show alice --address) --chain-id=wireline

Alice claims a timeout after waiting for 20 blocks (also try running this before the timeout and see what happens).

$ regcli tx htlc fail CB4595E84361629F0BB6A3EAA79220E553A8360191433538FF0E0C41F44E30DB --from=$(regcli keys show alice --address) --chain-id=wireline

Check balances. Note that Alice has been refunded 25wire.

$ regcli query account $(regcli keys show alice --address) --indent --chain-id=wireline
$ regcli query account $(regcli keys show bob --address) --indent --chain-id=wireline

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(keeper Keeper) sdk.Handler

NewHandler returns a handler for "htlc" type messages.

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers concrete types on the Amino codec.

Types

type Keeper

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

Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine.

func NewKeeper

func NewKeeper(coinKeeper bank.Keeper, htlcStoreKey sdk.StoreKey, cdc *codec.Codec) Keeper

NewKeeper creates new instances of the HTLC Keeper.

func (Keeper) Clear

func (k Keeper) Clear(ctx sdk.Context)

Clear - clear all entries from the store [TESTING ONLY!].

func (Keeper) GetHtlc

func (k Keeper) GetHtlc(ctx sdk.Context, hash string) ObjHtlc

GetHtlc - gets a HTLC from the store.

func (Keeper) HasHtlc

func (k Keeper) HasHtlc(ctx sdk.Context, hash string) bool

HasHtlc - returns whether or not the HTLC by that hash exists.

func (Keeper) UpsertHtlc

func (k Keeper) UpsertHtlc(ctx sdk.Context, obj ObjHtlc)

UpsertHtlc - adds a HTLC to the store.

type MsgAddHtlc

type MsgAddHtlc struct {
	Amount         sdk.Coin
	Hash           string
	Locktime       int64
	RedeemAddress  sdk.AccAddress
	TimeoutAddress sdk.AccAddress
}

MsgAddHtlc defines a AddHtlc message.

func NewMsgAddHtlc

func NewMsgAddHtlc(amount sdk.Coin, hash string, locktime int64, redeemAddress sdk.AccAddress, timeoutAddress sdk.AccAddress) MsgAddHtlc

NewMsgAddHtlc is the constructor function for MsgAddHtlc.

func (MsgAddHtlc) GetSignBytes

func (msg MsgAddHtlc) GetSignBytes() []byte

GetSignBytes Implements Msg.

func (MsgAddHtlc) GetSigners

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

GetSigners Implements Msg.

func (MsgAddHtlc) Route

func (msg MsgAddHtlc) Route() string

Route Implements Msg.

func (MsgAddHtlc) Type

func (msg MsgAddHtlc) Type() string

Type Implements Msg.

func (MsgAddHtlc) ValidateBasic

func (msg MsgAddHtlc) ValidateBasic() sdk.Error

ValidateBasic Implements Msg.

type MsgClearHtlc

type MsgClearHtlc struct {
	Sender sdk.AccAddress
}

MsgClearHtlc defines the ClearHtlc message.

func NewMsgClearHtlc

func NewMsgClearHtlc(sender sdk.AccAddress) MsgClearHtlc

NewMsgClearHtlc is the constructor function for MsgClearHtlc.

func (MsgClearHtlc) GetSignBytes

func (msg MsgClearHtlc) GetSignBytes() []byte

GetSignBytes Implements Msg.

func (MsgClearHtlc) GetSigners

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

GetSigners Implements Msg.

func (MsgClearHtlc) Route

func (msg MsgClearHtlc) Route() string

Route Implements Msg.

func (MsgClearHtlc) Type

func (msg MsgClearHtlc) Type() string

Type Implements Msg.

func (MsgClearHtlc) ValidateBasic

func (msg MsgClearHtlc) ValidateBasic() sdk.Error

ValidateBasic Implements Msg.

type MsgFailHtlc

type MsgFailHtlc struct {
	Hash   string
	Sender sdk.AccAddress
}

MsgFailHtlc defines the FailHtlc message.

func NewMsgFailHtlc

func NewMsgFailHtlc(hash string, sender sdk.AccAddress) MsgFailHtlc

NewMsgFailHtlc is the constructor function for MsgFailHtlc.

func (MsgFailHtlc) GetSignBytes

func (msg MsgFailHtlc) GetSignBytes() []byte

GetSignBytes Implements Msg.

func (MsgFailHtlc) GetSigners

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

GetSigners Implements Msg.

func (MsgFailHtlc) Route

func (msg MsgFailHtlc) Route() string

Route Implements Msg.

func (MsgFailHtlc) Type

func (msg MsgFailHtlc) Type() string

Type Implements Msg.

func (MsgFailHtlc) ValidateBasic

func (msg MsgFailHtlc) ValidateBasic() sdk.Error

ValidateBasic Implements Msg.

type MsgRedeemHtlc

type MsgRedeemHtlc struct {
	Preimage string
	Sender   sdk.AccAddress
}

MsgRedeemHtlc defines the RedeemHtlc message.

func NewMsgRedeemHtlc

func NewMsgRedeemHtlc(preimage string, sender sdk.AccAddress) MsgRedeemHtlc

NewMsgRedeemHtlc is the constructor function for MsgRedeemHtlc.

func (MsgRedeemHtlc) GetSignBytes

func (msg MsgRedeemHtlc) GetSignBytes() []byte

GetSignBytes Implements Msg.

func (MsgRedeemHtlc) GetSigners

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

GetSigners Implements Msg.

func (MsgRedeemHtlc) Route

func (msg MsgRedeemHtlc) Route() string

Route Implements Msg.

func (MsgRedeemHtlc) Type

func (msg MsgRedeemHtlc) Type() string

Type Implements Msg.

func (MsgRedeemHtlc) ValidateBasic

func (msg MsgRedeemHtlc) ValidateBasic() sdk.Error

ValidateBasic Implements Msg.

type ObjHtlc

type ObjHtlc struct {
	Amount         sdk.Coin
	Hash           string
	Locktime       int64
	RedeemAddress  sdk.AccAddress
	TimeoutAddress sdk.AccAddress
	Status         Status
	BlockCreatedAt int64
}

ObjHtlc is persisted in the KV store.

type Status

type Status uint8

Status represents the status of an HTLC.

const (
	HtlcCreated  Status = 1
	HtlcRedeemed Status = 2
	HtlcFailed   Status = 3
)

HTLC status enum.

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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