public async Task <List <BlockchainVoteModelPlainText> > GetResults(string walletId, string decryptKey) { // Get the votes, aka transactions to our wallet ID var votes = await GetAddressTransactions(walletId); // Read into models, decrypting if necessary return(votes .Select(v => { try { // Read vote data hex var voteBytes = MultiChainClient.ParseHexString(v.Data.First()); // Convert to string var voteStr = Encoding.UTF8.GetString(voteBytes); // Decrypt string if necessary if (!string.IsNullOrWhiteSpace(decryptKey)) { // Read into model (not all parts of the vote are encrypted) var encrypted = JsonConvert.DeserializeObject <BlockchainVoteModelEncrypted>(voteStr); // Convert to regular vote model return encrypted.Decrypt(decryptKey); } return JsonConvert.DeserializeObject <BlockchainVoteModelPlainText>(voteStr); } catch (Exception e) { Debug.WriteLine($"Error reading vote. {e.Message}"); return null; } }) .Where(v => v != null).ToList()); }
public DescentralizedIncentiveScheme(IRepository repository, Incentive incentive) : base(repository, null, incentive) { bool chainAlreadyExist = false; int chainPort; string username; string password; string chainName; //create the blockchain if it does not exist //CreateBlockChain(out chainAlreadyExist); //start the blockchain StartBlockChain(); //load the multichain parameters LoadMultichainParameters(out chainPort, out username, out password, out chainName); //instanciates a multi-chain client this.MultichainClient = new MultiChainClient("localhost", chainPort, false, username, password, chainName); var response = this.MultichainClient.GetInfoAsync(); Console.WriteLine("[INFO] - Connected to Blockchain : [" + response.Result.Result.ChainName + "] with SUCCESS!"); //generates and assoaciates an address for the system Manager GetAddressForManager(); //create the incentives to be distributed in the blockchain IssueIncentives(); //FIXME: remove, just for testing //UserTesting(); }
public async Task <string> WriteTransaction( IEnumerable <CreateRawTransactionTxIn> txIds, IEnumerable <CreateRawTransactionAmount> assets, object data = null) { var blobRes = await RpcClient.CreateRawTransactionAync(txIds, assets); await Task.Delay(500); var blob = blobRes.Result; if (data != null) { var jsonData = JsonConvert.SerializeObject(data); var bytes = Encoding.UTF8.GetBytes(jsonData); blobRes = await RpcClient.AppendRawDataAsync(blob, MultiChainClient.FormatHex(bytes)); await Task.Delay(500); blob = blobRes.Result; } var signedRes = await RpcClient.SignRawTransactionAsync(blob); await Task.Delay(500); var txId = await RpcClient.SendRawTransactionAsync(signedRes.Result.Hex); return(txId.Result); }
internal async Task connectToChain() { //blockchain data user entry String ipAddress = ipEntry.Text; int portNum = Convert.ToInt32(portEntry.Text); String rpcUserName = rpcUserEntry.Text; String rpcPass = rpcPasswordentry.Text; String chainName = chainNameEntry.Text; client = new MultiChainClient(ipAddress, portNum, false, rpcUserName, rpcPass, chainName); //Fast client data entry here for development //client = new MultiChainClient("192.168.218.131", 4390, false, "test", "123", "test"); //Print out chain name to console to be sure we are connected Console.WriteLine("Connect to chain"); var info = await client.GetInfoAsync(); info.AssertOk(); Console.WriteLine("ChainName: {0}", info.Result.ChainName); Console.WriteLine(); clientConnected = true; }
public ActionResult Create(FormCollection collection) { TrialModel trialModel = new TrialModel(); try { MultiChainClient mcClient = new MultiChainClient("54.234.132.18", 2766, false, "multichainrpc", "testmultichain", "TrialRepository"); //populate trial-model by trial-view-model trialModel = GetTrialModel(collection); //Keep following line commented till the time GetTrialModel implemented. var info = mcClient.ListStreamItems("TrialStream"); //var info = mcClient.PublishStream("TrialStream", trialModel.TrialKey, trialModel.TrialData); info.AssertOk(); return(RedirectToAction("Index", "Home")); } catch { return(View()); } }
}// atomic exchange public static async Task <string> getBurnAddress(MultiChainClient multiChainCli) { var client = multiChainCli; var info = await client.GetInfoAsync(); info.AssertOk(); return(info.Result.burnaddress); }
public VotingWindow(MultiChainClient importClient) : base(Gtk.WindowType.Toplevel) { client = importClient; this.Build(); Pango.FontDescription fd = Pango.FontDescription.FromString ("Arial bold 15"); this.votingTitle.ModifyFont(fd); }
private const int NUM_VOTERS = 49; //look at the database for this one. Currently only 49 records in database public MainStationWindow(MultiChainClient importClient, Ssh importSsh, ConnectDB importDB) : base(Gtk.WindowType.Toplevel) { client = importClient; sshClient = importSsh; db = importDB; Console.WriteLine("current logged in user: " + db.getCurrentUser()); this.Build(); }
public LoginWindow(MultiChainClient importClient) : base(Gtk.WindowType.Toplevel) { client = importClient; this.Build(); Pango.FontDescription fd = Pango.FontDescription.FromString("Arial bold 15"); this.titleLabel.ModifyFont(fd); this.passwordEntry.WidthChars = 20; this.userEntry.WidthChars = 20; }
private static void CreateNewAsset(MultiChainClient client, string assetName, int quantity) { //var newAddress = client.Address.CreateKeyPairsAsync(1).Result.Result[0].Address; //client.Wallet.ImportAddress(newAddress, null, false); var newAddress = client.Wallet.GetNewAddress().Result; client.Permission.Grant(newAddress, LucidOcean.MultiChain.API.Enums.BlockChainPermission.Send); client.Permission.Grant(newAddress, LucidOcean.MultiChain.API.Enums.BlockChainPermission.Receive); client.Asset.IssueAsync(newAddress, assetName, quantity, 1m); }
static void Main(string[] args) { try { config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", true, true) .Build(); var MultiChainConnectionConfig = config.GetSection("MultiChainConnection"); connection = new MultiChainConnection() { Hostname = MultiChainConnectionConfig["Hostname"], Port = Convert.ToInt32(MultiChainConnectionConfig["Port"]), Username = MultiChainConnectionConfig["Username"], Password = MultiChainConnectionConfig["Password"], ChainName = MultiChainConnectionConfig["ChainName"], }; multiChainClient = new MultiChainClient(connection); adminAddress = MultiChainConnectionConfig["AdminAddress"]; var otherNodesConfigurationCount = config.GetSection("OtherNodes").GetChildren().ToList().Count; for (int i = 0; i < otherNodesConfigurationCount; i++) { var nodeConfiguration = config.GetSection($"OtherNodes:{i}"); var connection = new MultiChainConnection() { Hostname = nodeConfiguration["Hostname"], Port = Convert.ToInt32(nodeConfiguration["Port"]), Username = nodeConfiguration["Username"], Password = nodeConfiguration["Password"], ChainName = MultiChainConnectionConfig["ChainName"], }; var node = new MultiChainClient(connection); otherNodes.Add(node); } ImportAddresses().GetAwaiter().GetResult(); SubscribeToStreams().GetAwaiter().GetResult(); Console.WriteLine("initialize nodes service finished successfully, Press any key to exit"); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine($"initialize nodes service stopped because : {ex.Message}"); Console.ReadLine(); } }
public MChainstreamController(string blockchain) { ChainName = blockchain; RpcUser = "******"; RpcPassword = "******"; RpcHost = "localhost"; cli.StartInfo.FileName = "MultichainApps\\multichain-cli.exe"; cli.StartInfo.Arguments = ChainName; cli.StartInfo.UseShellExecute = false; client = new MultiChainClient(RpcHost, 6718, false, RpcUser, RpcPassword, ChainName); }
internal async Task connectToChain() { client = new MultiChainClient("192.168.218.128", 6820, false, "multichainrpc", "A3u8rr7R7i8wCtcYEfMH41aCjWcapXGdxhmdHhVtMGvs", "test"); // get server info... Console.WriteLine("Connect to chain"); var info = await client.GetInfoAsync(); info.AssertOk(); Console.WriteLine("ChainName: {0}", info.Result.ChainName); Console.WriteLine(); }
// // GET: /Search/Download/5 public ActionResult Download(string selectedTrialKey, string selectedTxId) { var trialList = GetMultiChainClient().ListStreamKeyItems(GetTrialStream(), selectedTrialKey); var trialModel = trialList.Result.Where(item => item.TxId == selectedTxId).FirstOrDefault(); var jsonTrialViewModel = Utility.HexadecimalEncoding.FromHexString(trialModel.Data); var trialViewModel = JsonConvert.DeserializeObject <TrialViewModel>(jsonTrialViewModel); if (string.IsNullOrEmpty(trialViewModel.DocumentUrl)) { ViewBag.Error = "File was not uploaded for this trial."; return(View("Error")); } var serverFileHash = Utility.GetHash(trialViewModel.DocumentUrl); if (string.IsNullOrEmpty(serverFileHash)) { ViewBag.Error = "File not found on the server. It could have been moved or deleted from the server."; return(View("Error")); } if (serverFileHash != trialViewModel.DocumentHash) { ViewBag.Error = string.Format("Blockchain detected Hash ({0}) mismatch. <br/>File seems to be modified. <br/>Download Terminated!<br/><br/>{1}", trialViewModel.DocumentHash, trialList.RawJson); return(View("Error")); } //continue with logging download request, and actual file download var downloadViewModel = new DownloadViewModel() { TrialName = trialViewModel.TrialName, Description = trialViewModel.TrialDescription, StudyNumber = trialViewModel.StudyNumber, ProtocolName = trialViewModel.ProtocolName, Location = trialViewModel.Location, DownloadedOn = DateTime.UtcNow, DownloadedBy = HttpContext.User.Identity.Name }; var downloadTrialModel = GetTrialModel(trialViewModel.TrialName, downloadViewModel); //Create a download entry for the Current logged in User, requesting for the TrialKey file download MultiChainClient mcClient = GetMultiChainClient(); var info = mcClient.PublishStream(GetTrialDownloadStream(), downloadTrialModel.TrialName, downloadTrialModel.TrialData); info.AssertOk(); //Download the selected file string filePath = Path.Combine(Server.MapPath(trialViewModel.DocumentUrl)); var stream = System.IO.File.OpenRead(filePath); return(File(stream, "application/octet-stream", Path.GetFileName(trialViewModel.DocumentUrl))); }
private static T StreamToModel <T>(ListStreamKeyItemsResponse r) where T : class { try { var modelBytes = MultiChainClient.ParseHexString(r.Data); var bytesJson = Encoding.UTF8.GetString(modelBytes); return(JsonConvert.DeserializeObject <T>(bytesJson)); } catch (JsonSerializationException) { return(null); } }
/// <summary> /// Disconnects RPC Client from multichaind /// </summary> /// <returns></returns> public async Task DisconnectRpc() { Debug.WriteLine($"Disconnecting from {Name} (Connected: {Connected})"); if (!Connected || (RpcClient == null)) { return; } await RpcClient.StopAsync(); RpcClient = null; Connected = false; }
public VotingWindow(MultiChainClient importClient, Ssh importSsh, ConnectDB importDB) : base(Gtk.WindowType.Toplevel) { client = importClient; sshClient = importSsh; db = importDB; Console.WriteLine("current logged in user: "******"Arial bold 15"); this.votingTitle.ModifyFont(fd); GetCandidateName(); }
protected MultiChainClient GetMultiChainClient(string chainName = "") { if (string.IsNullOrEmpty(chainName)) { chainName = ConfigurationManager.AppSettings["TrialRepository"]; } var multiChainIP = ConfigurationManager.AppSettings["MultiChainIPAddress"]; var multiChainPort = Convert.ToInt32(ConfigurationManager.AppSettings["MultiChainPort"]); var multiChainUsername = ConfigurationManager.AppSettings["MultiChainUsername"]; var multiChainPassword = ConfigurationManager.AppSettings["MultiChainPassword"]; mcClient = new MultiChainClient(multiChainIP, multiChainPort, false, multiChainUsername, multiChainPassword, chainName); return(mcClient); }
private static void DistributeAssetToUsers(MultiChainClient client, string fromAddress, string adminAddress, string assetName, decimal quantity) { var addresses = client.Wallet.ListAddresses(true).Result; foreach (var address in addresses) { if (address.Address != fromAddress && address.Address != adminAddress) { //var dictionnary = new Dictionary<string, object>(); //dictionnary.Add(address.Address, new { restaurant_stocks = 100 }); //var TxHex = client.Transaction.CreateRawSendFromAsync(productMarkertAddress, dictionnary).Result.TxHex.Result; var response = client.Asset.SendAssetFromAsync(fromAddress, address.Address, assetName, quantity).Result; } } }
/// <summary> /// Connects to a blockchain using RPC /// </summary> /// <exception cref="InvalidOperationException">Cannot connect to multichain</exception> public async Task ConnectRpc() { if ((RpcClient != null) && Connected) { return; } // Reset, in case we encounter an exception Connected = false; RpcClient = new MultiChainClient("127.0.0.1", RpcPort, false, RpcUser, RpcPassword, Name); await RpcClient.GetInfoAsync(); Connected = true; }
public LoginWindow(MultiChainClient importClient, Ssh importSsh, ConnectDB importDB) : base(Gtk.WindowType.Toplevel) { client = importClient; sshClient = importSsh; db = importDB; this.Build(); Pango.FontDescription fd = Pango.FontDescription.FromString("Arial bold 15"); this.titleLabel.ModifyFont(fd); this.passwordEntry.WidthChars = 20; this.userEntry.WidthChars = 20; setStation(); }
private static void CreateUsers(MultiChainClient client, int usersNumber) { for (int i = 1; i < usersNumber + 1; i++) { // create new address with pub/priv keys //var clientAddress = client.Address.CreateKeyPairsAsync(1).Result.Result[0].Address; //client.Wallet.ImportAddress(clientAddress, null, false); var userAddress = client.Wallet.GetNewAddress().Result; //grant address some permissions client.Permission.Grant(userAddress, LucidOcean.MultiChain.API.Enums.BlockChainPermission.Send); client.Permission.Grant(userAddress, LucidOcean.MultiChain.API.Enums.BlockChainPermission.Receive); byte[] label = Encoding.ASCII.GetBytes($"user{i}"); client.Stream.PublishFrom(userAddress, "root", "", label); } }
public static async Task <string> getProductProviderAddress(MultiChainClient client, string productProviderName) { productProviderName = removeSpaces(productProviderName); List <productprovider> providerList = (from l in db.productproviders select l).ToList(); foreach (productprovider p in providerList) { string tmpName = removeSpaces(p.ppCompanyName); if (productProviderName.Equals(tmpName)) { return(await getAddress(client, p.User_ID)); } } return(""); }
static void Main(string[] args) { MultiChainConnection connection = new MultiChainConnection() { Hostname = "192.168.50.1", Port = 4798, Username = "******", Password = "******", ChainName = "chain1", }; MultiChainClient _Client = new MultiChainClient(connection); //CreateNewAsset(_Client, "restaurant_stocks", 500); //CreateNewAsset(_Client, "Euro", 5000); //CreateUsers(_Client, 5); }
//check if user has asset or if user has amount (assetBalanceToCheck) of type asset on the blockchain public static async Task <bool> hasAssetBalance(MultiChainClient client, int userID, string asset, int assetBalanceToCheck) { string userAddress = await getAddress(client, userID); var getAddressBalances = await client.GetAddressBalancesAsync(userAddress); getAddressBalances.AssertOk(); foreach (var balance in getAddressBalances.Result) { if (balance.Name.Equals(asset) && Convert.ToInt32(balance.Qty) >= assetBalanceToCheck) { return(true); } } return(false); }
private async Task <string> CreateAddressAsync(MultiChainClient client, BlockchainPermissions permissions) { // create an address... Console.WriteLine("*** getnewaddress ***"); var newAddress = await client.GetNewAddressAsync(); newAddress.AssertOk(); Console.WriteLine("New issue address: " + newAddress.Result); Console.WriteLine(); // grant permissions... Console.WriteLine("*** grant ***"); var perms = await client.GrantAsync(new List <string>() { newAddress.Result }, permissions); Console.WriteLine(perms.RawJson); perms.AssertOk(); return(newAddress.Result); }
//exchange assset1 (a serialized json) belonging to user 1, for asset2 belonging to user 2 public static async Task <int> atomicExchange(MultiChainClient multiChainCli, int user1, string JsonStrAsset1, int user2, string JsonStrAsset2) { var client = multiChainCli; string user1Addr = await getAddress(client, user1); string user2Addr = await getAddress(client, user2); // var prepLockUnspentAsset2From = await client.PrepareLockUnspentFromsync(user1Addr, JsonStrAsset1); prepLockUnspentAsset2From.AssertOk(); PrepareLockUnspentFromResponse lockedAsset2 = prepLockUnspentAsset2From.Result; //create raw exchange taking in locked inputs for asset 2. ask for asset 1 var newRawExch = await client.CreateRawExchangeAsync(lockedAsset2.txid, lockedAsset2.vout, JsonStrAsset2); newRawExch.AssertOk(); string hexBlob = newRawExch.Result; //decode raw exchange transaction - output: offer, ask & cancompete //var decodeExch = await client.DecodeRawExchangeAsync(hexBlob); //decodeExch.AssertOk(); //prepare lock unspent inputs of asset 1 var prepLockUnspentAsset1From = await client.PrepareLockUnspentFromsync(user2Addr, JsonStrAsset2); prepLockUnspentAsset1From.AssertOk(); PrepareLockUnspentFromResponse lockedAsset1 = prepLockUnspentAsset1From.Result; //append asset 1 to raw exchange var appendRawExch = await client.AppendRawExchangeAsync(hexBlob, lockedAsset1.txid, lockedAsset1.vout, JsonStrAsset1); appendRawExch.AssertOk(); AppendRawExchangeResponse appendRawExchResponse = appendRawExch.Result; //broadcast raw exchange var sendRawTransaction = await client.SendRawTransactionAsync(appendRawExchResponse.hex); sendRawTransaction.AssertOk(); return(0); }// atomic exchange
//returns users associated address. if user has no address -> give user address -> return new address. permission params - assign permissions if new address is created. // public static async Task<string> getAddress(MultiChainClient client, int userID, params BlockchainPermissions[] paramPermissions) public static async Task <string> getAddress(MultiChainClient client, int userID) { user tmp = new user(); tmp.User_ID = -1; tmp = await db.users.SingleAsync(l => l.User_ID == userID); if (tmp.User_ID != -1) { if (tmp.blockchainAddress == null) { //get new address, get user for which address does not exist, add address to user record. var newAddress = await client.GetNewAddressAsync(); newAddress.AssertOk(); string newAddr = newAddress.Result; //give permissions // var grant1 = client.GrantAsync(new List<string>() { newAddr }, BlockchainPermissions.Send); //var grant2 = client.GrantAsync(new List<string>() { newAddr }, BlockchainPermissions.Receive); tmp.blockchainAddress = newAddress.Result; db.Entry(tmp).State = EntityState.Modified; db.SaveChanges(); //if(paramPermissions.Length > 0) //{ // MUserController tmpUser = new MUserController(userID); // tmpUser = await tmpUser.init(); // await tmpUser.grantPermissions(paramPermissions); //} return(newAddress.Result); } else { return(tmp.blockchainAddress); } } else { throw new KeyNotFoundException(); } }
public async Task GrantPermissions(string runningNode, string newAddress, int port, string username, string password) { IEnumerable <string> address = new string[] { newAddress }; try { var client = new MultiChainClient(runningNode, port, false, username, password, chainName); var connect = await client.GrantAsync(address, BlockchainPermissions.Connect, 0, "0", "0", 0, 0); var admin = await client.GrantAsync(address, BlockchainPermissions.Admin, 0, "0", "0", 0, 0); var issue = await client.GrantAsync(address, BlockchainPermissions.Issue, 0, "0", "0", 0, 0); var send = await client.GrantAsync(address, BlockchainPermissions.Send, 0, "0", "0", 0, 0); var receive = await client.GrantAsync(address, BlockchainPermissions.Receive, 0, "0", "0", 0, 0); Console.WriteLine("Permissions granted!"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
internal async Task connectToChain() { //blockchain data user entry uncomment in production build /** * String ipAddress = ipEntry.Text; * int portNum = Convert.ToInt32(portEntry.Text); * String rpcUserName = rpcUserEntry.Text; * String rpcPass = rpcPasswordentry.Text; * String chainName = chainNameEntry.Text; * client = new MultiChainClient(ipAddress, portNum, false, rpcUserName, rpcPass, chainName); **/ //Fast client data entry here for development comment or change as needed client = new MultiChainClient(MAIN_STATION_IP, RPC_PORT, false, RPC_USERNAME, RPC_PASSWORD, CHAIN_NAME); //Print out chain name to console to be sure we are connected var info = await client.GetInfoAsync(); info.AssertOk(); Console.WriteLine("ChainName: {0}", info.Result.ChainName); Console.WriteLine(); clientConnected = true; }
//internal async Task DoMagic() //{ // // connect to the client... // var client = new MultiChainClient("192.168.40.130", 50001, false, "rpc_username", "rpc_password", "the_chain_name"); // // get some info back... // var info = await client.GetInfoAsync(); // Console.WriteLine("Chain: {0}, difficulty: {1}", info.Result.ChainName, info.Result.Difficulty); //} internal async Task RunAsync() { var client = new MultiChainClient("192.168.40.130", 50001, false, "multichainrpc", "J1Bs45oEms6LRCcUw7CykoZ9ccUCTJbuwfdktk4N7M1Q", "chain_b82037073985329be60ae98e30"); // var client = new MultiChainClient("localhost", 8911, null, null, "chain_2fb1bbf830bf49f6722abc6aae", "493bacb6e18601794a7b99bc2c444decd4e343ef9af8eabddca6d0f64bffd3b3"); //var client = new MultiChainClient("rpc.pbjcloud.com", 443, true, null, null, "chain_4662dcf2e58c1daf3a5a2cf0e0", "23da5aecda55b1dd0613018265a35a0673f73398c571f5e295f9dd2a6ec64fd2"); // get server info... Console.WriteLine("*** getinfo ***"); var info = await client.GetInfoAsync(); info.AssertOk(); Console.WriteLine("Chain: {0}, difficulty: {1}", info.Result.ChainName, info.Result.Difficulty); Console.WriteLine(); // help... Console.WriteLine("*** help ***"); var help = await client.HelpAsync(); help.AssertOk(); Console.WriteLine(help.Result); Console.WriteLine(); // help... Console.WriteLine("*** help ***"); var helpDetail = await client.HelpAsync("getrawmempool"); helpDetail.AssertOk(); Console.WriteLine(helpDetail.Result); Console.WriteLine(); // getgenerate... Console.WriteLine("*** getgenerate ***"); var getGenerate = await client.GetGenerateAsync(); getGenerate.AssertOk(); Console.WriteLine(getGenerate.Result); Console.WriteLine(); // gethashespersec... Console.WriteLine("*** gethashespersec ***"); var getHashesPerSec = await client.GetHashesPerSecAsync(); getHashesPerSec.AssertOk(); Console.WriteLine(getHashesPerSec.Result); Console.WriteLine(); // getmininginfo... Console.WriteLine("*** getmininginfo ***"); var getMiningInfo = await client.GetMiningInfoAsync(); getMiningInfo.AssertOk(); Console.WriteLine(getMiningInfo.Result.Blocks + ", difficulty: " + getMiningInfo.Result.Difficulty); Console.WriteLine(); // getbestblockhash... Console.WriteLine("*** getbestblockhash ***"); var getBestBlockHash = await client.GetBestBlockHashAsync(); getBestBlockHash.AssertOk(); Console.WriteLine(getBestBlockHash.Result); Console.WriteLine(); // getblockcount... Console.WriteLine("*** getblockcount ***"); var getBlockCount = await client.GetBlockCountAsync(); getBlockCount.AssertOk(); Console.WriteLine(getBlockCount.Result); Console.WriteLine(); // getblockcount... Console.WriteLine("*** getblockchaininfo ***"); var getBlockchainInfo = await client.GetBlockchainInfoAsync(); getBlockchainInfo.AssertOk(); Console.WriteLine(getBlockchainInfo.RawJson); Console.WriteLine(); // get peer info... Console.WriteLine("*** getpeerinfo ***"); var peers = await client.GetPeerInfoAsync(); peers.AssertOk(); foreach (var peer in peers.Result) Console.WriteLine("{0} ({1})", peer.Addr, peer.Handshake); Console.WriteLine(); // get the address that can issue assets... // create an asset... Console.WriteLine("*** issue ***"); var assetName = "asset_" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 24); Console.WriteLine("Asset name: " + assetName); var issueAddress = await CreateAddressAsync(client, BlockchainPermissions.Issue | BlockchainPermissions.Receive | BlockchainPermissions.Send); var asset = await client.IssueAsync(issueAddress, assetName, 1000000, 0.1M); asset.AssertOk(); Console.WriteLine("Issue transaction ID: " + asset.Result); Console.WriteLine(); // list the assets... while (true) { Console.WriteLine("*** listassets ***"); var assets = await client.ListAssetsAsync(); assets.AssertOk(); AssetResponse found = null; foreach (var walk in assets.Result) { Console.WriteLine("Name: {0}, ref: {1}", walk.Name, walk.AssetRef); if (walk.Name == assetName) found = walk; } Console.WriteLine(); // have we found it? if (string.IsNullOrEmpty(found.AssetRef)) { Console.WriteLine("Asset is not ready - waiting (this can take 30 seconds or more)..."); Thread.Sleep(10000); } else break; } // create an address... var recipient = await this.CreateAddressAsync(client, BlockchainPermissions.Send | BlockchainPermissions.Receive); // send with metadata... Console.WriteLine("*** sendwithmetadata ***"); var bs = Encoding.UTF8.GetBytes("Hello, world."); var sendResult = await client.SendWithMetadataAsync(recipient, assetName, 1, bs); sendResult.AssertOk(); Console.WriteLine("Send transaction ID: " + sendResult.Result); Console.WriteLine(); // get it... Console.WriteLine("*** getrawtransaction ***"); var retrieved = await client.GetRawTransactionVerboseAsync(sendResult.Result); retrieved.AssertOk(); Console.WriteLine("ID: {0}", retrieved.Result.TxId); for(var index = 0; index < retrieved.Result.Data.Count; index++) { Console.WriteLine("Data: " + retrieved.Result.Data[index]); var retrievedBs = retrieved.Result.GetDataAsBytes(index); Console.WriteLine("--> " + Encoding.UTF8.GetString(retrievedBs)); } }
private async Task<string> CreateAddressAsync(MultiChainClient client, BlockchainPermissions permissions) { // create an address... Console.WriteLine("*** getnewaddress ***"); var newAddress = await client.GetNewAddressAsync(); newAddress.AssertOk(); Console.WriteLine("New issue address: " + newAddress.Result); Console.WriteLine(); // grant permissions... Console.WriteLine("*** grant ***"); var perms = await client.GrantAsync(new List<string>() { newAddress.Result }, permissions); Console.WriteLine(perms.RawJson); perms.AssertOk(); return newAddress.Result; }
internal async Task RunAsync() { //var client = new MultiChainClient("192.168.40.131", 50009, false, "multichainrpc", "QWYLSyhv44EiSKFwyvRufNBcqtJyd8QJi7NUzm2xG2X", "chain_600bf49a419e7fb3fa0530de6e"); //var client = new MultiChainClient("localhost", 8911, false, null, null, "chain_600bf49a419e7fb3fa0530de6e", "7ae614be3a222c8ef0f337504d046b46805baaa7f787381db33cb2e1f4b562e6"); var client = new MultiChainClient("rpc.pbjcloud.com", 443, true, null, null, "chain_3c03d89be612441af8a5c148ca", "54cd2dd2edc0a87a05a7f7e7b0f13e9913cf6de3ca202df232b21d83ccc93fa2"); var isPbj = false; // get info... Console.WriteLine("*** getinfo ***"); var info = await client.GetInfoAsync(); info.AssertOk(); Console.WriteLine("Chain: {0}, difficulty: {1}", info.Result.ChainName, info.Result.Difficulty); Console.WriteLine(); // get server info... if (isPbj) { Console.WriteLine("*** getserverinfo ***"); var serverInfo = await client.GetServerInfoAsync(); serverInfo.AssertOk(); Console.WriteLine("Version: {0}", serverInfo.Result.Version); Console.WriteLine(); } // get info... Console.WriteLine("*** ping ***"); var ping = await client.PingAsync(); ping.AssertOk(); Console.WriteLine(ping.RawJson); Console.WriteLine(); // help... Console.WriteLine("*** help ***"); var help = await client.HelpAsync(); help.AssertOk(); Console.WriteLine(help.Result); Console.WriteLine(); // help... Console.WriteLine("*** help ***"); var helpDetail = await client.HelpAsync("getrawmempool"); helpDetail.AssertOk(); Console.WriteLine(helpDetail.Result); Console.WriteLine(); // setgenerate... Console.WriteLine("*** setgenerate ***"); var setGenerate = await client.SetGenerateAsync(true); setGenerate.AssertOk(); Console.WriteLine(setGenerate.Result); Console.WriteLine(); // getgenerate... Console.WriteLine("*** getgenerate ***"); var getGenerate = await client.GetGenerateAsync(); getGenerate.AssertOk(); Console.WriteLine(getGenerate.Result); Console.WriteLine(); // gethashespersec... Console.WriteLine("*** gethashespersec ***"); var getHashesPerSec = await client.GetHashesPerSecAsync(); getHashesPerSec.AssertOk(); Console.WriteLine(getHashesPerSec.Result); Console.WriteLine(); // getmininginfo... Console.WriteLine("*** getmininginfo ***"); var getMiningInfo = await client.GetMiningInfoAsync(); getMiningInfo.AssertOk(); Console.WriteLine(getMiningInfo.Result.Blocks + ", difficulty: " + getMiningInfo.Result.Difficulty); Console.WriteLine(); // getnetworkhashps... Console.WriteLine("*** getnetworkhashps ***"); var getNetworkHashPs = await client.GetNetworkHashPsAsync(); getNetworkHashPs.AssertOk(); Console.WriteLine(getNetworkHashPs.Result); Console.WriteLine(); // getnetworkhashps... //Console.WriteLine("*** settxfee ***"); //var setTxFee = await client.SetTxFeeAsync(0.001M); //setTxFee.AssertOk(); //Console.WriteLine(setTxFee.Result); //Console.WriteLine(); // getblocktemplate... //Console.WriteLine("*** getblocktemplate ***"); //var getBlockTemplate = await client.GetBlockTemplateAsync(); //getBlockTemplate.AssertOk(); //Console.WriteLine(getBlockTemplate.Result); //Console.WriteLine(); // getbestblockhash... Console.WriteLine("*** getbestblockhash ***"); var getBestBlockHash = await client.GetBestBlockHashAsync(); getBestBlockHash.AssertOk(); Console.WriteLine(getBestBlockHash.Result); Console.WriteLine(); // getblockcount... Console.WriteLine("*** getblockcount ***"); var getBlockCount = await client.GetBlockCountAsync(); getBlockCount.AssertOk(); Console.WriteLine(getBlockCount.Result); Console.WriteLine(); // getblockcount... Console.WriteLine("*** getblockchaininfo ***"); var getBlockchainInfo = await client.GetBlockchainInfoAsync(); getBlockchainInfo.AssertOk(); Console.WriteLine(getBlockchainInfo.Result.Description + ", best: " + getBlockchainInfo.Result.BestBlockHash); Console.WriteLine(); // getdifficulty... Console.WriteLine("*** getdifficulty ***"); var getDifficulty = await client.GetDifficultyAsync(); getDifficulty.AssertOk(); Console.WriteLine(getDifficulty.Result); Console.WriteLine(); // get chain tips... Console.WriteLine("*** getchaintips ***"); var getChainTips = await client.GetChainTipsAsync(); getChainTips.AssertOk(); foreach (var tip in getChainTips.Result) Console.WriteLine("{0}, {1}, {2}", tip.Height, tip.Hash, tip.Status); Console.WriteLine(); // get mempool info... Console.WriteLine("*** getmempoolinfo ***"); var getMempoolInfo = await client.GetMempoolInfoAsync(); getMempoolInfo.AssertOk(); Console.WriteLine(getMempoolInfo.Result.Size + ", bytes: " + getMempoolInfo.Result.Bytes); Console.WriteLine(); // get block hash... Console.WriteLine("*** getblockhash ***"); var getBlockHash = await client.GetBlockHashAsync(1); getBlockHash.AssertOk(); Console.WriteLine(getBlockHash.Result); Console.WriteLine(); // getblock... Console.WriteLine("*** getblock ***"); var getBlock = await client.GetBlockAsync(getBlockHash.Result); getBlock.AssertOk(); Console.WriteLine(getBlock.Result); Console.WriteLine(); // getblock... Console.WriteLine("*** getblock (verbose) ***"); var getBlockVerbose = await client.GetBlockVerboseAsync(getBlockHash.Result); getBlockVerbose.AssertOk(); Console.WriteLine(getBlockVerbose.Result.Hash + ", nonce: " + getBlockVerbose.Result.Nonce); Console.WriteLine(); // getrawmempool... Console.WriteLine("*** getrawmempool ***"); var getRawMemPool = await client.GetRawMempoolAsync(); getRawMemPool.AssertOk(); Console.WriteLine(getRawMemPool.Result); Console.WriteLine(); // getrawmempool... Console.WriteLine("*** getrawmempool (verbose) ***"); var getRawMemPoolVerbose = await client.GetRawMempoolVerboseAsync(); getRawMemPoolVerbose.AssertOk(); Console.WriteLine(getRawMemPoolVerbose.Result); Console.WriteLine(); // getblockchainpararms... Console.WriteLine("*** getblockchainparams ***"); var getBlockchainParams = await client.GetBlockchainParamsAsync(); getBlockchainParams.AssertOk(); foreach (var key in getBlockchainParams.Result.Keys) Console.WriteLine("{0}: {1}", key, getBlockchainParams.Result[key]); Console.WriteLine(); //// getblockchainpararms... //Console.WriteLine("*** getblockchainpararms (displayNames) ***"); //var getBlockchainParams2 = await client.GetBlockchainParamsAsync(new List<string>() { "chain-protocol" }); //getBlockchainParams2.AssertOk(); //foreach (var key in getBlockchainParams2.Result.Keys) // Console.WriteLine("{0}: {1}", key, getBlockchainParams2.Result[key]); //Console.WriteLine(); // get connection count... Console.WriteLine("*** getconnectioncount ***"); var getConnectionCount = await client.GetConnectionCountAsync(); getConnectionCount.AssertOk(); Console.WriteLine(getConnectionCount.Result); Console.WriteLine(); // get network info... Console.WriteLine("*** getnetworkinfo ***"); var getNetworkInfo = await client.GetNetworkInfoAsync(); getNetworkInfo.AssertOk(); Console.WriteLine(getNetworkInfo.Result.Version + ", subversion: " + getNetworkInfo.Result.Subversion); foreach (var network in getNetworkInfo.Result.Networks) Console.WriteLine(network.Name); Console.WriteLine(); // get net totals... Console.WriteLine("*** getnettotals ***"); var getNetTotals = await client.GetNetTotalsAsync(); getNetTotals.AssertOk(); Console.WriteLine("Received: {0}, sent: {1}:, time: {2}", getNetTotals.Result.TotalsBytesRecv, getNetTotals.Result.TotalsBytesSent, getNetTotals.Result.TimeMillis); Console.WriteLine(); // get peer info... Console.WriteLine("*** getunconfirmedbalance ***"); var getUnconfirmedBalance = await client.GetUnconfirmedBalanceAsync(); getUnconfirmedBalance.AssertOk(); Console.WriteLine(getUnconfirmedBalance.Result); Console.WriteLine(); // keypool refill... Console.WriteLine("*** keypoolrefill ***"); var keypoolRefill = await client.KeypoolRefillAsync(); keypoolRefill.AssertOk(); Console.WriteLine(keypoolRefill.RawJson); Console.WriteLine(); // get wallet info... Console.WriteLine("*** getwalletinfo ***"); var getWalletInfo = await client.GetWalletInfoAsync(); getWalletInfo.AssertOk(); Console.WriteLine(getWalletInfo.Result.WalletVersion + ", balance: " + getWalletInfo.Result.Balance); Console.WriteLine(); // get added node info... Console.WriteLine("*** getaddednodeinfo ***"); var getAddedNodeInfo = await client.GetAddedNodeInfoAsync(); getAddedNodeInfo.AssertOk(); Console.WriteLine(getAddedNodeInfo.RawJson); Console.WriteLine(); // get raw change address... Console.WriteLine("*** getrawchangeaddress ***"); var getRawChangeAddress = await client.GetRawChangeAddressAsync(); getRawChangeAddress.AssertOk(); Console.WriteLine(getRawChangeAddress.Result); Console.WriteLine(); // get addresses... Console.WriteLine("*** getaddresses ***"); var getAddresses = await client.GetAddressesAsync(); getAddresses.AssertOk(); foreach(var address in getAddresses.Result) Console.WriteLine(address); Console.WriteLine(); // get addresses verbose... Console.WriteLine("*** getaddresses (verbose) ***"); var getAddressesVerbose = await client.GetAddressesVerboseAsync(); getAddressesVerbose.AssertOk(); foreach (var address in getAddressesVerbose.Result) Console.WriteLine("{0}, mine: {1}", address.Address, address.IsMine); Console.WriteLine(); // get peer info... Console.WriteLine("*** getpeerinfo ***"); var peers = await client.GetPeerInfoAsync(); peers.AssertOk(); foreach (var peer in peers.Result) Console.WriteLine("{0} ({1})", peer.Addr, peer.Handshake); Console.WriteLine(); // backup wallet... Console.WriteLine("*** backupwallet ***"); var path = Path.GetTempFileName(); Console.WriteLine(path); var backup = await client.BackupWalletAsync(path); backup.AssertOk(); Console.WriteLine(backup.RawJson); Console.WriteLine(); // backup wallet... Console.WriteLine("*** dumpwallet ***"); path = Path.GetTempFileName(); Console.WriteLine(path); var dumpWallet = await client.DumpWalletAsync(path); dumpWallet.AssertOk(); Console.WriteLine(dumpWallet.RawJson); Console.WriteLine(); // estimate fee... Console.WriteLine("*** estimatefee ***"); var estimateFee = await client.EstimateFeeAsync(10); estimateFee.AssertOk(); Console.WriteLine(estimateFee.Result); Console.WriteLine(); // estimate priority... Console.WriteLine("*** estimatepriority ***"); var estimatePriority = await client.EstimatePriorityAsync(10); estimatePriority.AssertOk(); Console.WriteLine(estimatePriority.Result); Console.WriteLine(); // get new address... Console.WriteLine("*** getnewaddress ***"); var getNewAddress = await client.GetNewAddressAsync(); getNewAddress.AssertOk(); Console.WriteLine(getNewAddress.Result); Console.WriteLine(); // validate address... Console.WriteLine("*** validateaddress ***"); var validateAddress = await client.ValidateAddressAsync(getNewAddress.Result); validateAddress.AssertOk(); Console.WriteLine(validateAddress.Result.Address + ", pubkey: " + validateAddress.Result.PubKey); Console.WriteLine(); // get balance... Console.WriteLine("*** getbalance ***"); var getBalance = await client.GetBalanceAsync(); getBalance.AssertOk(); Console.WriteLine(getBalance.Result); Console.WriteLine(); // get balance... Console.WriteLine("*** gettotalbalances ***"); var getTotalBalances = await client.GetTotalBalancesAsync(); getTotalBalances.AssertOk(); foreach (var balance in getTotalBalances.Result) Console.WriteLine("{0}, ref: {1}, qty: {2}", balance.Name, balance.AssetRef, balance.Qty); Console.WriteLine(); // list accounts... Console.WriteLine("*** listaccounts ***"); var listAccounts = await client.ListAccountsAsync(); listAccounts.AssertOk(); foreach (var key in listAccounts.Result.Keys) Console.WriteLine("{0}, balance: {1}", key, listAccounts.Result[key]); Console.WriteLine(); // get account... Console.WriteLine("*** getaddressesbyaccount ***"); var getAddressesByAccount = await client.GetAddressesByAccountAsync(null); getAddressesByAccount.AssertOk(); foreach (var address in getAddressesByAccount.Result) Console.WriteLine(address); Console.WriteLine(); // get account address... Console.WriteLine("*** getaccountaddress ***"); var getAccountAddress = await client.GetAccountAddressAsync(null); getAccountAddress.AssertOk(); Console.WriteLine(getAccountAddress.Result); Console.WriteLine(); // get account... Console.WriteLine("*** getaccount ***"); var getAccount = await client.GetAccountAsync(getAddressesByAccount.Result.First()); getAccount.AssertOk(); Console.WriteLine(getAccount.Result); Console.WriteLine(); // get address balances... Console.WriteLine("*** getaddressbalances ***"); var getAddressBalances = await client.GetAddressBalancesAsync(getAddressesByAccount.Result.First()); getAddressBalances.AssertOk(); foreach (var balance in getAddressBalances.Result) Console.WriteLine(balance); Console.WriteLine(); // list address groupings... Console.WriteLine("*** listaddressgroupings ***"); var listAddressGroupings = await client.ListAddressGroupingsAsync(); listAddressGroupings.AssertOk(); Console.Write(listAddressGroupings.RawJson); Console.WriteLine(); // list unspent... Console.WriteLine("*** listunspent ***"); var listUnspent = await client.ListUnspentAsync(); listUnspent.AssertOk(); foreach (var unspent in listUnspent.Result) Console.WriteLine("{0}, tx: {1}", unspent.Address, unspent.TxId); Console.WriteLine(); // list lock unspent... Console.WriteLine("*** listlockunspent ***"); var listLockUnspent = await client.ListLockUnspentAsync(); listLockUnspent.AssertOk(); foreach (var unspent in listLockUnspent.Result) Console.WriteLine(unspent); Console.WriteLine(); // list since block... Console.WriteLine("*** listsinceblock ***"); var listSinceBlock = await client.ListSinceBlockAsync(getBlockHash.Result); listSinceBlock.AssertOk(); foreach (var tx in listSinceBlock.Result.Transactions) Console.WriteLine(tx.Address + ", hash: " + tx.BlockHash); Console.WriteLine(); //// import address... //Console.WriteLine("*** importaddress ***"); //var importAddress = await client.ImportAddressAsync("1RytCj4dMZvt3pR8SysvBo5ntXMxUu1gTWN9j8"); //importAddress.AssertOk(); //Console.WriteLine(importAddress.RawJson); //Console.WriteLine(); // get received by account... Console.WriteLine("*** getreceivedbyaccount ***"); var getReceivedByAccount = await client.GetReceivedByAccountAsync(); getReceivedByAccount.AssertOk(); Console.WriteLine(getReceivedByAccount.Result); Console.WriteLine(); // list transactions... Console.WriteLine("*** listtransactions ***"); var listTransactions = await client.ListTransactionsAsync(); listTransactions.AssertOk(); foreach (var tx in listTransactions.Result) Console.WriteLine("{0}, tx: {1}", tx.Address, tx.TxId); Console.WriteLine(); // capture... var txId = listTransactions.Result.Last().TxId; // list transactions... Console.WriteLine("*** gettransaction ***"); var getTransaction = await client.GetTransactionAsync(txId); getTransaction.AssertOk(); Console.WriteLine("{0}, block time: {1}", getTransaction.Result.BlockHash, getTransaction.Result.BlockTime); foreach (var details in getTransaction.Result.Details) Console.WriteLine(details.Address + ", amount: " + details.Amount); Console.WriteLine(); // get tx out... Console.WriteLine("*** gettxout ***"); var getTxOut = await client.GetTxOutAsync(txId); getTxOut.AssertOk(); Console.WriteLine("{0}, asm: {1}", getTxOut.Result.BestBlock, getTxOut.Result.ScriptPubKey.Asm); foreach (var walk in getTxOut.Result.Assets) Console.WriteLine("{0}, ref: {1}", walk.Name, walk.AssetRef); Console.WriteLine(); // get raw transaction... Console.WriteLine("*** getrawtransaction ***"); var getRawTransaction = await client.GetRawTransactionAsync(txId); getRawTransaction.AssertOk(); Console.WriteLine(getRawTransaction.Result); Console.WriteLine(); // decode raw transaction... Console.WriteLine("*** decoderawstransaction ***"); var decodeRawTransaction = await client.DecodeRawTransactionAsync(getRawTransaction.Result); decodeRawTransaction.AssertOk(); foreach (var walk in decodeRawTransaction.Result.Vin) Console.WriteLine(walk.TxId); foreach (var walk in decodeRawTransaction.Result.Vout) Console.WriteLine(walk.Value); Console.WriteLine(); // get raw transaction... Console.WriteLine("*** getrawtransaction (verbose) ***"); var getRawTransactionVerbose = await client.GetRawTransactionVerboseAsync(txId); getRawTransactionVerbose.AssertOk(); foreach(var walk in getRawTransactionVerbose.Result.Data) Console.WriteLine(walk); Console.WriteLine(); // get tx out set info... Console.WriteLine("*** gettxoutsetinfo ***"); var getTxOutSetInfo = await client.GetTxOutSetInfoAsync(); getTxOutSetInfo.AssertOk(); Console.WriteLine("{0}, best: {1}", getTxOutSetInfo.Result.Height, getTxOutSetInfo.Result.BestBlock); Console.WriteLine(); // prioritise transaction... Console.WriteLine("*** prioritisetransaction ***"); var prioritiseTransaction = await client.PrioritiseTransactionAsync(txId, 10, 1); prioritiseTransaction.AssertOk(); Console.WriteLine(prioritiseTransaction.RawJson); Console.WriteLine(); // get asset balances... Console.WriteLine("*** getassetbalances ***"); var getAssetBalances = await client.GetAssetBalancesAsync(); getAssetBalances.AssertOk(); foreach (var walk in getAssetBalances.Result) Console.WriteLine("{0}, ref: {1}, balance: {2}", walk.Name, walk.AssetRef, walk.Qty); Console.WriteLine(); // list received by address... Console.WriteLine("*** listreceivedbyaddress ***"); var listReceivedByAddress = await client.ListReceivedByAddressAsync(); listReceivedByAddress.AssertOk(); foreach(var walk in listReceivedByAddress.Result) Console.WriteLine("{0}, confirmations: {1}", walk.Address, walk.Confirmations); Console.WriteLine(); // list received by account... Console.WriteLine("*** listreceivedbyaccount ***"); var listReceivedByAccount = await client.ListReceivedByAccountAsync(); listReceivedByAccount.AssertOk(); foreach (var walk in listReceivedByAccount.Result) Console.WriteLine("{0}, confirmations: {1}", walk.Account, walk.Confirmations); Console.WriteLine(); // list permissions... Console.WriteLine("*** listpermissions ***"); var listPermissions = await client.ListPermissions(BlockchainPermissions.Admin); listPermissions.AssertOk(); foreach (var walk in listPermissions.Result) Console.WriteLine(walk.Address + ", " + walk.Type); Console.WriteLine(); // one, two... var one = await CreateAddressAsync(client, BlockchainPermissions.Issue | BlockchainPermissions.Send | BlockchainPermissions.Receive); var two = await CreateAddressAsync(client, BlockchainPermissions.Send | BlockchainPermissions.Receive); var three = await CreateAddressAsync(client, BlockchainPermissions.Send | BlockchainPermissions.Receive); var four = await CreateAddressAsync(client, BlockchainPermissions.Send | BlockchainPermissions.Receive); // revoke... Console.WriteLine("*** revoke ***"); var revoke = await client.RevokeAsync(new List<string>() { three }, BlockchainPermissions.Send); revoke.AssertOk(); Console.WriteLine(revoke.Result); Console.WriteLine(); // revoke... Console.WriteLine("*** revokefrom ***"); var revokeFrom = await client.RevokeFromAsync(listPermissions.Result.First().Address, new List<string>() { three }, BlockchainPermissions.Receive); revokeFrom.AssertOk(); Console.WriteLine(revokeFrom.Result); Console.WriteLine(); // grant from... Console.WriteLine("*** grantfrom ***"); var grantFrom = await client.GrantFromAsync(listPermissions.Result.First().Address, new List<string>() { two }, BlockchainPermissions.Send | BlockchainPermissions.Receive); grantFrom.AssertOk(); Console.WriteLine(grantFrom.Result); Console.WriteLine(); // set account... Console.WriteLine("*** setaccount ***"); var setAccount = await client.SetAccountAsync(four, this.GetRandomName("account")); setAccount.AssertOk(); Console.WriteLine(setAccount.Result); Console.WriteLine(); // get received by address... Console.WriteLine("*** getreceivedbyaddress ***"); var getReceivedByAddress = await client.GetReceivedByAddressAsync(one); getReceivedByAddress.AssertOk(); Console.WriteLine(getReceivedByAddress.Result); Console.WriteLine(); // dump priv key... Console.WriteLine("*** dumpprivkey ***"); var dumpPrivKey = await client.DumpPrivKeyAsync(one); dumpPrivKey.AssertOk(); Console.WriteLine(dumpWallet.Result); Console.WriteLine(); // create multisig... var toUse = new List<string>(); foreach (var address in getAddresses.Result) { toUse.Add(address); if (toUse.Count == 5) break; } while (toUse.Count < 5) toUse.Add(await this.CreateAddressAsync(client, BlockchainPermissions.Receive)); Console.WriteLine("*** createmultisig ***"); var createMultiSig = await client.CreateMultiSigAsync(5, toUse); createMultiSig.AssertOk(); Console.WriteLine("{0}, redeemScript: {1}", createMultiSig.Result.Address, createMultiSig.Result.RedeemScript); Console.WriteLine(); Console.WriteLine("*** decodescript ***"); var decodeScript = await client.DecodeScriptAsync(createMultiSig.Result.RedeemScript); decodeScript.AssertOk(); foreach (var walk in decodeScript.Result.Addresses) Console.WriteLine(walk); Console.WriteLine(); Console.WriteLine("*** addmultisigaddress ***"); var addMultiSigAddress = await client.AddMultiSigAddressAsync(5, toUse); addMultiSigAddress.AssertOk(); Console.WriteLine(addMultiSigAddress.Result); Console.WriteLine(); // issue... Console.WriteLine("*** issue ***"); var assetName = this.GetRandomName("asset"); var issue = await client.IssueAsync(one, assetName, 1000000, 0.1M); Console.WriteLine(issue.Result); Console.WriteLine(); // issue... Console.WriteLine("*** issuefrom ***"); assetName = "asset_" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 24); var issueFrom = await client.IssueFromAsync(one, two, assetName, 1000000, 0.1M); Console.WriteLine(issueFrom.Result); Console.WriteLine(); // list the assets... while (true) { Console.WriteLine("*** listassets ***"); var assets = await client.ListAssetsAsync(); assets.AssertOk(); AssetResponse found = null; foreach (var walk in assets.Result) { if (walk.Name == assetName) found = walk; } Console.WriteLine(); // have we found it? if (string.IsNullOrEmpty(found.AssetRef)) { Console.WriteLine("Asset is not ready - waiting (this can take 30 seconds or more)..."); Thread.Sleep(2500); } else break; } // send with meta data... Console.WriteLine("*** sendwithmetadata ***"); var bs = Encoding.UTF8.GetBytes("Hello, world."); var sendWithMetaData = await client.SendWithMetadataAsync(two, assetName, 1, bs); sendWithMetaData.AssertOk(); Console.WriteLine("Send transaction ID: " + sendWithMetaData.Result); Console.WriteLine(); // send with meta data... Console.WriteLine("*** sendwithmetadataform ***"); var sendWithMetaDataFrom = await client.SendWithMetadataFromAsync(two, one, assetName, 1, bs); sendWithMetaDataFrom.AssertOk(); Console.WriteLine("Send transaction ID: " + sendWithMetaDataFrom.Result); Console.WriteLine(); // send asset to address... Console.WriteLine("*** sendassettoaddress ***"); var sendAssetToAddress = await client.SendAssetToAddressAsync(two, assetName, 1); sendAssetToAddress.AssertOk(); Console.WriteLine("Send transaction ID: " + sendAssetToAddress.Result); Console.WriteLine(); // send to address... Console.WriteLine("*** sendtoaddress ***"); var sendToAddress = await client.SendToAddressAsync(two, assetName, 1); sendToAddress.AssertOk(); Console.WriteLine("Send transaction ID: " + sendToAddress.Result); Console.WriteLine(); // send asset from... Console.WriteLine("*** sendassetfrom ***"); var sendAssetFrom = await client.SendAssetFromAsync(two, one, assetName, 1); sendAssetFrom.AssertOk(); Console.WriteLine("Send transaction ID: " + sendAssetFrom.Result); Console.WriteLine(); // send from... //Console.WriteLine("*** sendfrom ***"); //var sendFrom = await client.SendFromAsync("", two, 1); //sendFrom.AssertOk(); //Console.WriteLine(sendFrom.Result); // submit block... //Console.WriteLine("*** submitblock ***"); //var submitBlock = await client.SubmitBlockAsync(Encoding.UTF8.GetBytes("Hello, world.")); //submitBlock.AssertOk(); //Console.WriteLine("Send transaction ID: " + sendAssetFrom.Result); //Console.WriteLine(); //// verify message... //Console.WriteLine("*** verifymessage ***"); //var sendAssetFrom = await client.SendAssetFromAsync(two, one, assetName, 1); //sendAssetFrom.AssertOk(); //Console.WriteLine("Send transaction ID: " + sendAssetFrom.Result); //Console.WriteLine(); // check blocks... Console.WriteLine("*** verifychain ***"); var verifyChain = await client.VerifyChainAsync(CheckBlockType.ReadFromDisk); verifyChain.AssertOk(); Console.WriteLine(verifyChain.Result); Console.WriteLine(); }