Skip to content
This repository has been archived by the owner on Jun 4, 2018. It is now read-only.

Add vote preference stakepool integration. #241

Merged
merged 1 commit into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright (c) 2016 The btcsuite developers
Copyright (c) 2016 The Decred developers
Copyright (c) 2016-2017 The Decred developers

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
26 changes: 26 additions & 0 deletions Paymetheus.Decred/Agenda.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2017 The Decred developers
// Licensed under the ISC license. See LICENSE file in the project root for full license information.

using System;

namespace Paymetheus.Decred
{
public sealed class Agenda
{
public sealed class Choice
{
public string ID { get; set; }
public string Description { get; set; }
public ushort Bits { get; set; }
public bool IsAbstain { get; set; }
public bool IsNo { get; set; }
}

public string ID { get; set; }
public string Description { get; set; }
public ushort Mask { get; set; }
public Choice[] Choices { get; set; }
public DateTimeOffset StartTime { get; set; }
public DateTimeOffset ExpireTime { get; set; }
}
}
1 change: 1 addition & 0 deletions Paymetheus.Decred/Paymetheus.Decred.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Agenda.cs" />
<Compile Include="Amount.cs" />
<Compile Include="Blake256.cs" />
<Compile Include="BlockChain.cs" />
Expand Down
8,103 changes: 6,946 additions & 1,157 deletions Paymetheus.Rpc/Api.cs

Large diffs are not rendered by default.

766 changes: 766 additions & 0 deletions Paymetheus.Rpc/ApiGrpc.cs

Large diffs are not rendered by default.

45 changes: 43 additions & 2 deletions Paymetheus.Rpc/WalletClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2016 The btcsuite developers
// Copyright (c) 2016 The Decred developers
// Copyright (c) 2016-2017 The Decred developers
// Licensed under the ISC license. See LICENSE file in the project root for full license information.

using Google.Protobuf;
Expand All @@ -21,7 +21,7 @@ namespace Paymetheus.Rpc
{
public sealed class WalletClient : IDisposable
{
private static readonly SemanticVersion RequiredRpcServerVersion = new SemanticVersion(4, 4, 1);
private static readonly SemanticVersion RequiredRpcServerVersion = new SemanticVersion(4, 9, 0);

public static void Initialize()
{
Expand Down Expand Up @@ -478,6 +478,47 @@ public async Task RescanFromBlockHeightAsync(int beginHeight, Action<int> progre
}
}

public async Task<TupleValue<uint, Agenda[]>> AgendasAsync()
{
var client = new AgendaService.AgendaServiceClient(_channel);
var request = new AgendasRequest();
var response = await client.AgendasAsync(request, cancellationToken: _tokenSource.Token);
var agendas = response.Agendas.Select(a => new Agenda
{
ID = a.Id,
Description = a.Description,
Choices = a.Choices.Select(c => new Agenda.Choice
{
ID = c.Id,
Description = c.Description,
Bits = (ushort)c.Bits,
IsAbstain = c.IsAbstain,
IsNo = c.IsNo,
}).ToArray(),
Mask = (ushort)a.Mask,
StartTime = DateTimeOffsetExtras.FromUnixTimeSeconds(a.StartTime),
ExpireTime = DateTimeOffsetExtras.FromUnixTimeSeconds(a.ExpireTime),
}).ToArray();
return TupleValue.Create(response.Version, agendas);
}

public async Task<TupleValue<string, string>[]> VoteChoicesAsync()
{
var client = new VotingService.VotingServiceClient(_channel);
var request = new VoteChoicesRequest();
var response = await client.VoteChoicesAsync(request, cancellationToken: _tokenSource.Token);
return response.Choices.Select(c => TupleValue.Create(c.AgendaId, c.ChoiceId)).ToArray();
}

public async Task<ushort> SetVoteChoicesAsync(TupleValue<string, string>[] choices)
{
var client = new VotingService.VotingServiceClient(_channel);
var request = new SetVoteChoicesRequest();
request.Choices.AddRange(choices.Select(c => new SetVoteChoicesRequest.Types.Choice { AgendaId = c.Item1, ChoiceId = c.Item2 }));
var response = await client.SetVoteChoicesAsync(request, cancellationToken: _tokenSource.Token);
return (ushort)response.Votebits;
}

/// <summary>
/// Begins synchronization of the client with the remote wallet process.
/// A delegate must be passed to be connected to the wallet's ChangesProcessed event to avoid
Expand Down
219 changes: 219 additions & 0 deletions Paymetheus.Rpc/protos/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ service WalletService {
rpc ImportPrivateKey (ImportPrivateKeyRequest) returns (ImportPrivateKeyResponse);
rpc ImportScript(ImportScriptRequest) returns (ImportScriptResponse);
rpc FundTransaction (FundTransactionRequest) returns (FundTransactionResponse);
rpc ConstructTransaction (ConstructTransactionRequest) returns (ConstructTransactionResponse);
rpc SignTransaction (SignTransactionRequest) returns (SignTransactionResponse);
rpc PublishTransaction (PublishTransactionRequest) returns (PublishTransactionResponse);
rpc PurchaseTickets(PurchaseTicketsRequest) returns (PurchaseTicketsResponse);
Expand All @@ -58,6 +59,35 @@ service WalletLoaderService {
rpc FetchHeaders(FetchHeadersRequest) returns (FetchHeadersResponse);
}

service TicketBuyerService {
rpc StartAutoBuyer (StartAutoBuyerRequest) returns (StartAutoBuyerResponse);
rpc StopAutoBuyer (StopAutoBuyerRequest) returns (StopAutoBuyerResponse);
rpc TicketBuyerConfig (TicketBuyerConfigRequest) returns (TicketBuyerConfigResponse);
rpc SetAccount (SetAccountRequest) returns (SetAccountResponse);
rpc SetBalanceToMaintain (SetBalanceToMaintainRequest) returns (SetBalanceToMaintainResponse);
rpc SetMaxFee (SetMaxFeeRequest) returns (SetMaxFeeResponse);
rpc SetMaxPriceRelative (SetMaxPriceRelativeRequest) returns (SetMaxPriceRelativeResponse);
rpc SetMaxPriceAbsolute (SetMaxPriceAbsoluteRequest) returns (SetMaxPriceAbsoluteResponse);
rpc SetVotingAddress (SetVotingAddressRequest) returns (SetVotingAddressResponse);
rpc SetPoolAddress (SetPoolAddressRequest) returns (SetPoolAddressResponse);
rpc SetPoolFees (SetPoolFeesRequest) returns (SetPoolFeesResponse);
rpc SetMaxPerBlock (SetMaxPerBlockRequest) returns (SetMaxPerBlockResponse);
}

service SeedService {
rpc GenerateRandomSeed (GenerateRandomSeedRequest) returns (GenerateRandomSeedResponse);
rpc DecodeSeed (DecodeSeedRequest) returns (DecodeSeedResponse);
}

service AgendaService {
rpc Agendas (AgendasRequest) returns (AgendasResponse);
}

service VotingService {
rpc VoteChoices (VoteChoicesRequest) returns (VoteChoicesResponse);
rpc SetVoteChoices (SetVoteChoicesRequest) returns (SetVoteChoicesResponse);
}

message TransactionDetails {
message Input {
uint32 index = 1;
Expand All @@ -68,13 +98,23 @@ message TransactionDetails {
uint32 index = 1;
uint32 account = 2;
bool internal = 3;
int64 amount = 4;
string address = 5;
bytes output_script = 6;
}
bytes hash = 1;
bytes transaction = 2;
repeated Input debits = 3;
repeated Output credits = 4;
int64 fee = 5;
int64 timestamp = 6; // May be earlier than a block timestamp, but never later.
enum TransactionType {
REGULAR = 0;
TICKET_PURCHASE = 1;
VOTE = 2;
REVOCATION = 3;
}
TransactionType transaction_type = 7;
}

message BlockDetails {
Expand Down Expand Up @@ -268,6 +308,35 @@ message FundTransactionResponse {
bytes change_pk_script = 3;
}

message ConstructTransactionRequest {
message OutputDestination {
string address = 1;

bytes script = 2;
uint32 script_version = 3;
}
message Output {
OutputDestination destination = 1;
int64 amount = 2;
}
enum OutputSelectionAlgorithm {
UNSPECIFIED = 0;
ALL = 1;
}
uint32 source_account = 1;
int32 required_confirmations = 2;
int32 fee_per_kb = 3;
OutputSelectionAlgorithm output_selection_algorithm = 4;
repeated Output non_change_outputs = 5;
OutputDestination change_destination = 6;
}
message ConstructTransactionResponse {
bytes unsigned_transaction = 1;
int64 total_previous_output_amount = 2;
int64 total_output_amount = 3;
uint32 estimated_signed_size = 4;
}

message SignTransactionRequest {
bytes passphrase = 1;

Expand Down Expand Up @@ -402,4 +471,154 @@ message FetchHeadersResponse {
uint32 fetched_headers_count = 1;
bytes first_new_block_hash = 2;
int32 first_new_block_height = 3;
bytes main_chain_tip_block_hash = 4;
int32 main_chain_tip_block_height = 5;
}

message GenerateRandomSeedRequest {
uint32 seed_length = 1;
}
message GenerateRandomSeedResponse {
bytes seed_bytes = 1;
string seed_hex = 2;
string seed_mnemonic = 3;
}

message DecodeSeedRequest {
string user_input = 1;
}
message DecodeSeedResponse {
bytes decoded_seed = 1;
}

message StartAutoBuyerRequest {
bytes passphrase = 1;
uint32 account = 2;
int64 balance_to_maintain = 3;
int64 max_fee_per_kb = 4;
double max_price_relative = 5;
int64 max_price_absolute = 6;
string voting_address = 7;
string pool_address = 8;
double pool_fees = 9;
int64 max_per_block = 10;
}
message StartAutoBuyerResponse {}

message StopAutoBuyerRequest {}
message StopAutoBuyerResponse {}
message TicketBuyerConfigRequest{
}

message TicketBuyerConfigResponse{
uint32 account = 1;
string avg_price_mode = 2;
int64 avg_priceVWAP_delta = 3;
int64 balance_to_maintain = 4;
int64 blocks_to_avg = 5;
bool dont_wait_for_tickets = 6;
int64 expiry_delta = 7;
string fee_source = 8;
double fee_target_scaling = 9;
int64 min_fee = 10;
int64 max_fee = 12;
int64 max_per_block = 13;
int64 max_price_absolute = 14;
double max_price_relative = 15;
int64 max_in_mempool = 17;
string pool_address = 18;
double pool_fees = 19;
bool spread_ticket_purchases = 20;
string voting_address = 21;
int64 tx_fee = 22;
}

message SetAccountRequest{
uint32 account = 1;
}
message SetAccountResponse{}

message SetBalanceToMaintainRequest{
int64 balance_to_maintain = 1;
}
message SetBalanceToMaintainResponse{}

message SetMaxFeeRequest{
int64 max_fee_per_kb = 1;
}
message SetMaxFeeResponse{}

message SetMaxPriceRelativeRequest{
double max_price_relative = 1;
}
message SetMaxPriceRelativeResponse{}

message SetMaxPriceAbsoluteRequest{
int64 max_price_absolute = 1;
}
message SetMaxPriceAbsoluteResponse{}

message SetVotingAddressRequest{
string voting_address = 1;
}
message SetVotingAddressResponse{}

message SetPoolAddressRequest{
string pool_address = 1;
}
message SetPoolAddressResponse{}

message SetPoolFeesRequest{
double pool_fees = 1;
}
message SetPoolFeesResponse{}

message SetMaxPerBlockRequest{
int64 max_per_block = 1;
}
message SetMaxPerBlockResponse{}

message AgendasRequest {}
message AgendasResponse {
message Agenda {
string id = 1;
string description = 2;
uint32 mask = 3;
repeated Choice choices = 4;
int64 start_time = 5;
int64 expire_time = 6;
}
message Choice {
string id = 1;
string description = 2;
uint32 bits = 3;
bool is_abstain = 4;
bool is_no = 5;
}
uint32 version = 1;
repeated Agenda agendas = 2;
}

message VoteChoicesRequest {}
message VoteChoicesResponse {
message Choice {
string agenda_id = 1;
string agenda_description = 2;
string choice_id = 3;
string choice_description = 4;
}
uint32 version = 1;
repeated Choice choices = 2;
uint32 votebits = 3;
}

message SetVoteChoicesRequest {
message Choice {
string agenda_id = 1;
string choice_id = 2;
}
repeated Choice choices = 1;
}
message SetVoteChoicesResponse {
uint32 votebits = 1;
}
Loading