Skip to content

Commit

Permalink
add get producers list, add APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
noypi committed Apr 3, 2019
1 parent 1b48e92 commit f19ff63
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
35 changes: 35 additions & 0 deletions IOST.Test/ApiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using IOSTSdk;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;

namespace IOSTSdk.Test
{
[TestClass]
public class ApiTests
{
[TestInitialize]
public void Initialize()
{

}

[TestMethod]
public async Task TestGetProducers()
{
var client = Client.NewJapan();
var iost = new IOST(client);

var producers = await iost.GetProducers256();
Assert.IsTrue(0 < producers.Count);

foreach (var s in producers)
{
Debug.WriteLine(s);
}
}
}
}
12 changes: 12 additions & 0 deletions IOST/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ public Task<GetContractStorageResponse> GetContractStorage(GetContractStorageReq
.ResponseAsync;
}

public Task<GetContractStorageFieldsResponse> GetContractStorageFields(GetContractStorageFieldsRequest request)
{
return _asc.GetContractStorageFields(request, new CallOptions { })
.ResponseAsync;
}

public Task<GetProducerVoteInfoResponse> GetProducerVoteInfo(GetProducerVoteInfoRequest request)
{
return _asc.GetProducerVoteInfo(request, new CallOptions { })
.ResponseAsync;
}

public Task<SendTransactionResponse> SendTransaction(TransactionRequest request)
{
return _asc.SendTransaction(request, new CallOptions { })
Expand Down
18 changes: 18 additions & 0 deletions IOST/IOST.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace IOSTSdk
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using IOSTSdk.Crypto;

Expand Down Expand Up @@ -73,5 +74,22 @@ public KeyPair GenerateNewKeyPair()
{
return SodiumEd25519.NewKeyPair();
}

/// <summary>
/// Gets at most 256 producers
/// </summary>
/// <returns></returns>
public Task<IList<string>> GetProducers256()
{
return _client.GetContractStorageFields(new Rpcpb.GetContractStorageFieldsRequest()
{
ByLongestChain = true,
Key = "producerTable",
Id = Contract.System.VoteProducer.Cid
}).ContinueWith<IList<string>>(t =>
{
return t.Result.Fields;
});
}
}
}
78 changes: 78 additions & 0 deletions IOST/rpcpb/ApiServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ private static readonly
"GetChainInfo",
__Marshaller_EmptyRequest(),
__Marshaller_ChainInfoResponse());

private static readonly
Func<Method<EmptyRequest, RAMInfoResponse>> __Method_GetRAMInfo = () => new Method<EmptyRequest, RAMInfoResponse>(
MethodType.Unary,
"rpcpb.ApiService",
"GetRAMInfo",
__Marshaller_EmptyRequest(),
__Marshaller_RAMInfoResponse());
private static readonly
Func<Method<EmptyRequest, GasRatioResponse>> __Method_GetGasRatio = () => new Method<EmptyRequest, GasRatioResponse>(
MethodType.Unary,
"rpcpb.ApiService",
"GetGasRatio",
__Marshaller_EmptyRequest(),
__Marshaller_GasRatioResponse());
private static readonly
Func<Method<TxHashRequest, TransactionResponse>> __Method_GetTxByHash = () => new Method<TxHashRequest, TransactionResponse>(
MethodType.Unary,
Expand Down Expand Up @@ -80,6 +95,21 @@ private static readonly
"GetContractStorage",
__Marshaller_GetContractStorageRequest(),
__Marshaller_GetContractStorageResponse());
private static readonly
Func<Method<GetContractStorageFieldsRequest, GetContractStorageFieldsResponse>> __Method_GetContractStorageFields = () => new Method<GetContractStorageFieldsRequest, GetContractStorageFieldsResponse>(
MethodType.Unary,
"rpcpb.ApiService",
"GetContractStorageFields",
__Marshaller_GetContractStorageFieldsRequest(),
__Marshaller_GetContractStorageFieldsResponse());
private static readonly
Func<Method<GetProducerVoteInfoRequest, GetProducerVoteInfoResponse>> __Method_GetProducerVoteInfo = () => new Method<GetProducerVoteInfoRequest, GetProducerVoteInfoResponse>(
MethodType.Unary,
"rpcpb.ApiService",
"GetProducerVoteInfo",
__Marshaller_GetProducerVoteInfoRequest(),
__Marshaller_GetProducerVoteInfoResponse());

private static readonly
Func<Method<TransactionRequest, SendTransactionResponse>> __Method_SendTransaction = () => new Method<TransactionRequest, SendTransactionResponse>(
MethodType.Unary,
Expand Down Expand Up @@ -130,6 +160,15 @@ private static readonly
Func<Marshaller<GetContractStorageRequest>> __Marshaller_GetContractStorageRequest = () => Marshallers.Create<GetContractStorageRequest>(
arg => MessageExtensions.ToByteArray(arg),
GetContractStorageRequest.Parser.ParseFrom);
private static readonly
Func<Marshaller<GetContractStorageFieldsRequest>> __Marshaller_GetContractStorageFieldsRequest = () => Marshallers.Create<GetContractStorageFieldsRequest>(
arg => MessageExtensions.ToByteArray(arg),
GetContractStorageFieldsRequest.Parser.ParseFrom);
private static readonly
Func<Marshaller<GetProducerVoteInfoRequest>> __Marshaller_GetProducerVoteInfoRequest = () => Marshallers.Create<GetProducerVoteInfoRequest>(
arg => MessageExtensions.ToByteArray(arg),
GetProducerVoteInfoRequest.Parser.ParseFrom);

private static readonly
Func<Marshaller<TransactionRequest>> __Marshaller_TransactionRequest = () => Marshallers.Create<TransactionRequest>(
arg => MessageExtensions.ToByteArray(arg),
Expand All @@ -145,6 +184,15 @@ private static readonly
arg => MessageExtensions.ToByteArray(arg),
ChainInfoResponse.Parser.ParseFrom);
private static readonly
Func<Marshaller<RAMInfoResponse>> __Marshaller_RAMInfoResponse = () => Marshallers.Create<RAMInfoResponse>(
arg => MessageExtensions.ToByteArray(arg),
RAMInfoResponse.Parser.ParseFrom);

private static readonly
Func<Marshaller<GasRatioResponse>> __Marshaller_GasRatioResponse = () => Marshallers.Create<GasRatioResponse>(
arg => MessageExtensions.ToByteArray(arg),
GasRatioResponse.Parser.ParseFrom);
private static readonly
Func<Marshaller<TransactionResponse>> __Marshaller_TransactionResponse = () => Marshallers.Create<TransactionResponse>(
arg => MessageExtensions.ToByteArray(arg),
TransactionResponse.Parser.ParseFrom);
Expand Down Expand Up @@ -172,6 +220,16 @@ private static readonly
Func<Marshaller<GetContractStorageResponse>> __Marshaller_GetContractStorageResponse = () => Marshallers.Create<GetContractStorageResponse>(
arg => MessageExtensions.ToByteArray(arg),
GetContractStorageResponse.Parser.ParseFrom);
private static readonly
Func<Marshaller<GetContractStorageFieldsResponse>> __Marshaller_GetContractStorageFieldsResponse = () => Marshallers.Create<GetContractStorageFieldsResponse>(
arg => MessageExtensions.ToByteArray(arg),
GetContractStorageFieldsResponse.Parser.ParseFrom);

private static readonly
Func<Marshaller<GetProducerVoteInfoResponse>> __Marshaller_GetProducerVoteInfoResponse = () => Marshallers.Create<GetProducerVoteInfoResponse>(
arg => MessageExtensions.ToByteArray(arg),
GetProducerVoteInfoResponse.Parser.ParseFrom);

private static readonly
Func<Marshaller<SendTransactionResponse>> __Marshaller_SendTransactionResponse = () => Marshallers.Create<SendTransactionResponse>(
arg => MessageExtensions.ToByteArray(arg),
Expand Down Expand Up @@ -215,6 +273,16 @@ public AsyncUnaryCall<ChainInfoResponse> GetChainInfo(CallOptions options)
return CallInvoker.AsyncUnaryCall<EmptyRequest, ChainInfoResponse>(__Method_GetChainInfo(), _host, options, new EmptyRequest());
}

public AsyncUnaryCall<RAMInfoResponse> GetRamInfo(CallOptions options)
{
return CallInvoker.AsyncUnaryCall<EmptyRequest, RAMInfoResponse>(__Method_GetRAMInfo(), _host, options, new EmptyRequest());
}

public AsyncUnaryCall<GasRatioResponse> GetGasRatio(CallOptions options)
{
return CallInvoker.AsyncUnaryCall<EmptyRequest, GasRatioResponse>(__Method_GetGasRatio(), _host, options, new EmptyRequest());
}

public AsyncUnaryCall<TransactionResponse> GetTxByHash(TxHashRequest request, CallOptions options)
{
return CallInvoker.AsyncUnaryCall<TxHashRequest, TransactionResponse>(__Method_GetTxByHash(), _host, options, request);
Expand Down Expand Up @@ -255,6 +323,16 @@ public AsyncUnaryCall<GetContractStorageResponse> GetContractStorage(GetContract
return CallInvoker.AsyncUnaryCall<GetContractStorageRequest, GetContractStorageResponse>(__Method_GetContractStorage(), _host, options, request);
}

public AsyncUnaryCall<GetContractStorageFieldsResponse> GetContractStorageFields(GetContractStorageFieldsRequest request, CallOptions options)
{
return CallInvoker.AsyncUnaryCall<GetContractStorageFieldsRequest, GetContractStorageFieldsResponse>(__Method_GetContractStorageFields(), _host, options, request);
}

public AsyncUnaryCall<GetProducerVoteInfoResponse> GetProducerVoteInfo(GetProducerVoteInfoRequest request, CallOptions options)
{
return CallInvoker.AsyncUnaryCall<GetProducerVoteInfoRequest, GetProducerVoteInfoResponse>(__Method_GetProducerVoteInfo(), _host, options, request);
}

public AsyncUnaryCall<SendTransactionResponse> SendTransaction(TransactionRequest request, CallOptions options)
{
return CallInvoker.AsyncUnaryCall<TransactionRequest, SendTransactionResponse>(__Method_SendTransaction(), _host, options, request);
Expand Down

0 comments on commit f19ff63

Please sign in to comment.