Add API for Plugin Interoperability #7

Open
opened 2025-06-19 20:35:06 +00:00 by saulteafarmer · 0 comments

Add API for Plugin Interoperability

Feature Request

Description

Create a public API that allows other Oxide plugins to interact with the Orangemart blood buying and Bitcoin sending system programmatically. This will enable developers to integrate Lightning Network payments and blood purchases into their own plugins without requiring players to use chat commands.

Motivation

Currently, the only way to interact with the system is through chat commands (/buyblood and //sendblood). Other plugin developers have expressed interest in integrating with our system for features like:

  • Custom shop interfaces that include blood purchases via Lightning
  • Automated Bitcoin payouts based on game events
  • Integration with clan/team systems for group purchases
  • Quest/mission systems that can trigger Bitcoin rewards
  • Tournament plugins that can send prize money directly via Lightning

Proposed API Methods

1. BuyBlood(ulong playerId, int amount)

  • Description: Create a Lightning invoice for blood purchase and handle the payment flow
  • Parameters:
    • playerId: The SteamID of the player
    • amount: Amount of blood items to purchase
  • Returns: Dictionary<string, object> containing:
    • success: bool - Whether invoice was created successfully
    • invoiceId: string - The payment hash for tracking
    • bolt11: string - The Lightning invoice for payment
    • amountSats: int - The amount in satoshis
  • Notes:
    • Creates Lightning invoice via LNbits
    • Monitors payment status
    • Spawns blood items into inventory once paid
    • Respects the same price calculation (amount * pricePerCurrencyUnit)

2. SendBitcoin(ulong playerId, string lightningAddress, int bloodAmount)

  • Description: Send Bitcoin payment using blood from player's inventory
  • Parameters:
    • playerId: The SteamID of the sending player
    • lightningAddress: The Lightning address to send to
    • bloodAmount: Amount of blood items to convert and send
  • Returns: Dictionary<string, object> containing:
    • success: bool - Whether payment was initiated
    • paymentHash: string - The payment hash if successful
    • satsAmount: int - The amount sent in satoshis
    • error: string - Error message if failed
  • Notes:
    • Checks player has enough blood items in inventory
    • Removes blood from inventory
    • Converts to sats (bloodAmount * satsPerCurrencyUnit)
    • Returns blood if payment fails
    • Respects domain whitelist/blacklist settings

3. GetPendingInvoice(string paymentHash)

  • Description: Check the status of a pending invoice
  • Parameters:
    • paymentHash: The payment hash to check
  • Returns: Dictionary<string, object> containing:
    • exists: bool - Whether invoice exists
    • isPaid: bool - Payment status
    • type: string - "Currency", "Vip", or "SendBitcoin"
    • amount: int - Amount in the transaction

4. CancelInvoice(string paymentHash)

  • Description: Cancel a pending invoice and refund if necessary
  • Parameters:
    • paymentHash: The payment hash to cancel
  • Returns: bool - Success/failure
  • Notes:
    • Removes from pending invoices
    • Returns blood if it was a SendBitcoin transaction

Example Usage

// Example from another plugin
[PluginReference]
private Plugin Orangemart;

// Example 1: Create a blood purchase invoice
void CreateBloodPurchase(BasePlayer player, int amount)
{
    if (Orangemart == null)
    {
        PrintError("Orangemart plugin not found!");
        return;
    }

    var result = Orangemart.Call<Dictionary<string, object>>("BuyBlood", player.userID, amount);
    if (result != null && (bool)result["success"])
    {
        string invoice = (string)result["bolt11"];
        string invoiceId = (string)result["invoiceId"];
        int sats = (int)result["amountSats"];
        
        // Display invoice to player or send to Discord
        player.ChatMessage($"Pay {sats} sats to receive {amount} blood");
        player.ChatMessage($"Invoice: {invoice}");
        
        // Track the invoice for your plugin's purposes
        TrackPurchase(player.userID, invoiceId);
    }
}

// Example 2: Send Bitcoin as reward
void SendBitcoinReward(BasePlayer winner, string lightningAddress, int bloodAmount)
{
    var result = Orangemart.Call<Dictionary<string, object>>("SendBitcoin", 
        winner.userID, lightningAddress, bloodAmount);
    
    if (result != null && (bool)result["success"])
    {
        int satsAmount = (int)result["satsAmount"];
        winner.ChatMessage($"Sending {satsAmount} sats to {lightningAddress}...");
    }
    else
    {
        string error = result?["error"]?.ToString() ?? "Unknown error";
        winner.ChatMessage($"Failed to send Bitcoin: {error}");
    }
}

// Example 3: Check payment status
void CheckPaymentStatus(string paymentHash)
{
    var status = Orangemart.Call<Dictionary<string, object>>("GetPendingInvoice", paymentHash);
    if (status != null && (bool)status["exists"])
    {
        bool isPaid = (bool)status["isPaid"];
        if (isPaid)
        {
            // Handle successful payment
        }
    }
}
# Add API for Plugin Interoperability ## Feature Request ### Description Create a public API that allows other Oxide plugins to interact with the Orangemart blood buying and Bitcoin sending system programmatically. This will enable developers to integrate Lightning Network payments and blood purchases into their own plugins without requiring players to use chat commands. ### Motivation Currently, the only way to interact with the system is through chat commands (`/buyblood` and `//sendblood`). Other plugin developers have expressed interest in integrating with our system for features like: - Custom shop interfaces that include blood purchases via Lightning - Automated Bitcoin payouts based on game events - Integration with clan/team systems for group purchases - Quest/mission systems that can trigger Bitcoin rewards - Tournament plugins that can send prize money directly via Lightning ### Proposed API Methods #### 1. `BuyBlood(ulong playerId, int amount)` - **Description**: Create a Lightning invoice for blood purchase and handle the payment flow - **Parameters**: - `playerId`: The SteamID of the player - `amount`: Amount of blood items to purchase - **Returns**: `Dictionary<string, object>` containing: - `success`: bool - Whether invoice was created successfully - `invoiceId`: string - The payment hash for tracking - `bolt11`: string - The Lightning invoice for payment - `amountSats`: int - The amount in satoshis - **Notes**: - Creates Lightning invoice via LNbits - Monitors payment status - Spawns blood items into inventory once paid - Respects the same price calculation (amount * pricePerCurrencyUnit) #### 2. `SendBitcoin(ulong playerId, string lightningAddress, int bloodAmount)` - **Description**: Send Bitcoin payment using blood from player's inventory - **Parameters**: - `playerId`: The SteamID of the sending player - `lightningAddress`: The Lightning address to send to - `bloodAmount`: Amount of blood items to convert and send - **Returns**: `Dictionary<string, object>` containing: - `success`: bool - Whether payment was initiated - `paymentHash`: string - The payment hash if successful - `satsAmount`: int - The amount sent in satoshis - `error`: string - Error message if failed - **Notes**: - Checks player has enough blood items in inventory - Removes blood from inventory - Converts to sats (bloodAmount * satsPerCurrencyUnit) - Returns blood if payment fails - Respects domain whitelist/blacklist settings #### 3. `GetPendingInvoice(string paymentHash)` - **Description**: Check the status of a pending invoice - **Parameters**: - `paymentHash`: The payment hash to check - **Returns**: `Dictionary<string, object>` containing: - `exists`: bool - Whether invoice exists - `isPaid`: bool - Payment status - `type`: string - "Currency", "Vip", or "SendBitcoin" - `amount`: int - Amount in the transaction #### 4. `CancelInvoice(string paymentHash)` - **Description**: Cancel a pending invoice and refund if necessary - **Parameters**: - `paymentHash`: The payment hash to cancel - **Returns**: `bool` - Success/failure - **Notes**: - Removes from pending invoices - Returns blood if it was a SendBitcoin transaction ### Example Usage ```csharp // Example from another plugin [PluginReference] private Plugin Orangemart; // Example 1: Create a blood purchase invoice void CreateBloodPurchase(BasePlayer player, int amount) { if (Orangemart == null) { PrintError("Orangemart plugin not found!"); return; } var result = Orangemart.Call<Dictionary<string, object>>("BuyBlood", player.userID, amount); if (result != null && (bool)result["success"]) { string invoice = (string)result["bolt11"]; string invoiceId = (string)result["invoiceId"]; int sats = (int)result["amountSats"]; // Display invoice to player or send to Discord player.ChatMessage($"Pay {sats} sats to receive {amount} blood"); player.ChatMessage($"Invoice: {invoice}"); // Track the invoice for your plugin's purposes TrackPurchase(player.userID, invoiceId); } } // Example 2: Send Bitcoin as reward void SendBitcoinReward(BasePlayer winner, string lightningAddress, int bloodAmount) { var result = Orangemart.Call<Dictionary<string, object>>("SendBitcoin", winner.userID, lightningAddress, bloodAmount); if (result != null && (bool)result["success"]) { int satsAmount = (int)result["satsAmount"]; winner.ChatMessage($"Sending {satsAmount} sats to {lightningAddress}..."); } else { string error = result?["error"]?.ToString() ?? "Unknown error"; winner.ChatMessage($"Failed to send Bitcoin: {error}"); } } // Example 3: Check payment status void CheckPaymentStatus(string paymentHash) { var status = Orangemart.Call<Dictionary<string, object>>("GetPendingInvoice", paymentHash); if (status != null && (bool)status["exists"]) { bool isPaid = (bool)status["isPaid"]; if (isPaid) { // Handle successful payment } } } ```
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: rustysats/orangemart.cs#7
No description provided.