Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Adding RPC Endpoints for viewing available gas and claiming gas #1

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions neo-cli/Network/RPC/RpcServerWithWallet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Neo.Core;
using Neo.IO.Json;
using Neo.Wallets;
using Neo.Shell;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -29,6 +30,17 @@ protected override JObject Process(string method, JArray _params)
json["confirmed"] = coins.Where(p => p.State.HasFlag(CoinState.Confirmed)).Sum(p => p.Output.Value).ToString();
return json;
}
case "getunclaimedgas":
if (Program.Wallet == null)
throw new RpcException(-400, "Access denied.");
else
{
Coins coins = new Coins(Program.Wallet, LocalNode);
JObject json = new JObject();
json["unavailable"] = coins.UnavailableBonus().ToString();
json["available"] = coins.AvailableBonus().ToString();
return json;
}
case "sendtoaddress":
if (Program.Wallet == null)
throw new RpcException(-400, "Access denied");
Expand Down Expand Up @@ -78,6 +90,25 @@ protected override JObject Process(string method, JArray _params)
Contract contract = Program.Wallet.GetContracts(key.PublicKeyHash).First(p => p.IsStandard);
return contract.Address;
}

case "claimgas":
if (Program.Wallet == null)
throw new RpcException(-400, "Access denied.");
else
{
Coins coins = new Coins(Program.Wallet, LocalNode);

ClaimTransaction tx = coins.Claim();
if (tx == null)
{
throw new RpcException(-401, "Could not claim gas");
}
else
{
return tx.ToJson();
}
}

case "dumpprivkey":
if (Program.Wallet == null)
throw new RpcException(-400, "Access denied");
Expand Down