Skip to content
Open
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
103 changes: 87 additions & 16 deletions MultiChainLib/Client/MultiChainClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Task<JsonRpcResponse<string>> SendToAddressAsync(string address, string a
{
var theAmount = new Dictionary<string, object>();
theAmount[assetName] = amount;
return this.ExecuteAsync<string>("sendtoaddress", 0, address, theAmount, comment ?? string.Empty,
return this.ExecuteAsync<string>("sendtoaddress", 0, address, theAmount, comment ?? string.Empty,
commentTo ?? string.Empty);
}

Expand All @@ -72,7 +72,7 @@ public Task<JsonRpcResponse<string>> SendWithMetadataFromAsync(string fromAddres
return this.ExecuteAsync<string>("sendwithmetadatafrom", 0, fromAddress, toAddress, theAmount, FormatHex(dataHex));
}

public Task<JsonRpcResponse<string>> SendAssetToAddressAsync(string address, string assetName, decimal quantity,
public Task<JsonRpcResponse<string>> SendAssetToAddressAsync(string address, string assetName, decimal quantity,
int nativeAmount = 0, string comment = null, string commentTo = null)
{
return this.ExecuteAsync<string>("sendassettoaddress", 0, address, assetName, quantity, nativeAmount,
Expand Down Expand Up @@ -176,7 +176,7 @@ public Task<JsonRpcResponse<List<ListPermissionsResponse>>> ListPermissions(Bloc
return this.ExecuteAsync<List<ListPermissionsResponse>>("listpermissions", 0, permissionsAsString);
}

public Task<JsonRpcResponse<string>> IssueAsync(string issueAddress, string assetName, int quantity, decimal units,
public Task<JsonRpcResponse<string>> IssueAsync(string issueAddress, string assetName, int quantity, decimal units,
decimal nativeAmount = 0, string comment = null, string commentTo = null, int startBlock = 0, int endBlock = 0)
{
return this.ExecuteAsync<string>("issue", 0, issueAddress, assetName, quantity, units); /*, nativeAmount, comment,
Expand Down Expand Up @@ -213,7 +213,7 @@ public Task<JsonRpcResponse<string>> RevokeAsync(IEnumerable<string> addresses,
commentTo ?? string.Empty, startBlock, endBlock);*/
}

public Task<JsonRpcResponse<string>> GrantFromAsync(string fromAddress, IEnumerable<string> toAddresses, BlockchainPermissions permissions, decimal nativeAmount = 0M,
public Task<JsonRpcResponse<string>> GrantFromAsync(string fromAddress, IEnumerable<string> toAddresses, BlockchainPermissions permissions, decimal nativeAmount = 0M,
string comment = null, string commentTo = null, int startBlock = 0, int endBlock = 0)
{
var stringifiedAddresses = this.StringifyValues(toAddresses);
Expand Down Expand Up @@ -382,22 +382,32 @@ public Task<JsonRpcResponse<bool>> VerifyChainAsync(CheckBlockType type = CheckB
return this.ExecuteAsync<bool>("verifychain", 0, (int)type, numBlocks);
}

// not implemented -- contact us with specific implementation requirements and we'll implement this...
public Task<JsonRpcResponse<string>> CreateRawTransactionAync()
public Task<JsonRpcResponse<string>> CreateRawTransactionAync(IEnumerable<CreateRawTransactionTxIn> txids = null, IEnumerable<CreateRawTransactionAmount> assets = null)
{
throw new NotImplementedException("This operation has not been implemented.");
string amountstr = string.Empty;
dynamic flexible;
flexible = new System.Dynamic.ExpandoObject();
var dictionary = (IDictionary<string, object>)flexible;
if (assets != null)
{
foreach (var asset in assets)
{
dictionary.Add(asset.Address, asset.StringifyAmount());
}
}
return this.ExecuteAsync<string>("createrawtransaction", 0, txids, dictionary);
}

// not implemented -- contact us with specific implementation requirements and we'll implement this...
public Task<JsonRpcResponse<string>> SendRawTransactionAsync()

public Task<JsonRpcResponse<string>> SendRawTransactionAsync(string hex)
{
throw new NotImplementedException("This operation has not been implemented.");
return this.ExecuteAsync<string>("sendrawtransaction", 0, hex);
}

// not implemented -- contact us with specific implementation requirements and we'll implement this...
public Task<JsonRpcResponse<string>> SignRawTransactionAsync()

public Task<JsonRpcResponse<SignRawTransactionResponse>> SignRawTransactionAsync(string hex)
{
throw new NotImplementedException("This operation has not been implemented.");
return this.ExecuteAsync<SignRawTransactionResponse>("signrawtransaction", 0, hex);
}

public Task<JsonRpcResponse<bool>> PrioritiseTransactionAsync(string txId, decimal priority, int feeSatoshis)
Expand Down Expand Up @@ -515,14 +525,75 @@ public Task<JsonRpcResponse<ListSinceLastBlockResponse>> ListSinceBlockAsync(str
return this.ExecuteAsync<ListSinceLastBlockResponse>("listsinceblock", 0, hash, confirmations, watchOnly);
}

public Task<JsonRpcResponse<CreateRawTransactionTxIn>> PrepareLockUnspent(string address = null, IEnumerable<PrepareLockUnspentAmount> amounts = null, bool _lock = true)
{
//multichain - cli testbc preparelockunspent '{"asset1":100,"asset2":20}'

string amountstr = string.Empty;
dynamic flexible;
flexible = new System.Dynamic.ExpandoObject();
var dictionary = (IDictionary<string, object>)flexible;
if (amounts != null)
{
foreach (var amount in amounts)
{
dictionary.Add(amount.Name, amount.Qty);
}
}
if (address == null)
return this.ExecuteAsync<CreateRawTransactionTxIn>("preparelockunspent", 0, dictionary, _lock);

return this.ExecuteAsync<CreateRawTransactionTxIn>("preparelockunspentfrom", 0, address, dictionary, _lock);
}


public Task<JsonRpcResponse<CreateRawTransactionTxIn>> PrepareLockUnspent(IEnumerable<PrepareLockUnspentAmount> amounts = null, bool _lock = true)
{
//multichain - cli testbc preparelockunspent '{"asset1":100,"asset2":20}'

string amountstr = string.Empty;
dynamic flexible;
flexible = new System.Dynamic.ExpandoObject();
var dictionary = (IDictionary<string, object>)flexible;
if (amounts != null)
{
foreach (var amount in amounts)
{
dictionary.Add(amount.Name, amount.Qty);
}
}

return this.ExecuteAsync<CreateRawTransactionTxIn>("preparelockunspent", 0, dictionary, _lock);
}

public Task<JsonRpcResponse<bool>> LockUnspent(bool unlock, IEnumerable<CreateRawTransactionTxIn> unspentTxs = null)
{


return this.ExecuteAsync<bool>("lockunspent", 0, unlock, unspentTxs);
}

public Task<JsonRpcResponse<List<UnspentResponse>>> ListUnspentAsync(int minConf = 1, int maxConf = 999999, IEnumerable<string> addresses = null)
{
return this.ExecuteAsync<List<UnspentResponse>>("listunspent", 0, minConf, maxConf);
//multichain - cli testbc listunspent 1 999999[\"4Qk5zZJbJNRTjwVETGzyBbgCW5ePVt7j4vuXTc\"]

StringBuilder builder = new StringBuilder();

foreach (var address in addresses)
{
if (builder.Length > 0)
builder.Append(",");
builder.Append(address);
}
builder.Insert(0, "[");
builder.Append("]");
//return this.ExecuteAsync<List<UnspentResponse>>("listunspent", 0, minConf, maxConf,addresses!=null?builder.ToString():string.Empty);
return this.ExecuteAsync<List<UnspentResponse>>("listunspent", 0, minConf, maxConf, addresses ?? null);
}

public Task<JsonRpcResponse<List<string>>> ListLockUnspentAsync()
public Task<JsonRpcResponse<List<UnspentResponse>>> ListLockUnspentAsync()
{
return this.ExecuteAsync<List<string>>("listlockunspent", 0);
return this.ExecuteAsync<List<UnspentResponse>>("listlockunspent", 0);
}

public Task<JsonRpcResponse<List<string>>> GetAddressesAsync()
Expand Down
27 changes: 27 additions & 0 deletions MultiChainLib/Model/AssetVout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MultiChainLib
{
public class AssetVout
{
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("issuetxid")]
public string IssueTxId { get; set; }

[JsonProperty("assetref")]
public string AssetRef { get; set; }

[JsonProperty("qty")]
public decimal Qty { get; set; }

[JsonProperty("raw")]
public long Raw { get; set; }
}
}
42 changes: 42 additions & 0 deletions MultiChainLib/Model/CreateRawTransactionAmount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MultiChainLib
{
public class CreateRawTransactionAmount
{
public string Address { get; set; }
public Decimal Qty { get; set; }

public CreateRawTransactionAmount()
{
}

//"1DK3fuhpAqHWAvNtbWHqsyHYxUsK38N878t3nZ":qty,
public virtual object StringifyAmount()
{
return Qty;
}
}

public class CreateRawTransactionAsset: CreateRawTransactionAmount
{
public string Name { get; set; }
public CreateRawTransactionAsset() { }

//"1DK3fuhpAqHWAvNtbWHqsyHYxUsK38N878t3nZ":{"asset":qty},
public override object StringifyAmount()
{
dynamic flexible;
flexible = new System.Dynamic.ExpandoObject();
var dictionary = (IDictionary<string, object>)flexible;
dictionary.Add(Name, Qty);

return dictionary;
}
}
}
25 changes: 25 additions & 0 deletions MultiChainLib/Model/CreateRawTransactionTxIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MultiChainLib
{
public class CreateRawTransactionTxIn
{
[JsonProperty("txid")]
public string TxId { get; set; }

[JsonProperty("vout")]
public int Vout { get; set; }


public CreateRawTransactionTxIn()
{
}


}
}
28 changes: 28 additions & 0 deletions MultiChainLib/Model/PrepareLockUnspentAmount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MultiChainLib
{
public class PrepareLockUnspentAmount
{
public string Name { get; set; }
public Decimal Qty { get; set; }

public PrepareLockUnspentAmount() { }
public PrepareLockUnspentAmount(string name, decimal qty) { Name = name; Qty = qty; }

public object StringifyAmount()
{
dynamic flexible;
flexible = new System.Dynamic.ExpandoObject();
var dictionary = (IDictionary<string, object>)flexible;
dictionary.Add(Name, Qty);

return dictionary;
}
}
}
23 changes: 23 additions & 0 deletions MultiChainLib/Model/SignRawTransactionResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MultiChainLib
{
public class SignRawTransactionResponse
{
[JsonProperty("hex")]
public string Hex { get; set; }

[JsonProperty("complete")]
public bool Complete { get; set; }


public SignRawTransactionResponse()
{
}
}
}
4 changes: 2 additions & 2 deletions MultiChainLib/Model/TransactionVout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public class TransactionVout
public ScriptPubKeyResponse ScriptPubKey { get; set; }

[JsonProperty("assets")]
public List<object> Assets { get; set; }
public List<AssetVout> Assets { get; set; }

[JsonProperty("permissions")]
public List<PermissionsResponse> Permissions { get; set; }

public TransactionVout()
{
this.Assets = new List<object>();
this.Assets = new List<AssetVout>();
this.Permissions = new List<PermissionsResponse>();
}
}
Expand Down
10 changes: 10 additions & 0 deletions MultiChainLib/MultiChainLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<AssemblyName>MultiChainLib</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -54,10 +58,14 @@
<Compile Include="Model\AddressGroupingResponse.cs" />
<Compile Include="Model\AddressResponse.cs" />
<Compile Include="Model\AssetBalanceResponse.cs" />
<Compile Include="Model\AssetVout.cs" />
<Compile Include="Model\AssetResponse.cs" />
<Compile Include="Model\BlockchainInfoResponse.cs" />
<Compile Include="Model\BlockResponse.cs" />
<Compile Include="Model\ChainTipResponse.cs" />
<Compile Include="Model\PrepareLockUnspentAmount.cs" />
<Compile Include="Model\CreateRawTransactionAmount.cs" />
<Compile Include="Model\CreateRawTransactionTxIn.cs" />
<Compile Include="Model\GetInfoResponse.cs" />
<Compile Include="Model\GetServerInfoResponse.cs" />
<Compile Include="Model\GetTransactionResponse.cs" />
Expand All @@ -75,6 +83,7 @@
<Compile Include="Model\ReceivedResponse.cs" />
<Compile Include="Model\ScriptResponse.cs" />
<Compile Include="Model\ScriptSigResponse.cs" />
<Compile Include="Model\SignRawTransactionResponse.cs" />
<Compile Include="Model\TransactionResponse.cs" />
<Compile Include="Model\ScriptPubKeyResponse.cs" />
<Compile Include="Model\TxAssetResponse.cs" />
Expand All @@ -89,6 +98,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="ClassDiagram1.cd" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down