UNPKG

@fairmint/canton-node-sdk

Version:
44 lines 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CreateBuyTrafficRequest = void 0; const core_1 = require("../../../../../../core"); const operations_1 = require("../../../../schemas/operations"); /** * @description Create a new buy traffic request to purchase traffic from another validator * @example * ```typescript * const request = await client.createBuyTrafficRequest({ * traffic_amount: 1000 * }); * console.log(`Request created: ${request.request_contract_id}`); * ``` */ 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.domain_id; if (!domain_id) { throw new Error('Unable to determine domain_id from amulet rules'); } // Get receiving validator party ID from client configuration const 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