@fairmint/canton-node-sdk
Version:
Canton Node SDK
51 lines • 2.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateBuyTrafficRequest = void 0;
const core_1 = require("../../../../../../core");
const operations_1 = require("../../../../schemas/operations");
/**
* Create a new buy traffic request to purchase traffic from another validator
*
* @example
* ```typescript
* // Purchase traffic for the current validator
* const request = await client.createBuyTrafficRequest({
* traffic_amount: 1000
* });
*
* // Purchase traffic for a different validator
* const request = await client.createBuyTrafficRequest({
* traffic_amount: 1000,
* receiving_validator_party_id: 'validator::party123...'
* });
* ```;
*/
exports.CreateBuyTrafficRequest = (0, core_1.createApiOperation)({
paramsSchema: operations_1.CreateBuyTrafficRequestParamsSchema,
method: 'POST',
buildUrl: (_params, apiUrl) => `${apiUrl}/api/validator/v0/wallet/buy-traffic-requests`,
buildRequestData: async (params, client) => {
// Cast client to ValidatorApiClient to access getAmuletRules
const validatorClient = client;
// Get domain_id from amulet rules
const amuletRules = await validatorClient.getAmuletRules();
const { domain_id } = amuletRules.amulet_rules;
if (!domain_id) {
throw new Error('Unable to determine domain_id from amulet rules');
}
// Get receiving validator party ID from params or client configuration
const receiving_validator_party_id = params.receiving_validator_party_id ?? client.getPartyId();
// Generate a unique tracking ID
const tracking_id = `buy-traffic-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
// Set expiration to 1 hour from now
const expires_at = Date.now() * 1000 + 3600000000; // 1 hour in microseconds
return {
receiving_validator_party_id,
domain_id,
traffic_amount: params.traffic_amount,
tracking_id,
expires_at,
};
},
});
//# sourceMappingURL=create.js.map