Skip to content

[Node] Add ipfsQuote nodeCall endpoint #585

Description

@tcsenpai

Repository: Node (this repo)

Implement ipfsQuote nodeCall to return cost estimates without transaction.

Files to create/modify

  • src/libs/network/routines/nodecalls/ipfs/ipfsQuote.ts - New file
  • src/libs/network/routines/nodecalls/ipfs/index.ts - Export new handler

Implementation

export async function ipfsQuote(args: { fileSize: number, operation: 'add' | 'pin' }): Promise<RPCResponse> {
    const { fileSize, operation } = args
    const sender = // get from request context
    const isGenesis = await isGenesisAccount(sender)
    const usedFreeBytes = await getUsedFreeBytes(sender)
    
    const costBreakdown = calculatePinCost(fileSize, isGenesis, usedFreeBytes)
    
    return {
        result: 200,
        response: {
            cost_dem: costBreakdown.finalCost,
            file_size_bytes: fileSize,
            is_genesis_rate: isGenesis,
            breakdown: costBreakdown
        },
        require_reply: false,
        extra: null
    }
}

Register in manageNodeCall.ts

Add case for "ipfsQuote"

Verification

  • bun run lint:fix must pass
  • bun run type-check must pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions