/** * Contract module for managing Dragonchain smart contracts */ import * as fs from 'fs'; import { DragonchainClient } from './client'; import { ContentType, SmartContractCreateRequest, SmartContractUpdateRequest, SmartContract, ListResponse, SuccessResponse, } from './types'; export class ContractClient { private client: DragonchainClient; constructor(client: DragonchainClient) { this.client = client; } /** * Creates a new smart contract */ async create(request: SmartContractCreateRequest): Promise { return this.client.post('/api/v1/contract', ContentType.JSON, request); } /** * Gets a smart contract by ID */ async get(contractId: string): Promise { return this.client.get(`/api/v1/contract/${contractId}`); } /** * Lists all smart contracts */ async list(): Promise { return this.client.get('/api/v1/contract'); } /** * Updates a smart contract */ async update(contractId: string, request: SmartContractUpdateRequest): Promise { return this.client.put( `/api/v1/contract/${contractId}`, ContentType.JSON, request ); } /** * Uploads smart contract code */ async upload(contractId: string, filePath: string): Promise { const fileContent = fs.readFileSync(filePath); return this.client.put( `/api/v1/contract/${contractId}/upload`, ContentType.OCTET_STREAM, fileContent ); } /** * Deletes a smart contract */ async delete(contractId: string): Promise { return this.client.delete(`/api/v1/contract/${contractId}`); } }