GS2-Exchange Script Trigger Reference

Reference for event triggers that call extended scripts

Trigger

exchange

Exchange

Synchronous Execution Script

The script is executed synchronously before the exchange process.

Request
Type Description
namespace Namespace Namespace
rateModel RateModel Exchange Rate Model
userId string User ID performing the exchange
count int Exchanging volume
config Config[] Configuration values applied to transaction variables
Result
Type Required Default Value Limits Description
permit bool
Whether to allow exchange
rateMode string
“float” Rate mode
rate float 1.0 0 ~ 1000 Acquisition quantity rate
logRate LogRate Logarithmic acquisition correction
Implementation Example
-- Request
local namespace = args.namespace
local rateModel = args.rateModel
local userId = args.userId
local count = args.count
local config = args.config

-- Business logic:
local permit = true
local rateMode = ""
local rate = 0
local logRate = nil

-- Result
result = {
  permit=permit,
  rateMode=rateMode,
  rate=rate,
  logRate=logRate
}

Asynchronous Execution Script

The script is executed asynchronously after the exchange process.

Request
Type Description
namespace Namespace Namespace
rateModel RateModel Exchange Rate Model
userId string User ID performing the exchange
count int Exchanging volume
config Config[] Configuration values applied to transaction variables
Implementation Example
-- Request
local namespace = args.namespace
local rateModel = args.rateModel
local userId = args.userId
local count = args.count
local config = args.config

-- Asynchronous scripts typically do not affect the API response.
-- Use for logging, analytics, external notifications, etc.

result = {
}

incrementalExchange

Exchange

Synchronous Execution Script

The script is executed synchronously before the exchange process.

Request
Type Description
namespace Namespace Namespace
rateModel IncrementalRateModel Exchange rate model
userId string User ID performing the exchange
count int Exchanging volume
config Config[] Configuration values applied to transaction variables
Result
Type Required Default Value Limits Description
permit bool
Whether to allow exchange
Implementation Example
-- Request
local namespace = args.namespace
local rateModel = args.rateModel
local userId = args.userId
local count = args.count
local config = args.config

-- Business logic:
local permit = true

-- Result
result = {
  permit=permit
}

Asynchronous Execution Script

The script is executed asynchronously after the exchange process.

Request
Type Description
namespace Namespace Namespace
rateModel IncrementalRateModel Exchange rate model
userId string User ID performing the exchange
count int Exchanging volume
config Config[] Configuration values applied to transaction variables
Implementation Example
-- Request
local namespace = args.namespace
local rateModel = args.rateModel
local userId = args.userId
local count = args.count
local config = args.config

-- Asynchronous scripts typically do not affect the API response.
-- Use for logging, analytics, external notifications, etc.

result = {
}

calculateCost

Cost calculation script for Incremental Cost Exchange Rate

Synchronous Execution Script

The script is executed synchronously before the cost calculation script for incremental cost exchange rate process.

Request
Type Description
namespace Namespace Namespace
incrementalRateModel IncrementalRateModel Incremental Cost Exchange Rate Model
userId string User ID
currentExchangeCount int Current number of exchange counts
quantity int Exchange Quantity
Result
Type Required Default Value Limits Description
costMode string
“num” Cost calculation method
cost long 0 ~ 9223372036854775805 Cost
logCost LogCost Cost calculation result using logarithm
Implementation Example
-- Request
local namespace = args.namespace
local incrementalRateModel = args.incrementalRateModel
local userId = args.userId
local currentExchangeCount = args.currentExchangeCount
local quantity = args.quantity

-- Business logic:
local costMode = ""
local cost = 0
local logCost = nil

-- Result
result = {
  costMode=costMode,
  cost=cost,
  logCost=logCost
}

acquireAwait

Exchange Await

Synchronous Execution Script

The script is executed synchronously before the exchange await process.

Request
Type Description
namespace Namespace Namespace
rateModel RateModel Exchange Rate Model
awaitModel Await Exchange Await
Result
Type Required Default Value Limits Description
permit bool
Whether to allow awaiting exchange
Implementation Example
-- Request
local namespace = args.namespace
local rateModel = args.rateModel
local awaitModel = args.awaitModel

-- Business logic:
local permit = true

-- Result
result = {
  permit=permit
}

Asynchronous Execution Script

The script is executed asynchronously after the exchange await process.

Request
Type Description
namespace Namespace Namespace
rateModel RateModel Exchange Rate Model
awaitModel Await Exchange Await
Implementation Example
-- Request
local namespace = args.namespace
local rateModel = args.rateModel
local awaitModel = args.awaitModel

-- Asynchronous scripts typically do not affect the API response.
-- Use for logging, analytics, external notifications, etc.

result = {
}