コード例 #1
0
        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"));
            }
        }
コード例 #2
0
        public BigChainDbService(string[] urls)
        {
            // Create a list of connections
            List <BlockchainConnection> connections = new List <BlockchainConnection>();

            Console.WriteLine("NodeURLs: ");
            Random rnd = new Random();

            string[] MyRandomArray = urls.OrderBy(x => rnd.Next()).ToArray();
            foreach (var url in MyRandomArray)
            {
                // print urls that we're connecting to
                Console.WriteLine(url);

                var conn_conf = new Dictionary <string, object>();
                conn_conf.Add("baseUrl", "https://" + url);
                BlockchainConnection bc_conn = new BlockchainConnection(conn_conf);
                connections.Add(bc_conn);
            }
            var builder = BigchainDbConfigBuilder
                          .addConnections(connections)
                          .setTimeout(60000);

            if (!AsyncContext.Run(() => builder.setup()))
            {
                Console.WriteLine("Failed Multi-Node Setup");
            }
            var baseURL = builder.BaseUrl.Split("/")[2];;

            Console.WriteLine("Finished connecting to multiple nodes");
            var client = new MongoClient($"mongodb://*****:*****@{baseURL}:27017/?authSource=bigchain");

            bigchainDatabase = client.GetDatabase("bigchain");
            ipfs             = new IpfsClient("http://" + baseURL + ":5001");
            return;
        }
コード例 #3
0
        private void setUp()
        {
            //setup mock node 1


            bdbNode1 = FluentMockServer.Start(9191);
            Console.WriteLine("port1 - 9191");

            //setup mock node 2
            bdbNode2 = FluentMockServer.Start(9192);
            Console.WriteLine("port2 - 9192");

            //set up mock node 3
            bdbNode3 = FluentMockServer.Start(9193);
            Console.WriteLine("port3 - 9193");

            //define headers
            headers["app_id"]  = "";
            headers["app_key"] = "";

            conn1Config["baseUrl"] = server1;
            conn1Config["headers"] = headers;
            BlockchainConnection conn1 = new BlockchainConnection(conn1Config);

            conn2Config["baseUrl"] = server2;
            conn2Config["headers"] = headers;
            BlockchainConnection conn2 = new BlockchainConnection(conn2Config);

            conn3Config["baseUrl"] = server3;
            conn3Config["headers"] = headers;
            BlockchainConnection conn3 = new BlockchainConnection(conn3Config);

            connections.Add(conn1);
            connections.Add(conn2);
            connections.Add(conn3);
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("Id,HolderFullName,DateOfIssue,TransactionId,CourseName")] SignedDiploma signedDiploma)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //Sign the transaction to the blockchain
                    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();

                    // 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);

                    BlockchainTransaction assetData = new BlockchainTransaction();
                    assetData.HoldersName = signedDiploma.HolderFullName;
                    assetData.DateOfIssue = signedDiploma.DateOfIssue;
                    assetData.CourseName  = signedDiploma.CourseName;

                    //TestMetadata metaData = new TestMetadata();
                    TransactionsMetadata metaData = new TransactionsMetadata();
                    string externalip             = new WebClient().DownloadString("http://icanhazip.com");
                    metaData.SignerIP = externalip;

                    // Set up, sign, and send your transaction
                    var transaction = BigchainDbTransactionBuilder <BlockchainTransaction, TransactionsMetadata>
                                      .init()
                                      .addAssets(assetData)
                                      .addMetaData(metaData)
                                      .operation(Operations.CREATE)
                                      .buildAndSignOnly(publicKey, privateKey);

                    var createTransaction = await TransactionsApi <BlockchainTransaction, TransactionsMetadata> .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;
                        signedDiploma.TransactionId = assetId2;
                        _context.SignedDiplomas.Add(signedDiploma);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    else if (createTransaction != null)
                    {
                        return(Content("Could not send it: " + createTransaction.Messsage.Message));
                    }
                }
                catch (Exception e)
                {
                    return(Content(e.ToString()));
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
コード例 #5
0
        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!
        }
コード例 #6
0
        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);
        }