micropay

package
v0.5.1-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

MicroPay: a micro payment POC

The package implements hardcoded ISC contract for continuos micro payment protocol.

The final implementation will be in Rust.

Use case

Party P (the provider) provides services to party C (the consumer).

Services are provided in small pieces, permanently, for example every several minutes. Telecom services would be an example. Upon delivery of a piece of services, P expects a payment from C according of the service contract. If C doesn't pay as expected, P may stop providing services. The payment usually very small, normally no more that some thousands of iotas per piece, a micro payment. Due to continuous flow of micro payments and micro services, the parties has limited financial risk.

Due to the confirmation latencies it is not practical to settle each micro payment into the DLT, IOTA Tangle in this case. Therefore, the approach in the MicroPay is for P to collect many payments into a batch and then settle it all into DLT at once: the off-ledger (a.k.a. off-chain, off_tangle) approach.

Requirements/assumptions

  • the off-ledger payments bear risk of not being able to settle them later due to shortage of funds
  • to eliminate that risk the P require a sum from C to be locked at third trusted part, a smart contract. This paymentWarrant (another word?) is used to settle the payments,
  • The contract guarantees settlement of off-ledger payments up to the amount left in the paymentWarrant account.
  • C can top up the paymentWarrant, however it is out of reach for C while the contract is in effect
  • C may announce it stops using the services at any time. P has in closeTimeout must settle all of pending off-ledger payments. It means closing the contract and releasing what has left in paymentWarrant back to C.
  • If P fails to close the contract from its side in closeTimeout, the paymentWarrant it release automatically and claims for payments are not accepted. It means, if not settled in time, the paymenst may be lost for P

Documentation

Index

Constants

View Source
const (
	ParamPublicKey      = "pk"
	ParamPayerAddress   = "pa"
	ParamServiceAddress = "sa"
	ParamPayments       = "m"

	ParamWarrant = "wa"
	ParamRevoked = "re"
	ParamLastOrd = "lo"

	StateVarPublicKeys = "k"

	WarrantRevokePeriod = 1 * time.Hour
)
View Source
const MinimumWarrantBaseTokens = 500

Variables

View Source
var (
	FuncPublicKey      = coreutil.Func("publicKey")
	FuncAddWarrant     = coreutil.Func("addWarrant")
	FuncRevokeWarrant  = coreutil.Func("revokeWarrant")
	FuncCloseWarrant   = coreutil.Func("closeWarrant")
	FuncSettle         = coreutil.Func("settle")
	FuncGetChannelInfo = coreutil.ViewFunc("getWarrantInfo")
)
View Source
var Contract = coreutil.NewContract("micropay", "Micro payment PoC smart contract")

Functions

This section is empty.

Types

type BatchPayment

type BatchPayment struct {
	Payer    iotago.Address
	Provider iotago.Address
	Payments []Payment
}

type Payment

type Payment struct {
	Ord            uint32
	Amount         uint64
	SignatureShort []byte
}

func NewPayment

func NewPayment(ord uint32, amount uint64, targetAddr iotago.Address, payerKeyPair *cryptolib.KeyPair) *Payment

func NewPaymentFromBytes

func NewPaymentFromBytes(data []byte) (*Payment, error)

func (*Payment) Bytes

func (p *Payment) Bytes() []byte

func (*Payment) Read

func (p *Payment) Read(r io.Reader) error

func (*Payment) Write

func (p *Payment) Write(w io.Writer) error

Jump to

Keyboard shortcuts

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