public async Task <IActionResult> ValidateAsync(string transactionId) { if (string.IsNullOrWhiteSpace(transactionId)) { return(NotFound()); } try { var conn1Config = new Dictionary <string, object>(); //config connection 1 conn1Config.Add("baseUrl", "http://ebcl1.ici.ro"); BlockchainConnection conn1 = new BlockchainConnection(conn1Config); var conn2Config = new Dictionary <string, object>(); var headers2 = new Dictionary <string, string>(); //config connection 2 conn2Config.Add("baseUrl", "http://ebcl2.ici.ro"); BlockchainConnection conn2 = new BlockchainConnection(conn2Config); var conn3Config = new Dictionary <string, object>(); var headers3 = new Dictionary <string, string>(); //config connection 2 conn3Config.Add("baseUrl", "http://ebcl3.ici.ro"); BlockchainConnection conn3 = new BlockchainConnection(conn2Config); //add connections IList <BlockchainConnection> connections = new List <BlockchainConnection>(); connections.Add(conn1); connections.Add(conn2); connections.Add(conn3); //multiple connections var builderWithConnections = BigchainDbConfigBuilder .addConnections(connections) .setTimeout(60000); //override default timeout of 20000 milliseconds await builderWithConnections.setup(); var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(transactionId); BlockchainTransaction bt = JsonConvert.DeserializeObject <BlockchainTransaction>(testTran2.Asset.Data.ToString()); return(View(bt)); } catch (Exception e) { return(Content("Error connecting to the blockchain")); } }
public async Task testTokensBuildAndCombineTransferPartingTransaction() { var publicKeyObj = BlockchainAccount.publicKeyFromHex(publicKey); var privateKeyObj = BlockchainAccount.privateKeyFromHex(privateKey); // initial tokens amount int tokens = 10000; TestToken assetData = new TestToken(); assetData.token = "My Token on " + DateTime.Now.Ticks.ToString(); assetData.number_tokens = tokens; TestMetadata metaData = new TestMetadata(); metaData.msg = "My first transaction"; // Set up, sign, and send your transaction var transaction = BigchainDbTransactionBuilder <TestToken, TestMetadata> .init() .addAssets(assetData) .addMetaData(metaData) .addOutput(tokens.ToString(), publicKeyObj) .operation(Operations.CREATE) .buildAndSignOnly(publicKeyObj, privateKeyObj); //.buildAndSign(account.PublicKey, account.PrivateKey); //var info = transaction.toHashInput(); var createTransaction = await TransactionsApi <TestToken, TestMetadata> .sendTransactionAsync(transaction); Thread.Sleep(5000); createTransaction.Data.ShouldNotBe(null); // the asset's ID is equal to the ID of the transaction that created it if (createTransaction.Data != null) { string testId2 = createTransaction.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(testId2); testTran2.ShouldNotBe(null); } // Describe the output you are fulfilling on the previous transaction FulFill spendFrom = new FulFill(); // the asset's ID is equal to the ID of the transaction that created it spendFrom.TransactionId = createTransaction.Data.Id; spendFrom.OutputIndex = 0; // we want to transfer 200 tokens to my cat int amount = 200; BlockchainAccount catAccount = new BlockchainAccount(); Details details = null; TestToken transferData = new TestToken(); assetData.token = "To my cat"; assetData.number_tokens = amount; int amountLeft = tokens - amount; // Use the previous transaction's asset and TRANSFER it var build2 = BigchainDbTransactionBuilder <Asset <string>, TestToken> . init(). addMetaData(transferData). addInput(details, spendFrom, publicKeyObj). addOutput(amountLeft.ToString(), publicKeyObj). addOutput(amount.ToString(), catAccount.PublicKey). addAssets(createTransaction.Data.Id). operation(Operations.TRANSFER). buildAndSignOnly(publicKeyObj, privateKeyObj); var transferTransaction = await TransactionsApi <Asset <string>, TestToken> .sendTransactionAsync(build2); Thread.Sleep(5000); transferTransaction.Data.ShouldNotBe(null); if (transferTransaction != null) { string tran2 = transferTransaction.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(tran2); testTran2.ShouldNotBe(null); } var useThisKey = transferTransaction.Data.Outputs[0].PublicKeys[0]; var compKey = KeyPairUtils.encodePublicKeyInBase58(publicKeyObj); // get unspent outputs var list = await OutputsApi.getUnspentOutputsAsync(useThisKey); //list.Count.ShouldBe(1); // Describe the output you are fulfilling on spent outputs FulFill spendFrom2 = new FulFill(); // the asset's ID is equal to the ID of the transaction that created it spendFrom2.TransactionId = transferTransaction.Data.Id; // list[0].TransactionId; spendFrom2.OutputIndex = 0; // now we want to send 100 tokens to my dog BlockchainAccount dogAccount = new BlockchainAccount(); Details details2 = null; TestToken transferData2 = new TestToken(); transferData2.token = "To my dog"; transferData2.number_tokens = amount; amountLeft = amountLeft - amount; // Use the previous transaction's asset and TRANSFER it var build3 = BigchainDbTransactionBuilder <Asset <string>, TestToken> . init(). addMetaData(transferData2). addInput(details2, spendFrom2, publicKeyObj). addOutput(amountLeft.ToString(), publicKeyObj). addOutput(amount.ToString(), dogAccount.PublicKey). addAssets(createTransaction.Data.Id). operation(Operations.TRANSFER). buildAndSignOnly(publicKeyObj, privateKeyObj); var transferTransaction3 = await TransactionsApi <Asset <string>, TestToken> .sendTransactionAsync(build3); Thread.Sleep(5000); transferTransaction3.Data.ShouldNotBe(null); if (transferTransaction3 != null) { string tran2 = transferTransaction3.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(tran2); testTran2.ShouldNotBe(null); } // now dog wants to share with puppy 100 tokens BlockchainAccount puppyAccount = new BlockchainAccount(); Details details3 = null; TestToken transferData3 = new TestToken(); transferData3.token = "To my puppy"; int topuppy = 100; transferData3.number_tokens = topuppy; FulFill spendFrom3 = new FulFill(); // the asset's ID is equal to the ID of the transaction that created it spendFrom3.TransactionId = transferTransaction3.Data.Id; // list[0].TransactionId; spendFrom3.OutputIndex = 1; var dogAmountLeft = amount - topuppy; // Use the previous transaction's asset and TRANSFER it var build4 = BigchainDbTransactionBuilder <Asset <string>, TestToken> . init(). addMetaData(transferData3). addInput(details3, spendFrom3, dogAccount.PublicKey). addOutput(dogAmountLeft.ToString(), dogAccount.PublicKey). addOutput(topuppy.ToString(), puppyAccount.PublicKey). addAssets(createTransaction.Data.Id). operation(Operations.TRANSFER). buildAndSignOnly(dogAccount.PublicKey, dogAccount.Key); var transferTransaction4 = await TransactionsApi <Asset <string>, TestToken> .sendTransactionAsync(build4); Thread.Sleep(5000); if (transferTransaction4.Messsage != null) { var msg = transferTransaction4.Messsage.Message; } transferTransaction4.Data.ShouldNotBe(null); if (transferTransaction4 != null) { string tran2 = transferTransaction4.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(tran2); testTran2.ShouldNotBe(null); } // now we feel bad for puppy and want to give puppy another 100 // Describe the output you are fulfilling on the previous transaction FulFill spendFrom5 = new FulFill(); // the asset's ID is equal to the ID of the transaction that created it // last transfer transaction id to dog spendFrom5.TransactionId = transferTransaction3.Data.Id; spendFrom5.OutputIndex = 0; // we want to transfer 100 tokens. int amount5 = 100; Details details5 = null; TestToken transferData5 = new TestToken(); transferData5.token = "To my puppy extra 100"; transferData5.number_tokens = amount5; amountLeft = amountLeft - amount5; // Use the previous transaction's asset and TRANSFER it var build5 = BigchainDbTransactionBuilder <Asset <string>, TestToken> . init(). addMetaData(transferData5). addInput(details5, spendFrom5, publicKeyObj). addOutput(amountLeft.ToString(), publicKeyObj). addOutput(amount5.ToString(), puppyAccount.PublicKey). addAssets(createTransaction.Data.Id). operation(Operations.TRANSFER). buildAndSignOnly(publicKeyObj, privateKeyObj); var transferTransaction5 = await TransactionsApi <Asset <string>, TestToken> .sendTransactionAsync(build5); Thread.Sleep(5000); transferTransaction5.Data.ShouldNotBe(null); if (transferTransaction5 != null) { string tran5 = transferTransaction5.Data.Id; var testTran5 = await TransactionsApi <object, object> .getTransactionByIdAsync(tran5); testTran5.ShouldNotBe(null); } // at this point, puppy has 2 transactions, with 100 tokens each. we want to combine those into Details details6 = null; TestToken transferData6 = new TestToken(); transferData5.token = "Puppy combined account"; transferData5.number_tokens = amount5 + topuppy; // we need to spend 2 previous transactions and create new one FulFill spendFromA = new FulFill(); // the asset's ID is equal to the ID of the transaction that created it spendFromA.TransactionId = transferTransaction4.Data.Id; // list[0].TransactionId; spendFromA.OutputIndex = 1; FulFill spendFromB = new FulFill(); // the asset's ID is equal to the ID of the transaction that created it spendFromB.TransactionId = transferTransaction5.Data.Id; // list[0].TransactionId; spendFromB.OutputIndex = 1; var combinedAmount = amount5 + topuppy; var build6 = BigchainDbTransactionBuilder <Asset <string>, TestToken> . init(). addMetaData(transferData5). addInput(details6, spendFromA, puppyAccount.PublicKey). addInput(details6, spendFromB, puppyAccount.PublicKey). addOutput(combinedAmount.ToString(), puppyAccount.PublicKey). addAssets(createTransaction.Data.Id). operation(Operations.TRANSFER). buildAndSignOnly(puppyAccount.PublicKey, puppyAccount.Key); var transferTransaction6 = await TransactionsApi <Asset <string>, TestToken> .sendTransactionAsync(build6); Thread.Sleep(5000); transferTransaction6.Data.ShouldNotBe(null); transferTransaction6.Data.Outputs[0].Amount.ShouldBe("200"); if (transferTransaction6 != null) { string tran6 = transferTransaction6.Data.Id; var testTran6 = await TransactionsApi <object, object> .getTransactionByIdAsync(tran6); testTran6.ShouldNotBe(null); } }
public async Task testGetTransaction() { Transaction <object, object> transaction = await TransactionsApi <object, object> .getTransactionByIdAsync(TRANSACTION_ID); transaction.Id.ShouldBe(TRANSACTION_ID); }
static void Main(string[] args) { // The code provided will print ‘Hello World’ to the console. // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app. Console.WriteLine("Hello Omnibasis!"); var testTransfer = false; //define connections var conn1Config = new Dictionary <string, object>(); //config connection 1 conn1Config.Add("baseUrl", "https://test.ipdb.io"); BlockchainConnection conn1 = new BlockchainConnection(conn1Config); var conn2Config = new Dictionary <string, object>(); var headers2 = new Dictionary <string, string>(); //config connection 2 conn2Config.Add("baseUrl", "https://test.ipdb.io"); BlockchainConnection conn2 = new BlockchainConnection(conn2Config); //add connections IList <BlockchainConnection> connections = new List <BlockchainConnection>(); connections.Add(conn1); connections.Add(conn2); //...You can add as many nodes as you want //multiple connections var builderWithConnections = BigchainDbConfigBuilder .addConnections(connections) .setTimeout(60000); //override default timeout of 20000 milliseconds // single connection var builder = BigchainDbConfigBuilder .baseUrl("https://test.ipdb.io"); if (!AsyncContext.Run(() => builder.setup())) { Console.WriteLine("Failed to setup"); } ; // prepare your key var algorithm = SignatureAlgorithm.Ed25519; var privateKey = Key.Import(algorithm, Utils.StringToByteArray(privateKeyString), KeyBlobFormat.PkixPrivateKey); var publicKey = PublicKey.Import(algorithm, Utils.StringToByteArray(publicKeyString), KeyBlobFormat.PkixPublicKey); //Account account = new Account(); //Dictionary<string, string> assetData = new Dictionary<string, string>(); //assetData.Add("msg", "Hello!"); Random random = new Random(); TestAsset assetData = new TestAsset(); assetData.msg = "Hello Omnibasis!"; assetData.city = "I was born in San Diego"; assetData.temperature = random.Next(60, 80); assetData.datetime = DateTime.Now; //MetaData metaData = new MetaData(); //metaData.setMetaData("msg", "My first transaction"); TestMetadata metaData = new TestMetadata(); metaData.msg = "My first transaction"; // Set up, sign, and send your transaction var transaction = BigchainDbTransactionBuilder <TestAsset, TestMetadata> .init() .addAssets(assetData) .addMetaData(metaData) .operation(Operations.CREATE) .buildAndSignOnly(publicKey, privateKey); //.buildAndSign(account.PublicKey, account.PrivateKey); //var info = transaction.toHashInput(); var createTransaction = AsyncContext.Run(() => TransactionsApi <TestAsset, TestMetadata> .sendTransactionAsync(transaction)); string assetId2 = ""; // the asset's ID is equal to the ID of the transaction that created it if (createTransaction != null && createTransaction.Data != null) { assetId2 = createTransaction.Data.Id; //"2984ac294290ce6f15124140dad652fc8a306aca62c38237174988dfcf31a3e6" var testTran2 = AsyncContext.Run(() => TransactionsApi <object, object> .getTransactionByIdAsync(assetId2)); if (testTran2 != null) { Console.WriteLine("Hello assetId: " + assetId2); } else { Console.WriteLine("Failed to find assetId: " + assetId2); } } else if (createTransaction != null) { Console.WriteLine("Failed to send transaction: " + createTransaction.Messsage.Message); } //} if (!string.IsNullOrEmpty(assetId2) && testTransfer) { // Describe the output you are fulfilling on the previous transaction FulFill spendFrom = new FulFill(); spendFrom.TransactionId = assetId2; spendFrom.OutputIndex = 0; // Change the metadata if you want //MetaData transferMetadata = new MetaData(); //metaData.setMetaData("msg", "My second transaction"); TestMetadata transferMetadata = new TestMetadata(); transferMetadata.msg = "My second transaction"; // the asset's ID is equal to the ID of the transaction that created it // By default, the 'amount' of a created digital asset == "1". So we spend "1" in our TRANSFER. string amount = "1"; BlockchainAccount account = new BlockchainAccount(); Details details = null; // Use the previous transaction's asset and TRANSFER it var build2 = BigchainDbTransactionBuilder <Asset <string>, TestMetadata> . init(). addMetaData(metaData). addInput(details, spendFrom, publicKey). addOutput("1", account.Key.PublicKey). addAssets(assetId2). operation(Operations.TRANSFER). buildAndSignOnly(publicKey, privateKey); var transferTransaction = AsyncContext.Run(() => TransactionsApi <Asset <string>, TestMetadata> .sendTransactionAsync(build2)); if (transferTransaction != null && transferTransaction.Data != null) { string assetIdTransfer = transferTransaction.Data.Id; var testTran2 = AsyncContext.Run(() => TransactionsApi <object, object> .getTransactionByIdAsync(assetIdTransfer)); if (testTran2 != null) { Console.WriteLine("Hello transfer assetId: " + assetIdTransfer); } else { Console.WriteLine("Failed to find transfer assetId: " + assetIdTransfer); } } else if (transferTransaction != null) { Console.WriteLine("Failed to send transaction: " + createTransaction.Messsage.Message); } } Console.ReadKey(true); // Go to http://aka.ms/dotnet-get-started-console to continue learning how to build a console app! }
static void Main(string[] args) { Console.WriteLine("Hello World!"); //define connections var conn1Config = new Dictionary <string, object>(); //define headers for connections var headers1 = new Dictionary <string, string>(); //config connection 1 conn1Config.Add("baseUrl", "https://test.ipdb.io/"); conn1Config.Add("headers", headers1); BlockchainConnection conn1 = new BlockchainConnection(conn1Config); var conn2Config = new Dictionary <string, object>(); var headers2 = new Dictionary <string, string>(); //config connection 2 conn2Config.Add("baseUrl", "https://test.ipdb.io/"); conn2Config.Add("headers", headers2); BlockchainConnection conn2 = new BlockchainConnection(conn2Config); //add connections IList <BlockchainConnection> connections = new List <BlockchainConnection>(); connections.Add(conn1); connections.Add(conn2); //...You can add as many nodes as you want //multiple connections var builder = BigchainDbConfigBuilder .addConnections(connections) .setTimeout(60000); //override default timeout of 20000 milliseconds // single connection //var builder = BigchainDbConfigBuilder // .baseUrl("https://test.ipdb.io/") // .addToken("app_id", "204d77e0") // .addToken("app_key", "910c0943ce05e76b568395986d3b33d9"); if (!AsyncContext.Run(() => builder.setup())) { Console.WriteLine("Failed to setup"); } ; // prepare your key var algorithm = SignatureAlgorithm.Ed25519; var privateKey = Key.Import(algorithm, Utils.StringToByteArray(privateKeyString), KeyBlobFormat.PkixPrivateKey); var publicKey = PublicKey.Import(algorithm, Utils.StringToByteArray(publicKeyString), KeyBlobFormat.PkixPublicKey); //Account account = new Account(); //Dictionary<string, string> assetData = new Dictionary<string, string>(); //assetData.Add("msg", "Hello!"); TestAsset assetData = new TestAsset(); assetData.msg = "Hello!"; assetData.city = "San Diego"; assetData.temperature = "74"; assetData.datetime = DateTime.Now; //MetaData metaData = new MetaData(); //metaData.setMetaData("msg", "My first transaction"); TestMetadata metaData = new TestMetadata(); metaData.msg = "My first transaction"; var createTransaction2 = AsyncContext.Run(() => TransactionsApi <object, object> .getTransactionByIdAsync("a30a6858185b9382fed0053e51a1e6faae490132c307a7cd488097c12a55b763")); //if(true) //{ // Set up, sign, and send your transaction var transaction = BigchainDbTransactionBuilder <TestAsset, TestMetadata> .init() .addAssets(assetData) .addMetaData(metaData) .operation(Operations.CREATE) .buildAndSignOnly(publicKey, privateKey); //.buildAndSign(account.PublicKey, account.PrivateKey); //var info = transaction.toHashInput(); var createTransaction = AsyncContext.Run(() => TransactionsApi <TestAsset, TestMetadata> .sendTransactionAsync(transaction)); // the asset's ID is equal to the ID of the transaction that created it if (createTransaction != null && createTransaction.Data != null) { string assetId2 = createTransaction.Data.Id; //"2984ac294290ce6f15124140dad652fc8a306aca62c38237174988dfcf31a3e6" var testTran2 = AsyncContext.Run(() => TransactionsApi <object, object> .getTransactionByIdAsync(assetId2)); Console.WriteLine("Hello assetId: " + assetId2); } else { Console.WriteLine("Failed to send transaction"); } //} // Describe the output you are fulfilling on the previous transaction FulFill spendFrom = new FulFill(); spendFrom.TransactionId = createTransaction.Data.Id; spendFrom.OutputIndex = 0; // Change the metadata if you want //MetaData transferMetadata = new MetaData(); //metaData.setMetaData("msg", "My second transaction"); TestMetadata transferMetadata = new TestMetadata(); transferMetadata.msg = "My second transaction"; // the asset's ID is equal to the ID of the transaction that created it // By default, the 'amount' of a created digital asset == "1". So we spend "1" in our TRANSFER. string amount = "1"; BlockchainAccount account = new BlockchainAccount(); Details details = null; // Use the previous transaction's asset and TRANSFER it var build2 = BigchainDbTransactionBuilder <Asset <string>, TestMetadata> . init(). addMetaData(metaData). addInput(details, spendFrom, publicKey). addOutput("1", account.Key.PublicKey). addAssets(createTransaction.Data.Id). operation(Operations.TRANSFER). buildAndSignOnly(publicKey, privateKey); var transferTransaction = AsyncContext.Run(() => TransactionsApi <Asset <string>, TestMetadata> .sendTransactionAsync(build2)); if (transferTransaction != null) { string assetId2 = transferTransaction.Data.Id; //"2984ac294290ce6f15124140dad652fc8a306aca62c38237174988dfcf31a3e6" var testTran2 = AsyncContext.Run(() => TransactionsApi <object, object> .getTransactionByIdAsync(assetId2)); Console.WriteLine("Hello assetId: " + assetId2); } else { Console.WriteLine("Failed to send transaction"); } Console.ReadKey(true); }
public async Task testTokensBuildAndTransferPartingTransaction() { var publicKeyObj = BlockchainAccount.publicKeyFromHex(publicKey); var privateKeyObj = BlockchainAccount.privateKeyFromHex(privateKey); int tokens = 10000; TestToken assetData = new TestToken(); assetData.token = "My Token on" + DateTime.Now.Ticks.ToString(); assetData.number_tokens = tokens; TestMetadata metaData = new TestMetadata(); metaData.msg = "My first transaction"; // Set up, sign, and send your transaction var transaction = BigchainDbTransactionBuilder <TestToken, TestMetadata> .init() .addAssets(assetData) .addMetaData(metaData) .addOutput(tokens.ToString(), publicKeyObj) .operation(Operations.CREATE) .buildAndSignOnly(publicKeyObj, privateKeyObj); //.buildAndSign(account.PublicKey, account.PrivateKey); //var info = transaction.toHashInput(); var createTransaction = await TransactionsApi <TestToken, TestMetadata> .sendTransactionAsync(transaction); createTransaction.Data.ShouldNotBe(null); // the asset's ID is equal to the ID of the transaction that created it if (createTransaction.Data != null) { string testId2 = createTransaction.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(testId2); testTran2.ShouldNotBe(null); } // Describe the output you are fulfilling on the previous transaction FulFill spendFrom = new FulFill(); // the asset's ID is equal to the ID of the transaction that created it spendFrom.TransactionId = createTransaction.Data.Id; spendFrom.OutputIndex = 0; // we want to transfer 200 tokens. int amount = 200; //int amountFake = 20000; BlockchainAccount account = new BlockchainAccount(); Details details = null; TestToken transferData = new TestToken(); assetData.token = "To my cat"; assetData.number_tokens = amount; int amountLeft = tokens - amount; // Use the previous transaction's asset and TRANSFER it var build2 = BigchainDbTransactionBuilder <Asset <string>, TestToken> . init(). addMetaData(transferData). addInput(details, spendFrom, publicKeyObj). addOutput(amountLeft.ToString(), publicKeyObj). addOutput(amount.ToString(), account.PublicKey). addAssets(createTransaction.Data.Id). operation(Operations.TRANSFER). buildAndSignOnly(publicKeyObj, privateKeyObj); var transferTransaction = await TransactionsApi <Asset <string>, TestToken> .sendTransactionAsync(build2); transferTransaction.Data.ShouldNotBe(null); if (transferTransaction != null) { string tran2 = transferTransaction.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(tran2); testTran2.ShouldNotBe(null); } var useThisKey = transferTransaction.Data.Outputs[0].PublicKeys[0]; var compKey = KeyPairUtils.encodePublicKeyInBase58(publicKeyObj); // get unspent outputs var list = await OutputsApi.getUnspentOutputsAsync(useThisKey); //list.Count.ShouldBe(1); // Describe the output you are fulfilling on spent outputs FulFill spendFrom2 = new FulFill(); // the asset's ID is equal to the ID of the transaction that created it spendFrom2.TransactionId = transferTransaction.Data.Id; // list[0].TransactionId; spendFrom2.OutputIndex = 0; BlockchainAccount dogAccount = new BlockchainAccount(); Details details2 = null; TestToken transferData2 = new TestToken(); transferData2.token = "To my dog"; transferData2.number_tokens = amount; amountLeft = amountLeft - amount; // Use the previous transaction's asset and TRANSFER it var build3 = BigchainDbTransactionBuilder <Asset <string>, TestToken> . init(). addMetaData(transferData2). addInput(details2, spendFrom2, publicKeyObj). addOutput(amountLeft.ToString(), publicKeyObj). addOutput(amount.ToString(), dogAccount.PublicKey). addAssets(createTransaction.Data.Id). operation(Operations.TRANSFER). buildAndSignOnly(publicKeyObj, privateKeyObj); var transferTransaction3 = await TransactionsApi <Asset <string>, TestToken> .sendTransactionAsync(build3); transferTransaction3.Data.ShouldNotBe(null); if (transferTransaction3 != null) { string tran2 = transferTransaction3.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(tran2); testTran2.ShouldNotBe(null); } //// Describe the output you are fulfilling on spent outputs //FulFill spendFrom2a = new FulFill(); //// the asset's ID is equal to the ID of the transaction that created it //spendFrom2a.TransactionId = transferTransaction3.Data.Id; // list[0].TransactionId; //spendFrom2a.OutputIndex = 0; //Details details2a = null; //TestToken transferData2a = new TestToken(); //transferData2a.token = "To my dog named Bingo"; //transferData2a.number_tokens = amount; //// Use the previous transaction's asset and TRANSFER it //var build3a = BigchainDbTransactionBuilder<Asset<string>, TestToken>. // init(). // addMetaData(transferData2a). // addInput(details2a, spendFrom2a, dogAccount.PublicKey). // addOutput(amountLeft.ToString(), publicKeyObj). // addOutput(amount.ToString(), dogAccount.PublicKey). // addAssets(createTransaction.Data.Id). // operation(Operations.TRANSFER). // buildAndSignOnly(dogAccount.PublicKey, dogAccount.Key); //var transferTransaction3a = await TransactionsApi<Asset<string>, TestToken>.sendTransactionAsync(build3a); //transferTransaction3.Data.ShouldNotBe(null); //if (transferTransaction3 != null) //{ // string tran2 = transferTransaction3.Data.Id; // var testTran2 = await TransactionsApi<object, object>.getTransactionByIdAsync(tran2); // testTran2.ShouldNotBe(null); //} // now dog wants to share with puppy BlockchainAccount puppyAccount = new BlockchainAccount(); Details details3 = null; TestToken transferData3 = new TestToken(); transferData3.token = "To my puppy"; int topuppy = 100; transferData3.number_tokens = topuppy; FulFill spendFrom3 = new FulFill(); // the asset's ID is equal to the ID of the transaction that created it spendFrom3.TransactionId = transferTransaction3.Data.Id; // list[0].TransactionId; spendFrom3.OutputIndex = 1; amountLeft = amount - topuppy; // Use the previous transaction's asset and TRANSFER it var build4 = BigchainDbTransactionBuilder <Asset <string>, TestToken> . init(). addMetaData(transferData3). addInput(details3, spendFrom3, dogAccount.PublicKey). addOutput(amountLeft.ToString(), dogAccount.PublicKey). addOutput(topuppy.ToString(), puppyAccount.PublicKey). addAssets(createTransaction.Data.Id). operation(Operations.TRANSFER). buildAndSignOnly(dogAccount.PublicKey, dogAccount.Key); var transferTransaction4 = await TransactionsApi <Asset <string>, TestToken> .sendTransactionAsync(build4); if (transferTransaction4.Messsage != null) { var msg = transferTransaction4.Messsage.Message; } transferTransaction4.Data.ShouldNotBe(null); if (transferTransaction4 != null) { string tran2 = transferTransaction4.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(tran2); testTran2.ShouldNotBe(null); } }
public async Task testBuildAndTransferPartingTransaction() { var publicKeyObj = BlockchainAccount.publicKeyFromHex(publicKey); var privateKeyObj = BlockchainAccount.privateKeyFromHex(privateKey); TestAsset assetData = new TestAsset(); assetData.msg = "Hello!"; assetData.city = "San Diego"; assetData.temperature = "74"; assetData.datetime = DateTime.Now; TestMetadata metaData = new TestMetadata(); metaData.msg = "My first transaction"; // Set up, sign, and send your transaction var transaction = BigchainDbTransactionBuilder <TestAsset, TestMetadata> .init() .addAssets(assetData) .addMetaData(metaData) .operation(Operations.CREATE) .buildAndSignOnly(publicKeyObj, privateKeyObj); //.buildAndSign(account.PublicKey, account.PrivateKey); //var info = transaction.toHashInput(); var createTransaction = await TransactionsApi <TestAsset, TestMetadata> .sendTransactionAsync(transaction); createTransaction.Data.ShouldNotBe(null); // the asset's ID is equal to the ID of the transaction that created it if (createTransaction != null) { string testId2 = createTransaction.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(testId2); testTran2.ShouldNotBe(null); } // Describe the output you are fulfilling on the previous transaction FulFill spendFrom = new FulFill(); // the asset's ID is equal to the ID of the transaction that created it spendFrom.TransactionId = createTransaction.Data.Id; spendFrom.OutputIndex = 0; // Change the metadata if you want TestMetadata transferMetadata = new TestMetadata(); transferMetadata.msg = "My second transaction"; // By default, the 'amount' of a created digital asset == "1". So we spend "1" in our TRANSFER. string amount = "1"; BlockchainAccount account = new BlockchainAccount(); Details details = null; // Use the previous transaction's asset and TRANSFER it var build2 = BigchainDbTransactionBuilder <Asset <string>, TestMetadata> . init(). addMetaData(transferMetadata). addInput(details, spendFrom, publicKeyObj). addOutput(amount, account.Key.PublicKey). addAssets(createTransaction.Data.Id). operation(Operations.TRANSFER). buildAndSignOnly(publicKeyObj, privateKeyObj); var transferTransaction = await TransactionsApi <Asset <string>, TestMetadata> .sendTransactionAsync(build2); transferTransaction.Data.ShouldNotBe(null); if (transferTransaction != null) { string tran2 = transferTransaction.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(tran2); testTran2.ShouldNotBe(null); } }
public async Task testBuildAndTransferPartingTransaction() { var publicKeyObj = BlockchainAccount.publicKeyFromHex(publicKey); var privateKeyObj = BlockchainAccount.privateKeyFromHex(privateKey); Vehicle car = new Vehicle(); car.id = "92832938203903" + DateTime.Now.ToLongDateString(); car.consumption = "20.9"; // Set up, sign, and send your transaction var transaction = BigchainDbTransactionBuilder <Vehicle, object> .init() .addAssets(car) .operation(Operations.CREATE) .buildAndSignOnly(publicKeyObj, privateKeyObj); //.buildAndSign(account.PublicKey, account.PrivateKey); //var info = transaction.toHashInput(); var createTransaction = await TransactionsApi <Vehicle, object> .sendTransactionAsync(transaction); createTransaction.Data.ShouldNotBe(null); // the asset's ID is equal to the ID of the transaction that created it if (createTransaction != null) { string testId2 = createTransaction.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(testId2); testTran2.ShouldNotBe(null); } // Describe the output you are fulfilling on the previous transaction FulFill spendFrom = new FulFill(); // the asset's ID is equal to the ID of the transaction that created it spendFrom.TransactionId = createTransaction.Data.Id; spendFrom.OutputIndex = 0; Mileage m = new Mileage(); m.Amount = "2000"; // By default, the 'amount' of a created digital asset == "1". So we spend "1" in our TRANSFER. string amount = "1"; Details details = null; // Use the previous transaction's asset and TRANSFER it var build2 = BigchainDbTransactionBuilder <Mileage, object> . init(). addInput(details, spendFrom, publicKeyObj). addOutput(amount, publicKeyObj). addAssets(createTransaction.Data.Id). operation(Operations.TRANSFER). buildAndSignOnly(publicKeyObj, privateKeyObj); var transferTransaction = await TransactionsApi <Mileage, object> .sendTransactionAsync(build2); transferTransaction.Data.ShouldNotBe(null); if (transferTransaction != null) { string tran2 = transferTransaction.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(tran2); testTran2.ShouldNotBe(null); } }