Entrypoints

Overview

Entrypoint

Short description

addNewExchange

Creates a new exchange in the exchanges map

changeOwner

Changes the owner of the contract

updateExchangeType

Updates an existing escrow type or creates a new one

validateExchange

Updates an existing exchange from the WAITING_FOR_TRANSFER state to WAITING_FOR_TRANSFER

validateSellerTransmission

Updates an existing exchange from the WAITING_FOR_VALIDATION state to VALIDATED

addNewExchange

This entry point initializes a new exchange between a seller and a buyer. It saves in the storage the key information about the exchange such as its id, the addresses of the parties involved (buyer and seller), the detailed amount put into escrow or the type of the escrow.

The validateSellerTransmission entry point can only be called by anyone who starts an exchange and puts funds into escrow.

Parameters
Parameters

Parameter

Type

name

TString

exchange_type

TString

id

TString

price

TMutez

shipping

TMutez

seller

TAddress

Response
Response

The contract storage is updated, adding a new entry to the exchanges map. The balance of the contract is updated with the amount put into escrow by the buyer.

Example of added entry

Key

Buyer

Name

Exchange_type

Last_update

Paid_price

Seller

State

3

tz1...

f63a8...

DOMAIN_NAME

2021-03-29T19:31:35Z

tz1...

WAITING_FOR_TRANSFER

Errors

Error message

Root cause

The type type_name does not exist

The buyer is trying to init an exchange for an escrow type that is not in the escrow_types map.

The amount sent is not enough

The amount the buyer is trying to put into escrow is inferior to the total of the asked price by the buyer + the commission amount + the slashing amount.

The exchange for the item n° id already exists

The buyer is trying to init an exchange for an item that already has an ongoing escrow.

The contract storage is updated, adding a new entry to the exchanges map. The balance of the contract is updated with the amount put into escrow by the buyer.

Example of added entry

changeOwner

This entry point is called to update the address of the owner of the contract.

The validateSellerTransmission entry point can only be called by the owner of the contract.

Parameters
Parameters

Parameter

Type

new_owner

TAddress

Response
Response

Success

The state variable owner in the storage is updated with the new designated owner of the contract.

Errors

Error

Root cause

Only the owner of the contract can designate a new owner

The sender of the transaction is not the owner of the contract

updateExchangeType

Parameters
Parameters

Parameter

Type

exchange_type

TString

commission

TNat

Response
Response

Success

If the exchange type already exists, its related commission is updated with the new commission value.

If the exchange type does not exist, a new entry is added to the exchange_types map.

Example of added entry

Key

Value

DOMAIN_NAME

4

Errors

Error

Root cause

Only the owner of the contract can update the exchange types

The sender of the transaction is not the owner of the contract

validateSellerTransmission

This entry point is called to confirm that the seller has transmitted the goods to the buyer.

The validateSellerTransmission entry point can only be called by the owner of the contract. Only the exchanges awaiting for transmission can be updated.

Parameters
Parameters

Parameter

Type

id

TString

Response
Response

Success

The exchange related to the id given in the parameters is updated. Its state changes fromWAITING_FOR_TRANSFER to WAITING_FOR_VALIDATION

Errors

Message

Root cause

Only the owner of the contract can validate the transmission of the goods

The sender of the transaction is not the owner of the contract

The exchange does not exist

The provided id in the parameters is not found in the exchanges map keys

The exchange is not awaiting transfer

The exchange current state is not equal to

WAITING_FOR_TRANSFER

validateExchange

This entry point updates the exchange as validated and dispatches the escrowed funds to the parties involved in the exchange: the buyer, the seller and the owner of the contract.

The validateExchange entry point can only be called by the buyer of the exchange which id is provided or the owner of the contract. Only the exchanges awaiting for validation can be validated.

Parameters
Parameters

Parameter

Type

id

TString

This entry point initializes a new exchange between a seller and a buyer. It saves in the storage the key information about the exchange such as its id, the addresses of the parties involved (buyer and seller), the detailed amount put into escrow or the type of the escrow.

The validateSellerTransmission entry point can only be called by anyone who starts an exchange and puts funds into escrow.

The contract storage is updated, adding a new entry to the exchanges map. The balance of the contract is updated with the amount put into escrow by the buyer.

Example of added entry

This entry point is called to update the address of the owner of the contract.

The validateSellerTransmission entry point can only be called by the owner of the contract.

The state variable owner in the storage is updated with the new designated owner of the contract.

If the exchange type already exists, its related commission is updated with the new commission value.

If the exchange type does not exist, a new entry is added to the exchange_types map.

Example of added entry

This entry point is called to confirm that the seller has transmitted the goods to the buyer.

The validateSellerTransmission entry point can only be called by the owner of the contract. Only the exchanges awaiting for transmission can be updated.

The exchange related to the id given in the parameters is updated. Its state changes fromWAITING_FOR_TRANSFER to WAITING_FOR_VALIDATION

This entry point updates the exchange as validated and dispatches the escrowed funds to the parties involved in the exchange: the buyer, the seller and the owner of the contract.

The validateExchange entry point can only be called by the buyer of the exchange which id is provided or the owner of the contract. Only the exchanges awaiting for validation can be validated.