API

This section elaborates on the transaction message handler methods being exposed by the Market module.

Add

When a transaction of adding a market is processed, the following actions take place:

  • The creator address and the ticket format are validated in the market module.

  • The OVM module is invoked to retrieve the ticket's contents and validate it.

  • If the ticket is valid, it is checked if the market already exists.

  • If the market does not already exist, a new market is created with the provided data and added to the market module's KVStore. The market is created as shown below:

market := types.NewMarket(
    addPayload.UID,
    msg.Creator,
    addPayload.StartTS,
    addPayload.EndTS,
    addPayload.Odds,
    addPayload.Meta,
    addPayload.UID,
    addPayload.SrContributionForHouse,
    addPayload.Status,
)

RPC

The RPC for adding a market is as follows:

rpc Add(MsgAdd) returns (MsgAddResponse);

Request Message

The request message for Add is MsgAdd. The proto for the request message is as follows:

// MsgAddMarket is the message type for adding the market into the
// state.
message MsgAdd {
  // creator is the address of the creator account of the market.
  string creator = 1;
  // ticket is the jwt ticket data.
  string ticket = 2;
}

Add ticket payload

// MarketAddTicketPayload indicates data of add market ticket
message MarketAddTicketPayload {
  // uid is the universal unique identifier of the market.
  string uid = 1 [
    (gogoproto.customname) = "UID",
    (gogoproto.jsontag) = "uid",
    json_name = "uid"
  ];
  // start_ts is the start timestamp of the market.
  uint64 start_ts = 2 [
    (gogoproto.customname) = "StartTS",
    (gogoproto.jsontag) = "start_ts",
    json_name = "start_ts"
  ];
  // end_ts is the end timestamp of the market.
  uint64 end_ts = 3 [
    (gogoproto.customname) = "EndTS",
    (gogoproto.jsontag) = "end_ts",
    json_name = "end_ts"
  ];
  // odds is the list of odds of the market.
  repeated Odds odds = 4;

  // status is the current status of the market.
  MarketStatus status = 5;

  // creator is the address of the creator of the market.
  string creator = 6;

  // min_bet_amount is the minimum allowed bet amount for a market.
  string min_bet_amount = 7 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false
  ];

  // bet_fee is the fee that the bettor needs to pay to bet on the market.
  string bet_fee = 8 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false
  ];

  // meta contains human-readable metadata of the market.
  string meta = 9;
}

Response Message

The response message of the MsgAdd is MsgAddResponse. The proto for the response message is as follows:

// MsgAddMarketResponse response for adding market.
message MsgAddResponse {
  // error contains an error if adding a market faces any issues.
  string error = 1 [ (gogoproto.nullable) = true ];
  // data is the data of market.
  Market data = 2 [ (gogoproto.nullable) = true ];
}

Resolve

When a transaction of resolving a market is processed, the following actions take place:

  • The creator address and the ticket format are validated in the market module.

  • The OVM module is invoked to retrieve the ticket's contents and validate it.

  • If the ticket is valid, it is checked if the market already exists.

  • If the market already exists, the market status should,types.MarketStatus_STATUS_ACTIVEso that the market can be resolved now.

  • Then the market is resolved as per the provided odds value and status and stored in the KVStore of the market module.

RPC

The RPC for resolving a market is as follows:

rpc Resolve(MsgResolve) returns (MsgResolveResponse);

Request Message

The request message for Resolve is MsgResolve. The proto for the request message is as follows:

// MsgResolveMarket is the message type for resolving a market.
message MsgResolve {
  // creator is the address of the creator account of the market.
  string creator = 1;
  // ticket is the jwt ticket data.
  string ticket = 2;
}

Resolve ticket payload

The proto of the payload accepted for the resolution of the market is as follows:

// MarketResolutionTicketPayload indicates data of the
// resolution of the market ticket.
message MarketResolutionTicketPayload {
  // uid is the universal unique identifier of the market.
  string uid = 1 [
    (gogoproto.customname) = "UID",
    (gogoproto.jsontag) = "uid",
    json_name = "uid"
  ];

  // resolution_ts is the resolution timestamp of the market.
  uint64 resolution_ts = 2 [
    (gogoproto.customname) = "ResolutionTS",
    (gogoproto.jsontag) = "resolution_ts",
    json_name = "resolution_ts"
  ];

  // winner_odds_uids is the universal unique identifier list of the winner
  // odds.
  repeated string winner_odds_uids = 3 [
    (gogoproto.customname) = "WinnerOddsUIDs",
    (gogoproto.jsontag) = "winner_odds_uids",
    json_name = "winner_odds_uids"
  ];

  // status is the status of the resolution.
  MarketStatus status = 4;
}

Response Message

The response message of the MsgResolve is MsgResolveResponse. The proto for the response message is as follows:

// MsgResolveMarketResponse response for resolving a market.
message MsgResolveResponse {
  // error contains an error if resolving a market faces any issues.
  string error = 1 [ (gogoproto.nullable) = true ];
  // data is the data of market.
  Market data = 2 [ (gogoproto.nullable) = true ];
}

Update

When a transaction of updating a market is processed, the following actions take place:

  • The creator address and the ticket format are validated in the market module.

  • The OVM module is invoked to retrieve the ticket's contents and validate it.

  • If the ticket is valid, it is checked if the market already exists.

  • If the market already exists, the market status should be types.MarketStatus_STATUS_Active or types.MarketStatus_STATUS_Inactive

  • Then the market is updated as per the provided data and stored in the KVStore of the market module again in the following way:

// replace current data with payload values
currentData.StartTS = updatePayload.StartTS
currentData.EndTS = updatePayload.EndTS
currentData.Status = updatePayload.Status

RPC

The RPC for updating a market is as follows:

// Update defines a method to update a market.
rpc Update(MsgUpdate) returns (MsgUpdateResponse);

Request Message

The request message for Update is MsgUpdate. The proto for the request message is as follows:

// MsgUpdate is the message type for updating market data.
// in the state
message MsgUpdate {
  // creator is the address of the creator account of the market.
  string creator = 1;
  // ticket is the jwt ticket data.
  string ticket = 2;
}

Update ticket payload

The proto of the payload accepted for updating the market is as follows:

// MarketUpdateTicketPayload9 indicates data of the market update ticket
message MarketUpdateTicketPayload {
  // uid is the uuid of the market
  string uid = 1 [
    (gogoproto.customname) = "UID",
    (gogoproto.jsontag) = "uid",
    json_name = "uid"
  ];
  // start_ts is the start timestamp of the market
  uint64 start_ts = 2 [
    (gogoproto.customname) = "StartTS",
    (gogoproto.jsontag) = "start_ts",
    json_name = "start_ts"
  ];
  // end_ts is the end timestamp of the market
  uint64 end_ts = 3 [
    (gogoproto.customname) = "EndTS",
    (gogoproto.jsontag) = "end_ts",
    json_name = "end_ts"
  ];
  // min_bet_amount is the minimum allowed bet amount for a market.
  string min_bet_amount = 4 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false
  ];

  // bet_fee is the fee that the bettor needs to pay to bet on the market.
  string bet_fee = 5 [
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
    (gogoproto.nullable) = false
  ];

  // status is the status of the resolution.
  MarketStatus status = 6;
}

Response Message

The response message of the Update is MsgUpdateResponse. The proto for the response message is as follows:

// MsgUpdateMarketResponse response for updating a market.
message MsgUpdateResponse {
  // error contains an error if updating a market faces any issues.
  string error = 1 [ (gogoproto.nullable) = true ];
  // data is the data of market
  Market data = 2 [ (gogoproto.nullable) = true ];
}38

Last updated