├── .gitattributes ├── .gitignore ├── BigchainCSharp.sln ├── BigchainCSharp_SimpleTest ├── App.config ├── BigchainCSharp_SimpleTest.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── TestAsset.cs └── TestMetadata.cs ├── BigchainCSharp_Test ├── App.config ├── BigchainCSharp_Test.csproj ├── Program.cs ├── TestAsset.cs └── TestMetadata.cs ├── BigchainCSharp_WS_Test ├── BigchainCSharp_WS_Test.csproj ├── Program.cs └── ValidTransactionMessageHandler.cs ├── BigchainCSharp_XUnitTest ├── AccountApiTest.cs ├── AppTestBase.cs ├── AssetsApiTest.cs ├── BigchainCSharp_XUnitTest.csproj ├── BigchainDBConnectionManagerTest.cs ├── BlocksApiTest.cs ├── MetaDataApiTest.cs ├── OutputsApiTest.cs ├── TransactionCombineViaTransferApiTest.cs ├── TransactionCreateApiTest.cs ├── TransactionTransferApiTest.cs ├── TransactionUpdateApiTest.cs ├── ValidatorsApiTest.cs └── appsettings.json └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /BigchainCSharp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BigchainCSharp_Test", "BigchainCSharp_Test\BigchainCSharp_Test.csproj", "{5195501C-E13C-48C6-92DB-384D68E08510}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BigchainCSharp_XUnitTest", "BigchainCSharp_XUnitTest\BigchainCSharp_XUnitTest.csproj", "{D773A5ED-0B83-4F74-AF1F-C72D0CAF9F92}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BigchainCSharp_WS_Test", "BigchainCSharp_WS_Test\BigchainCSharp_WS_Test.csproj", "{DA1A0E20-E068-4EDE-8CE1-6246CB5155FC}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BigchainCSharp_SimpleTest", "BigchainCSharp_SimpleTest\BigchainCSharp_SimpleTest.csproj", "{154EEF65-F94F-43A8-9B12-80E26E33ED72}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DEDE4B33-FB6F-4AFE-A00E-87029DE77D11}" 15 | ProjectSection(SolutionItems) = preProject 16 | README.md = README.md 17 | EndProjectSection 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|Any CPU = Debug|Any CPU 22 | Debug|x64 = Debug|x64 23 | Release|Any CPU = Release|Any CPU 24 | Release|x64 = Release|x64 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {5195501C-E13C-48C6-92DB-384D68E08510}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {5195501C-E13C-48C6-92DB-384D68E08510}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {5195501C-E13C-48C6-92DB-384D68E08510}.Debug|x64.ActiveCfg = Debug|Any CPU 30 | {5195501C-E13C-48C6-92DB-384D68E08510}.Debug|x64.Build.0 = Debug|Any CPU 31 | {5195501C-E13C-48C6-92DB-384D68E08510}.Release|Any CPU.ActiveCfg = Release|Any CPU 32 | {5195501C-E13C-48C6-92DB-384D68E08510}.Release|Any CPU.Build.0 = Release|Any CPU 33 | {5195501C-E13C-48C6-92DB-384D68E08510}.Release|x64.ActiveCfg = Release|Any CPU 34 | {5195501C-E13C-48C6-92DB-384D68E08510}.Release|x64.Build.0 = Release|Any CPU 35 | {D773A5ED-0B83-4F74-AF1F-C72D0CAF9F92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {D773A5ED-0B83-4F74-AF1F-C72D0CAF9F92}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {D773A5ED-0B83-4F74-AF1F-C72D0CAF9F92}.Debug|x64.ActiveCfg = Debug|Any CPU 38 | {D773A5ED-0B83-4F74-AF1F-C72D0CAF9F92}.Debug|x64.Build.0 = Debug|Any CPU 39 | {D773A5ED-0B83-4F74-AF1F-C72D0CAF9F92}.Release|Any CPU.ActiveCfg = Release|Any CPU 40 | {D773A5ED-0B83-4F74-AF1F-C72D0CAF9F92}.Release|Any CPU.Build.0 = Release|Any CPU 41 | {D773A5ED-0B83-4F74-AF1F-C72D0CAF9F92}.Release|x64.ActiveCfg = Release|Any CPU 42 | {D773A5ED-0B83-4F74-AF1F-C72D0CAF9F92}.Release|x64.Build.0 = Release|Any CPU 43 | {DA1A0E20-E068-4EDE-8CE1-6246CB5155FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {DA1A0E20-E068-4EDE-8CE1-6246CB5155FC}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {DA1A0E20-E068-4EDE-8CE1-6246CB5155FC}.Debug|x64.ActiveCfg = Debug|Any CPU 46 | {DA1A0E20-E068-4EDE-8CE1-6246CB5155FC}.Debug|x64.Build.0 = Debug|Any CPU 47 | {DA1A0E20-E068-4EDE-8CE1-6246CB5155FC}.Release|Any CPU.ActiveCfg = Release|Any CPU 48 | {DA1A0E20-E068-4EDE-8CE1-6246CB5155FC}.Release|Any CPU.Build.0 = Release|Any CPU 49 | {DA1A0E20-E068-4EDE-8CE1-6246CB5155FC}.Release|x64.ActiveCfg = Release|Any CPU 50 | {DA1A0E20-E068-4EDE-8CE1-6246CB5155FC}.Release|x64.Build.0 = Release|Any CPU 51 | {154EEF65-F94F-43A8-9B12-80E26E33ED72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 52 | {154EEF65-F94F-43A8-9B12-80E26E33ED72}.Debug|Any CPU.Build.0 = Debug|Any CPU 53 | {154EEF65-F94F-43A8-9B12-80E26E33ED72}.Debug|x64.ActiveCfg = Debug|x64 54 | {154EEF65-F94F-43A8-9B12-80E26E33ED72}.Debug|x64.Build.0 = Debug|x64 55 | {154EEF65-F94F-43A8-9B12-80E26E33ED72}.Release|Any CPU.ActiveCfg = Release|Any CPU 56 | {154EEF65-F94F-43A8-9B12-80E26E33ED72}.Release|Any CPU.Build.0 = Release|Any CPU 57 | {154EEF65-F94F-43A8-9B12-80E26E33ED72}.Release|x64.ActiveCfg = Release|x64 58 | {154EEF65-F94F-43A8-9B12-80E26E33ED72}.Release|x64.Build.0 = Release|x64 59 | EndGlobalSection 60 | GlobalSection(SolutionProperties) = preSolution 61 | HideSolutionNode = FALSE 62 | EndGlobalSection 63 | GlobalSection(ExtensibilityGlobals) = postSolution 64 | SolutionGuid = {5AB6DDAE-6891-47BD-B91B-A50F3DD551E2} 65 | EndGlobalSection 66 | EndGlobal 67 | -------------------------------------------------------------------------------- /BigchainCSharp_SimpleTest/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /BigchainCSharp_SimpleTest/BigchainCSharp_SimpleTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {154EEF65-F94F-43A8-9B12-80E26E33ED72} 8 | Exe 9 | BigchainCSharp_SimpleTest 10 | BigchainCSharp_SimpleTest 11 | v4.7.2 12 | 512 13 | true 14 | 15 | 16 | 17 | x64 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | true 37 | bin\x64\Debug\ 38 | DEBUG;TRACE 39 | full 40 | x64 41 | prompt 42 | MinimumRecommendedRules.ruleset 43 | true 44 | 45 | 46 | bin\x64\Release\ 47 | TRACE 48 | true 49 | pdbonly 50 | x64 51 | prompt 52 | MinimumRecommendedRules.ruleset 53 | true 54 | 55 | 56 | 57 | ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll 58 | 59 | 60 | ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll 61 | True 62 | True 63 | 64 | 65 | ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll 66 | 67 | 68 | ..\packages\Nito.AsyncEx.Context.1.1.0\lib\net46\Nito.AsyncEx.Context.dll 69 | 70 | 71 | ..\packages\Nito.AsyncEx.Tasks.1.1.0\lib\net46\Nito.AsyncEx.Tasks.dll 72 | 73 | 74 | ..\packages\Nito.Disposables.1.0.0\lib\portable45-net45+win8+wp8+wpa81\Nito.Disposables.dll 75 | 76 | 77 | ..\packages\NSec.Cryptography.18.6.0\lib\netstandard1.1\NSec.Cryptography.dll 78 | 79 | 80 | 81 | ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll 82 | True 83 | True 84 | 85 | 86 | ..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll 87 | 88 | 89 | 90 | ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll 91 | True 92 | True 93 | 94 | 95 | 96 | ..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll 97 | 98 | 99 | ..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll 100 | True 101 | True 102 | 103 | 104 | ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll 105 | True 106 | True 107 | 108 | 109 | 110 | ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll 111 | True 112 | True 113 | 114 | 115 | ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll 116 | True 117 | True 118 | 119 | 120 | ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll 121 | True 122 | True 123 | 124 | 125 | ..\packages\System.Memory.4.5.0\lib\netstandard2.0\System.Memory.dll 126 | 127 | 128 | ..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll 129 | True 130 | True 131 | 132 | 133 | ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll 134 | True 135 | True 136 | 137 | 138 | 139 | ..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll 140 | 141 | 142 | ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll 143 | 144 | 145 | ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll 146 | True 147 | True 148 | 149 | 150 | ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll 151 | True 152 | True 153 | 154 | 155 | ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll 156 | True 157 | True 158 | 159 | 160 | ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll 161 | True 162 | True 163 | 164 | 165 | ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll 166 | True 167 | True 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll 176 | True 177 | True 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 1.0.17.1 192 | 193 | 194 | 5.0.0 195 | 196 | 197 | 1.0.1 198 | 199 | 200 | 201 | -------------------------------------------------------------------------------- /BigchainCSharp_SimpleTest/Program.cs: -------------------------------------------------------------------------------- 1 | using Nito.AsyncEx; 2 | using NSec.Cryptography; 3 | using Omnibasis.BigchainCSharp.Api; 4 | using Omnibasis.BigchainCSharp.Builders; 5 | using Omnibasis.BigchainCSharp.Constants; 6 | using Omnibasis.BigchainCSharp.Model; 7 | using Omnibasis.BigchainCSharp.Util; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | 14 | namespace BigchainCSharp_SimpleTest 15 | { 16 | class Program 17 | { 18 | private static String publicKeyString = "302a300506032b657003210033c43dc2180936a2a9138a05f06c892d2fb1cfda4562cbc35373bf13cd8ed373"; 19 | private static String privateKeyString = "302e020100300506032b6570042204206f6b0cd095f1e83fc5f08bffb79c7c8a30e77a3ab65f4bc659026b76394fcea8"; 20 | 21 | static void Main(string[] args) 22 | { 23 | 24 | // The code provided will print ‘Hello World’ to the console. 25 | // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app. 26 | Console.WriteLine("Hello Omnibasis!"); 27 | 28 | var testTransfer = false; 29 | //define connections 30 | var conn1Config = new Dictionary(); 31 | 32 | //config connection 1 33 | conn1Config.Add("baseUrl", "https://test.ipdb.io"); 34 | BlockchainConnection conn1 = new BlockchainConnection(conn1Config); 35 | 36 | var conn2Config = new Dictionary(); 37 | var headers2 = new Dictionary(); 38 | //config connection 2 39 | conn2Config.Add("baseUrl", "https://test.ipdb.io"); 40 | BlockchainConnection conn2 = new BlockchainConnection(conn2Config); 41 | 42 | //add connections 43 | IList connections = new List(); 44 | connections.Add(conn1); 45 | connections.Add(conn2); 46 | //...You can add as many nodes as you want 47 | 48 | //multiple connections 49 | var builderWithConnections = BigchainDbConfigBuilder 50 | .addConnections(connections) 51 | .setTimeout(60000); //override default timeout of 20000 milliseconds 52 | 53 | // single connection 54 | var builder = BigchainDbConfigBuilder 55 | .baseUrl("https://test.ipdb.io"); 56 | 57 | if (!AsyncContext.Run(() => builder.setup())) 58 | { 59 | Console.WriteLine("Failed to setup"); 60 | }; 61 | 62 | // prepare your key 63 | var algorithm = SignatureAlgorithm.Ed25519; 64 | var privateKey = Key.Import(algorithm, Utils.StringToByteArray(privateKeyString), KeyBlobFormat.PkixPrivateKey); 65 | var publicKey = PublicKey.Import(algorithm, Utils.StringToByteArray(publicKeyString), KeyBlobFormat.PkixPublicKey); 66 | //Account account = new Account(); 67 | 68 | //Dictionary assetData = new Dictionary(); 69 | //assetData.Add("msg", "Hello!"); 70 | 71 | Random random = new Random(); 72 | TestAsset assetData = new TestAsset(); 73 | assetData.msg = "Hello Omnibasis!"; 74 | assetData.city = "I was born in San Diego"; 75 | assetData.temperature = random.Next(60, 80); 76 | assetData.datetime = DateTime.Now; 77 | 78 | //MetaData metaData = new MetaData(); 79 | //metaData.setMetaData("msg", "My first transaction"); 80 | TestMetadata metaData = new TestMetadata(); 81 | metaData.msg = "My first transaction"; 82 | 83 | // Set up, sign, and send your transaction 84 | var transaction = BigchainDbTransactionBuilder 85 | .init() 86 | .addAssets(assetData) 87 | .addMetaData(metaData) 88 | .operation(Operations.CREATE) 89 | .buildAndSignOnly(publicKey, privateKey); 90 | //.buildAndSign(account.PublicKey, account.PrivateKey); 91 | 92 | //var info = transaction.toHashInput(); 93 | var createTransaction = AsyncContext.Run(() => TransactionsApi.sendTransactionAsync(transaction)); 94 | string assetId2 = ""; 95 | // the asset's ID is equal to the ID of the transaction that created it 96 | if (createTransaction != null && createTransaction.Data != null) 97 | { 98 | assetId2 = createTransaction.Data.Id; 99 | //"2984ac294290ce6f15124140dad652fc8a306aca62c38237174988dfcf31a3e6" 100 | var testTran2 = AsyncContext.Run(() => TransactionsApi.getTransactionByIdAsync(assetId2)); 101 | if(testTran2 != null) 102 | Console.WriteLine("Hello assetId: " + assetId2); 103 | else 104 | Console.WriteLine("Failed to find assetId: " + assetId2); 105 | 106 | } 107 | else if (createTransaction != null) 108 | { 109 | Console.WriteLine("Failed to send transaction: " + createTransaction.Messsage.Message); 110 | } 111 | 112 | 113 | //} 114 | if(!string.IsNullOrEmpty(assetId2) && testTransfer) 115 | { 116 | // Describe the output you are fulfilling on the previous transaction 117 | FulFill spendFrom = new FulFill(); 118 | spendFrom.TransactionId = assetId2; 119 | spendFrom.OutputIndex = 0; 120 | 121 | // Change the metadata if you want 122 | //MetaData transferMetadata = new MetaData(); 123 | //metaData.setMetaData("msg", "My second transaction"); 124 | TestMetadata transferMetadata = new TestMetadata(); 125 | transferMetadata.msg = "My second transaction"; 126 | 127 | // the asset's ID is equal to the ID of the transaction that created it 128 | // By default, the 'amount' of a created digital asset == "1". So we spend "1" in our TRANSFER. 129 | string amount = "1"; 130 | BlockchainAccount account = new BlockchainAccount(); 131 | Details details = null; 132 | // Use the previous transaction's asset and TRANSFER it 133 | var build2 = BigchainDbTransactionBuilder, TestMetadata>. 134 | init(). 135 | addMetaData(metaData). 136 | addInput(details, spendFrom, publicKey). 137 | addOutput("1", account.Key.PublicKey). 138 | addAssets(assetId2). 139 | operation(Operations.TRANSFER). 140 | buildAndSignOnly(publicKey, privateKey); 141 | 142 | var transferTransaction = AsyncContext.Run(() => TransactionsApi, TestMetadata>.sendTransactionAsync(build2)); 143 | 144 | if (transferTransaction != null && transferTransaction.Data != null) 145 | { 146 | string assetIdTransfer = transferTransaction.Data.Id; 147 | var testTran2 = AsyncContext.Run(() => TransactionsApi.getTransactionByIdAsync(assetIdTransfer)); 148 | if (testTran2 != null) 149 | Console.WriteLine("Hello transfer assetId: " + assetIdTransfer); 150 | else 151 | Console.WriteLine("Failed to find transfer assetId: " + assetIdTransfer); 152 | 153 | } 154 | else if (transferTransaction != null) 155 | { 156 | Console.WriteLine("Failed to send transaction: " + createTransaction.Messsage.Message); 157 | } 158 | 159 | } 160 | 161 | 162 | Console.ReadKey(true); 163 | 164 | // Go to http://aka.ms/dotnet-get-started-console to continue learning how to build a console app! 165 | 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /BigchainCSharp_SimpleTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BigchainCSharp_SimpleTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BigchainCSharp_SimpleTest")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("154eef65-f94f-43a8-9b12-80e26e33ed72")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /BigchainCSharp_SimpleTest/TestAsset.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | [Serializable] 7 | public class TestAsset 8 | { 9 | [JsonProperty] 10 | public string msg { get; set; } 11 | [JsonProperty] 12 | public string city { get; set; } 13 | [JsonProperty] 14 | public int temperature { get; set; } 15 | [JsonProperty] 16 | public DateTime datetime { get; set; } 17 | } 18 | -------------------------------------------------------------------------------- /BigchainCSharp_SimpleTest/TestMetadata.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | [Serializable] 7 | public class TestMetadata 8 | { 9 | [JsonProperty] 10 | public string msg { get; set; } 11 | } 12 | -------------------------------------------------------------------------------- /BigchainCSharp_Test/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /BigchainCSharp_Test/BigchainCSharp_Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | BigchainCSharp_Test 7 | BigchainCSharp_Test 8 | Omnibasis.BigchainCSharp_Test.Program 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /BigchainCSharp_Test/Program.cs: -------------------------------------------------------------------------------- 1 | using Nito.AsyncEx; 2 | using NSec.Cryptography; 3 | using Omnibasis.BigchainCSharp.Api; 4 | using Omnibasis.BigchainCSharp.Builders; 5 | using Omnibasis.BigchainCSharp.Constants; 6 | using Omnibasis.BigchainCSharp.Model; 7 | using Omnibasis.BigchainCSharp.Util; 8 | using System; 9 | using System.Collections.Generic; 10 | 11 | namespace Omnibasis.BigchainCSharp_Test 12 | { 13 | class Program 14 | { 15 | private static String publicKeyString = "302a300506032b657003210033c43dc2180936a2a9138a05f06c892d2fb1cfda4562cbc35373bf13cd8ed373"; 16 | private static String privateKeyString = "302e020100300506032b6570042204206f6b0cd095f1e83fc5f08bffb79c7c8a30e77a3ab65f4bc659026b76394fcea8"; 17 | 18 | 19 | static void Main(string[] args) 20 | { 21 | Console.WriteLine("Hello World!"); 22 | //define connections 23 | var conn1Config = new Dictionary(); 24 | 25 | //define headers for connections 26 | var headers1 = new Dictionary(); 27 | 28 | //config connection 1 29 | conn1Config.Add("baseUrl", "https://test.ipdb.io/"); 30 | conn1Config.Add("headers", headers1); 31 | BlockchainConnection conn1 = new BlockchainConnection(conn1Config); 32 | 33 | var conn2Config = new Dictionary(); 34 | var headers2 = new Dictionary(); 35 | //config connection 2 36 | conn2Config.Add("baseUrl", "https://test.ipdb.io/"); 37 | conn2Config.Add("headers", headers2); 38 | BlockchainConnection conn2 = new BlockchainConnection(conn2Config); 39 | 40 | //add connections 41 | IList connections = new List(); 42 | connections.Add(conn1); 43 | connections.Add(conn2); 44 | //...You can add as many nodes as you want 45 | 46 | //multiple connections 47 | var builder = BigchainDbConfigBuilder 48 | .addConnections(connections) 49 | .setTimeout(60000); //override default timeout of 20000 milliseconds 50 | 51 | // single connection 52 | //var builder = BigchainDbConfigBuilder 53 | // .baseUrl("https://test.ipdb.io/") 54 | // .addToken("app_id", "204d77e0") 55 | // .addToken("app_key", "910c0943ce05e76b568395986d3b33d9"); 56 | 57 | if (!AsyncContext.Run(() => builder.setup())) 58 | { 59 | Console.WriteLine("Failed to setup"); 60 | }; 61 | 62 | // prepare your key 63 | var algorithm = SignatureAlgorithm.Ed25519; 64 | var privateKey = Key.Import(algorithm, Utils.StringToByteArray(privateKeyString), KeyBlobFormat.PkixPrivateKey); 65 | var publicKey = PublicKey.Import(algorithm, Utils.StringToByteArray(publicKeyString), KeyBlobFormat.PkixPublicKey); 66 | //Account account = new Account(); 67 | 68 | //Dictionary assetData = new Dictionary(); 69 | //assetData.Add("msg", "Hello!"); 70 | 71 | TestAsset assetData = new TestAsset(); 72 | assetData.msg = "Hello!"; 73 | assetData.city = "San Diego"; 74 | assetData.temperature = "74"; 75 | assetData.datetime = DateTime.Now; 76 | 77 | //MetaData metaData = new MetaData(); 78 | //metaData.setMetaData("msg", "My first transaction"); 79 | TestMetadata metaData = new TestMetadata(); 80 | metaData.msg = "My first transaction"; 81 | 82 | var createTransaction2 = AsyncContext.Run(() => TransactionsApi 83 | .getTransactionByIdAsync("a30a6858185b9382fed0053e51a1e6faae490132c307a7cd488097c12a55b763")); 84 | 85 | //if(true) 86 | //{ 87 | // Set up, sign, and send your transaction 88 | var transaction = BigchainDbTransactionBuilder 89 | .init() 90 | .addAssets(assetData) 91 | .addMetaData(metaData) 92 | .operation(Operations.CREATE) 93 | .buildAndSignOnly(publicKey, privateKey); 94 | //.buildAndSign(account.PublicKey, account.PrivateKey); 95 | 96 | //var info = transaction.toHashInput(); 97 | var createTransaction = AsyncContext.Run(() => TransactionsApi.sendTransactionAsync(transaction)); 98 | 99 | // the asset's ID is equal to the ID of the transaction that created it 100 | if (createTransaction != null && createTransaction.Data != null) 101 | { 102 | string assetId2 = createTransaction.Data.Id; 103 | //"2984ac294290ce6f15124140dad652fc8a306aca62c38237174988dfcf31a3e6" 104 | var testTran2 = AsyncContext.Run(() => TransactionsApi.getTransactionByIdAsync(assetId2)); 105 | Console.WriteLine("Hello assetId: " + assetId2); 106 | 107 | } 108 | else 109 | { 110 | Console.WriteLine("Failed to send transaction"); 111 | } 112 | 113 | 114 | //} 115 | 116 | // Describe the output you are fulfilling on the previous transaction 117 | FulFill spendFrom = new FulFill(); 118 | spendFrom.TransactionId = createTransaction.Data.Id; 119 | spendFrom.OutputIndex = 0; 120 | 121 | // Change the metadata if you want 122 | //MetaData transferMetadata = new MetaData(); 123 | //metaData.setMetaData("msg", "My second transaction"); 124 | TestMetadata transferMetadata = new TestMetadata(); 125 | transferMetadata.msg = "My second transaction"; 126 | 127 | // the asset's ID is equal to the ID of the transaction that created it 128 | // By default, the 'amount' of a created digital asset == "1". So we spend "1" in our TRANSFER. 129 | string amount = "1"; 130 | BlockchainAccount account = new BlockchainAccount(); 131 | Details details = null; 132 | // Use the previous transaction's asset and TRANSFER it 133 | var build2 = BigchainDbTransactionBuilder, TestMetadata>. 134 | init(). 135 | addMetaData(metaData). 136 | addInput(details, spendFrom, publicKey). 137 | addOutput("1", account.Key.PublicKey). 138 | addAssets(createTransaction.Data.Id). 139 | operation(Operations.TRANSFER). 140 | buildAndSignOnly(publicKey, privateKey); 141 | 142 | var transferTransaction = AsyncContext.Run(() => TransactionsApi, TestMetadata>.sendTransactionAsync(build2)); 143 | 144 | if (transferTransaction != null) 145 | { 146 | string assetId2 = transferTransaction.Data.Id; 147 | //"2984ac294290ce6f15124140dad652fc8a306aca62c38237174988dfcf31a3e6" 148 | var testTran2 = AsyncContext.Run(() => TransactionsApi.getTransactionByIdAsync(assetId2)); 149 | Console.WriteLine("Hello assetId: " + assetId2); 150 | 151 | } 152 | else 153 | { 154 | Console.WriteLine("Failed to send transaction"); 155 | } 156 | 157 | 158 | Console.ReadKey(true); 159 | 160 | } 161 | }; 162 | } -------------------------------------------------------------------------------- /BigchainCSharp_Test/TestAsset.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Omnibasis.BigchainCSharp_Test 7 | { 8 | [Serializable] 9 | public class TestAsset 10 | { 11 | [JsonProperty] 12 | public string msg { get; set; } 13 | [JsonProperty] 14 | public string city { get; set; } 15 | [JsonProperty] 16 | public string temperature { get; set; } 17 | [JsonProperty] 18 | public DateTime datetime { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /BigchainCSharp_Test/TestMetadata.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Omnibasis.BigchainCSharp_Test 7 | { 8 | [Serializable] 9 | public class TestMetadata 10 | { 11 | [JsonProperty] 12 | public string msg { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /BigchainCSharp_WS_Test/BigchainCSharp_WS_Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | BigchainCSharp_WS_Test 7 | BigchainCSharp_WS_Test 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /BigchainCSharp_WS_Test/Program.cs: -------------------------------------------------------------------------------- 1 | using Omnibasis.BigchainCSharp.Builders; 2 | using System; 3 | 4 | namespace Omnibasis.BigchainCSharp_WS_Test 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | BigchainDbConfigBuilder 11 | .baseUrl("https://test.ipdb.io/") 12 | .webSocketMonitor(new ValidTransactionMessageHandler()) 13 | .setup(); 14 | 15 | 16 | Console.ReadKey(true); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /BigchainCSharp_WS_Test/ValidTransactionMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using Omnibasis.BigchainCSharp.Model; 2 | using Omnibasis.BigchainCSharp.WS; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using Newtonsoft.Json; 7 | 8 | namespace Omnibasis.BigchainCSharp_WS_Test 9 | { 10 | public class ValidTransactionMessageHandler : MessageHandler 11 | { 12 | public void handleMessage(string message) 13 | { 14 | ValidTransaction validTransaction = JsonConvert.DeserializeObject(message); 15 | Console.WriteLine("validTransaction: " + validTransaction.TransactionId); 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/AccountApiTest.cs: -------------------------------------------------------------------------------- 1 | using Omnibasis.BigchainCSharp.Api; 2 | using Omnibasis.BigchainCSharp.Model; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using Xunit; 7 | using Shouldly; 8 | using NSec.Cryptography; 9 | using Omnibasis.BigchainCSharp.Util; 10 | 11 | namespace BigchainCSharp_XUnitTest 12 | { 13 | /** 14 | * The Class AccountApiTest. 15 | */ 16 | public class AccountApiTest : AppTestBase 17 | { 18 | public AccountApiTest() : base() 19 | { 20 | 21 | } 22 | 23 | /// 24 | /// Test asset search. 25 | /// 26 | [Fact] 27 | public void testLoadAccount() 28 | { 29 | BlockchainAccount account = AccountApi.loadAccount(publicKey, privateKey); 30 | account.Key.ShouldNotBe(null); 31 | account.PublicKey.ShouldNotBe(null); 32 | } 33 | 34 | /// 35 | /// Test create account. 36 | /// 37 | [Fact] 38 | public void testCreateAccount() 39 | { 40 | BlockchainAccount account = AccountApi.createAccount(); 41 | account.PublicKey.ShouldNotBe(null); 42 | account.Key.ShouldNotBe(null); 43 | } 44 | 45 | /// 46 | /// Test export keys. 47 | /// 48 | [Fact] 49 | public void testExportKeys() 50 | { 51 | var algorithm = SignatureAlgorithm.Ed25519; 52 | BlockchainAccount account = AccountApi.createAccount(true); 53 | account.PublicKey.ShouldNotBe(null); 54 | account.Key.ShouldNotBe(null); 55 | 56 | var data = Encoding.UTF8.GetBytes("Hello world!"); 57 | // sign the data with the private key 58 | var signature = algorithm.Sign(account.Key, data); 59 | 60 | 61 | var key = account.Export(); 62 | key.ShouldNotBe(null); 63 | var privateStr = Utils.ByteArrayToString(key); 64 | var pub = account.ExportPublic(); 65 | pub.ShouldNotBe(null); 66 | var publicStr = Utils.ByteArrayToString(pub); 67 | 68 | 69 | using (var newKey = Key.Import(algorithm, Utils.StringToByteArray(privateStr), KeyBlobFormat.PkixPrivateKey)) 70 | { 71 | 72 | var publicKey = PublicKey.Import(algorithm, Utils.StringToByteArray(publicStr), KeyBlobFormat.PkixPublicKey); 73 | 74 | // sign the data with the private key 75 | var signature2 = algorithm.Sign(newKey, data); 76 | signature2.ShouldBe(signature); 77 | // verify the data with the signature and the public key 78 | var done = algorithm.Verify(publicKey, data, signature2); 79 | done.ShouldBe(true); 80 | } 81 | 82 | // now user 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/AppTestBase.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Configuration; 2 | using Nito.AsyncEx; 3 | using Omnibasis.BigchainCSharp.Builders; 4 | using Shouldly; 5 | using System; 6 | using System.IO; 7 | using System.Threading.Tasks; 8 | 9 | namespace BigchainCSharp_XUnitTest 10 | { 11 | //public static class ShouldBeTestExtensions 12 | //{ 13 | // public static void ShouldNotBe(this T actual, T expected) 14 | // { 15 | // if(expected == null) 16 | // { 17 | // Assert.NotNull(actual); 18 | // } 19 | 20 | // } 21 | // public static void ShouldBe(this T actual, T expected) 22 | // { 23 | // Assert.NotEqual(actual, expected); 24 | // } 25 | //} 26 | /// 27 | /// This is base class for all our test classes. 28 | /// It prepares BigchainDB system. 29 | /// 30 | public abstract class AppTestBase 31 | { 32 | protected const string publicKey = "302a300506032b657003210033c43dc2180936a2a9138a05f06c892d2fb1cfda4562cbc35373bf13cd8ed373"; 33 | protected const string privateKey = "302e020100300506032b6570042204206f6b0cd095f1e83fc5f08bffb79c7c8a30e77a3ab65f4bc659026b76394fcea8"; 34 | 35 | 36 | 37 | protected BigchainDbConfigBuilder.IBlockchainConfigurationBuilder builder; 38 | 39 | public object AsyncHelper { get; } 40 | 41 | public static IConfigurationRoot GetIConfigurationRoot(string outputPath) 42 | { 43 | return new ConfigurationBuilder() 44 | .SetBasePath(outputPath) 45 | .AddJsonFile("appsettings.json", optional: true) 46 | .AddEnvironmentVariables() 47 | .Build(); 48 | } 49 | 50 | protected AppTestBase() 51 | { 52 | 53 | AsyncContext.Run(() => this.init()); 54 | 55 | } 56 | private async Task init() 57 | { 58 | 59 | try 60 | { 61 | var configuration = GetIConfigurationRoot(Directory.GetCurrentDirectory()); 62 | var appConfig = configuration.GetSection("AppConfig"); 63 | 64 | builder = BigchainDbConfigBuilder 65 | .baseUrl(appConfig["api:url"]); 66 | var ret = await builder.setup(); 67 | ret.ShouldBe(true); 68 | } 69 | catch (Exception e) 70 | { 71 | Console.WriteLine(e); 72 | } 73 | 74 | 75 | } 76 | 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/AssetsApiTest.cs: -------------------------------------------------------------------------------- 1 | using Omnibasis.BigchainCSharp.Api; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Xunit; 7 | using Shouldly; 8 | 9 | namespace BigchainCSharp_XUnitTest 10 | { 11 | /** 12 | * Test asset search. 13 | */ 14 | public class AssetsApiTest : AppTestBase 15 | { 16 | public AssetsApiTest() : base() 17 | { 18 | 19 | } 20 | 21 | 22 | /// 23 | /// Test asset search. 24 | /// 25 | [Fact] 26 | public async Task testAssetSearch() 27 | { 28 | var assets = await AssetsApi.getAssetsAsync("bigchaindb"); 29 | assets.Count.ShouldBe(assets.Count); 30 | } 31 | 32 | /// 33 | /// Test asset search with limit. 34 | /// 35 | [Fact] 36 | public async Task testAssetSearchWithLimit() 37 | { 38 | var assets = await AssetsApi.getAssetsWithLimitAsync("bigchaindb", 2); 39 | assets.Count.ShouldBe(2); 40 | } 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/BigchainCSharp_XUnitTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.1 5 | 6 | false 7 | 8 | BigchainCSharp_XUnitTest 9 | 10 | BigchainCSharp_XUnitTest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | all 25 | runtime; build; native; contentfiles; analyzers 26 | 27 | 28 | 29 | 30 | 31 | PreserveNewest 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/BigchainDBConnectionManagerTest.cs: -------------------------------------------------------------------------------- 1 | using Nito.AsyncEx; 2 | using Omnibasis.BigchainCSharp.Model; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | using Xunit; 8 | using Omnibasis.BigchainCSharp.Builders; 9 | using Shouldly; 10 | using Omnibasis.BigchainCSharp.Constants; 11 | using WireMock.Server; 12 | using WireMock.RequestBuilders; 13 | using WireMock.ResponseBuilders; 14 | using System.Threading.Tasks; 15 | using static Omnibasis.BigchainCSharp.Builders.BigchainDbConfigBuilder; 16 | 17 | namespace BigchainCSharp_XUnitTest 18 | { 19 | public class BigchainDBConnectionManagerTest 20 | { 21 | private string server1 = "http://localhost:9191"; 22 | private string server2 = "http://localhost:9192"; 23 | private string server3 = "http://localhost:9193"; 24 | 25 | private FluentMockServer bdbNode1, bdbNode2, bdbNode3; 26 | internal IDictionary conn1Config = new Dictionary(), conn2Config = new Dictionary(), conn3Config = new Dictionary(); 27 | 28 | internal IList connections = new List(); 29 | internal IDictionary headers = new Dictionary(); 30 | 31 | 32 | 33 | public BigchainDBConnectionManagerTest() 34 | { 35 | setUp(); 36 | } 37 | 38 | ~BigchainDBConnectionManagerTest() 39 | { 40 | tearDown(); 41 | } 42 | 43 | 44 | private void setUp() 45 | { 46 | //setup mock node 1 47 | 48 | 49 | bdbNode1 = FluentMockServer.Start(9191); 50 | Console.WriteLine("port1 - 9191"); 51 | 52 | //setup mock node 2 53 | bdbNode2 = FluentMockServer.Start(9192); 54 | Console.WriteLine("port2 - 9192"); 55 | 56 | //set up mock node 3 57 | bdbNode3 = FluentMockServer.Start(9193); 58 | Console.WriteLine("port3 - 9193"); 59 | 60 | //define headers 61 | headers["app_id"] = ""; 62 | headers["app_key"] = ""; 63 | 64 | conn1Config["baseUrl"] = server1; 65 | conn1Config["headers"] = headers; 66 | BlockchainConnection conn1 = new BlockchainConnection(conn1Config); 67 | 68 | conn2Config["baseUrl"] = server2; 69 | conn2Config["headers"] = headers; 70 | BlockchainConnection conn2 = new BlockchainConnection(conn2Config); 71 | 72 | conn3Config["baseUrl"] = server3; 73 | conn3Config["headers"] = headers; 74 | BlockchainConnection conn3 = new BlockchainConnection(conn3Config); 75 | 76 | connections.Add(conn1); 77 | connections.Add(conn2); 78 | connections.Add(conn3); 79 | 80 | 81 | } 82 | 83 | 84 | private void tearDown() 85 | { 86 | if (bdbNode1.IsStarted) 87 | { 88 | bdbNode1.Stop(); 89 | } 90 | if (bdbNode2.IsStarted) 91 | { 92 | bdbNode2.Stop(); 93 | } 94 | if (bdbNode3.IsStarted) 95 | { 96 | bdbNode3.Stop(); 97 | } 98 | } 99 | 100 | private void stub(FluentMockServer server) 101 | { 102 | server 103 | .Given(Request.Create().WithPath("/api/v1").UsingGet()) 104 | .RespondWith( 105 | Response.Create() 106 | .WithStatusCode(200) 107 | .WithBody(@"{ ""msg"": ""Hello world!"" }") 108 | ); 109 | 110 | } 111 | [Fact] 112 | public virtual async Task nodeIsReusedOnSuccessfulConnection() 113 | { 114 | //check that node is up 115 | if (!bdbNode1.IsStarted) 116 | { 117 | bdbNode1.Reset(); 118 | }; 119 | 120 | stub(bdbNode1); 121 | 122 | await BigchainDbConfigBuilder.addConnections(connections).setTimeout(10000).setup(); 123 | 124 | string actualBaseUrl = (string)BigchainDbConfigBuilder.Builder.CurrentNode.getConnection()["baseUrl"]; 125 | actualBaseUrl.ShouldBe(server1); 126 | 127 | await sendCreateTransaction(); 128 | 129 | string newBaseUrl = (string)BigchainDbConfigBuilder.Builder.CurrentNode.getConnection()["baseUrl"]; 130 | newBaseUrl.ShouldBe(server1); 131 | 132 | } 133 | 134 | [Fact] 135 | public virtual async Task testGivenConnection() 136 | { 137 | //check that node is up 138 | if (!bdbNode1.IsStarted) 139 | { 140 | bdbNode1.Reset(); 141 | }; 142 | 143 | stub(bdbNode1); 144 | 145 | var db = BigchainDbConfigBuilder.addConnections(connections).setTimeout(10000); 146 | await db.setup(); 147 | 148 | string actualBaseUrl = (string)BigchainDbConfigBuilder.Builder.CurrentNode.getConnection()["baseUrl"]; 149 | actualBaseUrl.ShouldBe(server1); 150 | 151 | await sendCreateTransaction(db); 152 | 153 | string newBaseUrl = (string)BigchainDbConfigBuilder.Builder.CurrentNode.getConnection()["baseUrl"]; 154 | newBaseUrl.ShouldBe(server1); 155 | 156 | } 157 | [Fact] 158 | public virtual async Task secondNodeIsUsedIfFirstNodeGoesDown() 159 | { 160 | //check that nodes are up 161 | if (!bdbNode1.IsStarted) 162 | { 163 | bdbNode1.Reset(); 164 | }; 165 | 166 | if (!bdbNode2.IsStarted) 167 | { 168 | bdbNode2.Reset(); 169 | }; 170 | 171 | 172 | //start listening on node 1 173 | stub(bdbNode1); 174 | 175 | 176 | //start listening on node 2 177 | stub(bdbNode2); 178 | 179 | 180 | await BigchainDbConfigBuilder.addConnections(connections).setTimeout(10000).setup(); 181 | 182 | //check if driver is connected to first node 183 | string actualBaseUrl = (string)BigchainDbConfigBuilder.Builder.CurrentNode.getConnection()["baseUrl"]; 184 | actualBaseUrl.ShouldBe(server1); 185 | 186 | //shut down node 1 187 | bdbNode1.Stop(); 188 | 189 | //now transaction should be send by node 2 190 | await sendCreateTransaction(); 191 | 192 | //verify driver is connected to node 2 193 | string newBaseUrl = (string)BigchainDbConfigBuilder.Builder.CurrentNode.getConnection()["baseUrl"]; 194 | newBaseUrl.ShouldBe(server2); 195 | 196 | } 197 | 198 | [Fact] 199 | public virtual async Task verifyMetaValuesForNodesAreUpdatedCorrectly() 200 | { 201 | //check that nodes are up 202 | if (!bdbNode1.IsStarted) 203 | { 204 | bdbNode1.Reset(); 205 | }; 206 | 207 | if (!bdbNode2.IsStarted) 208 | { 209 | bdbNode2.Reset(); 210 | }; 211 | 212 | if (!bdbNode3.IsStarted) 213 | { 214 | bdbNode3.Reset(); 215 | }; 216 | 217 | //start listening on node 1 218 | stub(bdbNode1); 219 | 220 | 221 | //start listening on node 2 222 | stub(bdbNode2); 223 | 224 | //start listening on node 3 225 | stub(bdbNode3); 226 | 227 | 228 | await BigchainDbConfigBuilder.addConnections(connections).setTimeout(10000).setup(); 229 | 230 | //verify meta values of nodes are initialized as 0 231 | foreach (BlockchainConnection conn in BigchainDbConfigBuilder.Builder.Connections) 232 | { 233 | (conn.TimeToRetryForConnection == 0).ShouldBe(true); 234 | (conn.RetryCount == 0).ShouldBe(true); 235 | } 236 | 237 | //check if driver is connected to first node 238 | string actualBaseUrl = (string)BigchainDbConfigBuilder.Builder.CurrentNode.getConnection()["baseUrl"]; 239 | actualBaseUrl.ShouldBe(server1); 240 | 241 | //shut down node 1 242 | bdbNode1.Stop(); 243 | 244 | 245 | //now transaction should be send by node 2 246 | await sendCreateTransaction(); 247 | 248 | string baseUrl1 = "", baseUrl2 = ""; 249 | //verify meta values of nodes are initialized as 0 250 | foreach (BlockchainConnection conn in BigchainDbConfigBuilder.Builder.Connections) 251 | { 252 | 253 | baseUrl1 = (string)conn.getConnection()["baseUrl"]; 254 | if (baseUrl1.Equals(server1)) 255 | { 256 | (conn.TimeToRetryForConnection != 0).ShouldBe(true); 257 | ((conn.TimeToRetryForConnection - DateTimeHelper.CurrentUnixTimeMillis()) <= BigchainDbConfigBuilder.Builder.Timeout).ShouldBe(true); 258 | (conn.RetryCount == 1).ShouldBe(true); 259 | } 260 | } 261 | 262 | //verify driver is connected to node 2 263 | string newBaseUrl = (string)BigchainDbConfigBuilder.Builder.CurrentNode.getConnection()["baseUrl"]; 264 | newBaseUrl.ShouldBe(server2); 265 | 266 | 267 | //shut down node 2 268 | bdbNode2.Stop(); 269 | 270 | //now transaction should be send by node 3 271 | await sendCreateTransaction(); 272 | 273 | long T1 = 0, T2 = 0; 274 | //verify meta values of nodes 275 | foreach (BlockchainConnection conn in BigchainDbConfigBuilder.Builder.Connections) 276 | { 277 | 278 | baseUrl2 = (string)conn.getConnection()["baseUrl"]; 279 | if (baseUrl2.Equals(server2)) 280 | { 281 | T2 = conn.TimeToRetryForConnection; 282 | (T2 != 0).ShouldBe(true); 283 | ((T2 - DateTimeHelper.CurrentUnixTimeMillis()) <= BigchainDbConfigBuilder.Builder.Timeout).ShouldBe(true); 284 | (conn.RetryCount == 1).ShouldBe(true); 285 | } 286 | 287 | baseUrl1 = (string)conn.getConnection()["baseUrl"]; 288 | if (baseUrl1.Equals(server1)) 289 | { 290 | T1 = conn.TimeToRetryForConnection; 291 | (T1 != 0).ShouldBe(true); 292 | (conn.RetryCount == 1).ShouldBe(true); 293 | } 294 | 295 | } 296 | 297 | //verify that T1 < T2 298 | (T1 < T2).ShouldBe(true); 299 | } 300 | 301 | [Fact] 302 | public virtual async Task shouldThrowTimeoutException() 303 | { 304 | //check that nodes are up 305 | if (!bdbNode1.IsStarted) 306 | { 307 | bdbNode1.Reset(); 308 | }; 309 | 310 | if (!bdbNode2.IsStarted) 311 | { 312 | bdbNode2.Reset(); 313 | }; 314 | 315 | if (!bdbNode3.IsStarted) 316 | { 317 | bdbNode3.Reset(); 318 | }; 319 | 320 | //start listening on node 1 321 | stub(bdbNode1); 322 | 323 | 324 | //start listening on node 2 325 | stub(bdbNode2); 326 | 327 | //start listening on node 3 328 | stub(bdbNode3); 329 | 330 | 331 | 332 | await BigchainDbConfigBuilder.addConnections(connections).setTimeout(10000).setup(); 333 | 334 | //check if driver is connected to first node 335 | string url1 = (string)BigchainDbConfigBuilder.Builder.CurrentNode.getConnection()["baseUrl"]; 336 | url1.ShouldBe(server1); 337 | 338 | //shut down node 1 339 | bdbNode1.Stop(); 340 | 341 | //now transaction should be send by node 2 342 | await sendCreateTransaction(); 343 | 344 | //check if driver is connected to node 2 345 | string url2 = (string)BigchainDbConfigBuilder.Builder.CurrentNode.getConnection()["baseUrl"]; 346 | url2.ShouldBe(server2); 347 | 348 | //shut down node 2 349 | bdbNode2.Stop(); 350 | 351 | //now transaction should be send by node 2 352 | await sendCreateTransaction(); 353 | 354 | //check if driver is connected to node 3 355 | string url3 = (string)BigchainDbConfigBuilder.Builder.CurrentNode.getConnection()["baseUrl"]; 356 | url3.ShouldBe(server3); 357 | 358 | //shut down node 3 359 | bdbNode3.Stop(); 360 | 361 | //now transaction cannot be send as all nodes are down 362 | await sendCreateTransaction(); 363 | } 364 | 365 | //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: 366 | //ORIGINAL LINE: public String sendCreateTransaction() throws TimeoutException, Exception 367 | private async Task sendCreateTransaction(IBlockchainConfigurationBuilder db = null) 368 | { 369 | 370 | BlockchainAccount account = new BlockchainAccount(); 371 | 372 | 373 | // create New asset 374 | Dictionary assetData = new Dictionary(); 375 | assetData.Add("name", "James Bond"); 376 | assetData.Add("age", "doesn't matter"); 377 | assetData.Add("purpose", "saving the world"); 378 | Console.WriteLine("(*) Assets Prepared.."); 379 | 380 | // create metadata 381 | Dictionary metaData = new Dictionary(); 382 | metaData.Add("where is he now?", "Thailand"); 383 | Console.WriteLine("(*) Metadata Prepared.."); 384 | //build and send CREATE transaction 385 | 386 | 387 | var transaction = 388 | await BigchainDbTransactionBuilder, Dictionary> 389 | .init() 390 | .addAssets(assetData) 391 | .addMetaData(metaData) 392 | .operation(Operations.CREATE) 393 | .buildAndSign(account.PublicKey, account.Key) 394 | .sendTransactionAsync(db); 395 | 396 | 397 | if(transaction.Data != null) 398 | { 399 | Console.WriteLine("(*) CREATE Transaction sent.. - " + transaction.Data.Id); 400 | 401 | return transaction.Data.Id; 402 | 403 | } else 404 | { 405 | Console.WriteLine("(*) CREATE Transaction failed.. - "); 406 | 407 | return null; 408 | 409 | } 410 | } 411 | 412 | 413 | 414 | internal static class DateTimeHelper 415 | { 416 | private static readonly System.DateTime Jan1st1970 = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc); 417 | public static long CurrentUnixTimeMillis() 418 | { 419 | return (long)(System.DateTime.UtcNow - Jan1st1970).TotalMilliseconds; 420 | } 421 | } 422 | } 423 | 424 | } -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/BlocksApiTest.cs: -------------------------------------------------------------------------------- 1 | using Omnibasis.BigchainCSharp.Api; 2 | using Omnibasis.BigchainCSharp.Model; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Xunit; 8 | using Shouldly; 9 | 10 | namespace BigchainCSharp_XUnitTest 11 | { 12 | /** 13 | * The Class BlocksApiTest. 14 | */ 15 | public class BlocksApiTest : AppTestBase 16 | { 17 | public BlocksApiTest() : base() 18 | { 19 | 20 | } 21 | 22 | public static string V1_BLOCK_JSON = "{\n" + 23 | " \"height\": 1,\n" + 24 | " \"transactions\": [\n" + 25 | " {\n" + 26 | " \"asset\": {\n" + 27 | " \"data\": {\n" + 28 | " \"msg\": \"Hello BigchainDB!\"\n" + 29 | " }\n" + 30 | " },\n" + 31 | " \"id\": \"4957744b3ac54434b8270f2c854cc1040228c82ea4e72d66d2887a4d3e30b317\",\n" + 32 | " \"inputs\": [\n" + 33 | " {\n" + 34 | " \"fulfillment\": \"pGSAIDE5i63cn4X8T8N1sZ2mGkJD5lNRnBM4PZgI_zvzbr-cgUCy4BR6gKaYT-tdyAGPPpknIqI4JYQQ-p2nCg3_9BfOI-15vzldhyz-j_LZVpqAlRmbTzKS-Q5gs7ZIFaZCA_UD\",\n" + 35 | " \"fulfills\": null,\n" + 36 | " \"owners_before\": [\n" + 37 | " \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\"\n" + 38 | " ]\n" + 39 | " }\n" + 40 | " ],\n" + 41 | " \"metadata\": {\n" + 42 | " \"sequence\": 0\n" + 43 | " },\n" + 44 | " \"operation\": \"CREATE\",\n" + 45 | " \"outputs\": [\n" + 46 | " {\n" + 47 | " \"amount\": \"1\",\n" + 48 | " \"condition\": {\n" + 49 | " \"details\": {\n" + 50 | " \"public_key\": \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\",\n" + 51 | " \"type\": \"ed25519-sha-256\"\n" + 52 | " },\n" + 53 | " \"uri\": \"ni:///sha-256;PNYwdxaRaNw60N6LDFzOWO97b8tJeragczakL8PrAPc?fpt=ed25519-sha-256&cost=131072\"\n" + 54 | " },\n" + 55 | " \"public_keys\": [\n" + 56 | " \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\"\n" + 57 | " ]\n" + 58 | " }\n" + 59 | " ],\n" + 60 | " \"version\": \"2.0\"\n" + 61 | " }\n" + 62 | " ]\n" + 63 | "}"; 64 | 65 | public static string V1_BLOCK_BY_TRANS_JSON = "[\n" + 66 | " 1\n" + 67 | "]"; 68 | 69 | 70 | /// 71 | /// Test get block. 72 | /// 73 | [Fact] 74 | public async Task testGetBlock() 75 | { 76 | Block block = await BlocksApi.getBlock(3395); 77 | block.Height.ShouldBe(3395); 78 | block.Transactions.Count.ShouldBe(1); 79 | } 80 | 81 | /// 82 | /// Test get block. 83 | /// 84 | [Fact] 85 | public async Task testGetBlockByTransactionId() 86 | { 87 | IList list = await BlocksApi.getBlocksByTransactionIdAsync("4957744b3ac54434b8270f2c854cc1040228c82ea4e72d66d2887a4d3e30b317"); 88 | list.Count.ShouldBe(1); 89 | } 90 | 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/MetaDataApiTest.cs: -------------------------------------------------------------------------------- 1 | using Omnibasis.BigchainCSharp.Api; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Xunit; 7 | using Shouldly; 8 | namespace BigchainCSharp_XUnitTest 9 | { 10 | 11 | /** 12 | * The Class MetaDataApiTest. 13 | */ 14 | public class MetaDataApiTest : AppTestBase 15 | { 16 | public MetaDataApiTest() : base() 17 | { 18 | 19 | } 20 | 21 | public static string V1_METADATA_JSON = "[\n" + 22 | " {\n" + 23 | " \"metadata\": {\"metakey1\": \"Hello BigchainDB 1!\"},\n" + 24 | " \"id\": \"51ce82a14ca274d43e4992bbce41f6fdeb755f846e48e710a3bbb3b0cf8e4204\"\n" + 25 | " },\n" + 26 | " {\n" + 27 | " \"metadata\": {\"metakey2\": \"Hello BigchainDB 2!\"},\n" + 28 | " \"id\": \"b4e9005fa494d20e503d916fa87b74fe61c079afccd6e084260674159795ee31\"\n" + 29 | " },\n" + 30 | " {\n" + 31 | " \"metadata\": {\"metakey3\": \"Hello BigchainDB 3!\"},\n" + 32 | " \"id\": \"fa6bcb6a8fdea3dc2a860fcdc0e0c63c9cf5b25da8b02a4db4fb6a2d36d27791\"\n" + 33 | " }\n" + 34 | "]\n"; 35 | 36 | public static string V1_METADATA_LIMIT_JSON = "[\n" + 37 | " {\n" + 38 | " \"metadata\": {\"msg\": \"Hello BigchainDB 1!\"},\n" + 39 | " \"id\": \"51ce82a14ca274d43e4992bbce41f6fdeb755f846e48e710a3bbb3b0cf8e4204\"\n" + 40 | " },\n" + 41 | " {\n" + 42 | " \"metadata\": {\"msg\": \"Hello BigchainDB 2!\"},\n" + 43 | " \"id\": \"b4e9005fa494d20e503d916fa87b74fe61c079afccd6e084260674159795ee31\"\n" + 44 | " }\n" + 45 | "]"; 46 | 47 | /// 48 | /// Test metadata search. 49 | /// 50 | [Fact] 51 | public async Task testMetaDataSearch() 52 | { 53 | var metadata = await MetaDataApi.getMetaDataAsync("bigchaindb"); 54 | //metadata.Count.ShouldBe(3); 55 | //metadata[0].Id.ShouldBe("51ce82a14ca274d43e4992bbce41f6fdeb755f846e48e710a3bbb3b0cf8e4204"); 56 | } 57 | 58 | /// 59 | /// Test metadata search with limit. 60 | /// 61 | [Fact] 62 | public async Task testMetaDataSearchWithLimit() 63 | { 64 | var metadata = await MetaDataApi.getMetaDataWithLimitAsync("bigchaindb", 2); 65 | metadata.Count.ShouldBe(2); 66 | } 67 | 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/OutputsApiTest.cs: -------------------------------------------------------------------------------- 1 | using Omnibasis.BigchainCSharp.Api; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Xunit; 7 | using Shouldly; 8 | 9 | namespace BigchainCSharp_XUnitTest 10 | { 11 | 12 | /** 13 | * The Class OutputsApiTest. 14 | */ 15 | public class OutputsApiTest : AppTestBase 16 | { 17 | public OutputsApiTest() : base() 18 | { 19 | 20 | } 21 | 22 | public static string V1_OUTPUTS_JSON = "[\n" + 23 | " {\n" + 24 | " \"output_index\": 0,\n" + 25 | " \"transaction_id\": \"2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e\"\n" + 26 | " },\n" + 27 | " {\n" + 28 | " \"output_index\": 1,\n" + 29 | " \"transaction_id\": \"2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e\"\n" + 30 | " }\n" + 31 | "]"; 32 | 33 | public static string V1_OUTPUTS_SPENT_JSON = "[\n" + 34 | " {\n" + 35 | " \"output_index\": 0,\n" + 36 | " \"transaction_id\": \"2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e\"\n" + 37 | " }\n" + 38 | "]"; 39 | 40 | public static string V1_OUTPUTS_UNSPENT_JSON = "[\n" + 41 | " {\n" + 42 | " \"output_index\": 1,\n" + 43 | " \"transaction_id\": \"2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e\"\n" + 44 | " }\n" + 45 | "]"; 46 | 47 | /// 48 | /// Test get outputs. 49 | /// 50 | [Fact] 51 | public async Task testGetOutputs() 52 | { 53 | var outputs = await OutputsApi.getOutputsAsync(publicKey); 54 | outputs.Count.ShouldBe(2); 55 | } 56 | 57 | /// 58 | /// Test get spent outputs. 59 | /// 60 | [Fact] 61 | public async Task testGetSpentOutputs() 62 | { 63 | var outputs = await OutputsApi.getSpentOutputsAsync(publicKey); 64 | outputs.Count.ShouldBe(1); 65 | outputs[0].OutputIndex.ShouldBe(0); 66 | outputs[0].TransactionId.ShouldBe("2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e"); 67 | } 68 | 69 | /// 70 | /// Test get unspent outputs. 71 | /// 72 | [Fact] 73 | public async Task testGetUnspentOutputs() 74 | { 75 | var outputs = await OutputsApi.getUnspentOutputsAsync(publicKey); 76 | outputs.Count.ShouldBe(1); 77 | outputs[0].OutputIndex.ShouldBe(1); 78 | outputs[0].TransactionId.ShouldBe("2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e"); 79 | } 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/TransactionCombineViaTransferApiTest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Omnibasis.BigchainCSharp.Api; 3 | using Omnibasis.BigchainCSharp.Builders; 4 | using Omnibasis.BigchainCSharp.Constants; 5 | using Omnibasis.BigchainCSharp.Model; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using Xunit; 11 | using Shouldly; 12 | using Omnibasis.CryptoConditionsCSharp; 13 | using System.Threading; 14 | 15 | namespace BigchainCSharp_XUnitTest 16 | { 17 | /** 18 | * The Class TransactionCombineViaTransferApiTest. 19 | */ 20 | public class TransactionCombineViaTransferApiTest : AppTestBase 21 | { 22 | 23 | public TransactionCombineViaTransferApiTest() : base() 24 | { 25 | 26 | } 27 | 28 | 29 | [Serializable] 30 | private class TestToken 31 | { 32 | [JsonProperty] 33 | public string token { get; set; } 34 | [JsonProperty] 35 | public int number_tokens { get; set; } 36 | } 37 | 38 | [Serializable] 39 | private class TestMetadata 40 | { 41 | [JsonProperty] 42 | public string msg { get; set; } 43 | } 44 | 45 | //https://www.bigchaindb.com/developers/guide/tutorial-token-launch/ 46 | [Fact] 47 | public async Task testTokensBuildAndCombineTransferPartingTransaction() 48 | { 49 | var publicKeyObj = BlockchainAccount.publicKeyFromHex(publicKey); 50 | var privateKeyObj = BlockchainAccount.privateKeyFromHex(privateKey); 51 | 52 | // initial tokens amount 53 | int tokens = 10000; 54 | TestToken assetData = new TestToken(); 55 | assetData.token = "My Token on " + DateTime.Now.Ticks.ToString(); 56 | assetData.number_tokens = tokens; 57 | 58 | TestMetadata metaData = new TestMetadata(); 59 | metaData.msg = "My first transaction"; 60 | 61 | // Set up, sign, and send your transaction 62 | var transaction = BigchainDbTransactionBuilder 63 | .init() 64 | .addAssets(assetData) 65 | .addMetaData(metaData) 66 | .addOutput(tokens.ToString(), publicKeyObj) 67 | .operation(Operations.CREATE) 68 | .buildAndSignOnly(publicKeyObj, privateKeyObj); 69 | //.buildAndSign(account.PublicKey, account.PrivateKey); 70 | 71 | //var info = transaction.toHashInput(); 72 | var createTransaction = await TransactionsApi.sendTransactionAsync(transaction); 73 | Thread.Sleep(5000); 74 | createTransaction.Data.ShouldNotBe(null); 75 | // the asset's ID is equal to the ID of the transaction that created it 76 | if (createTransaction.Data != null) 77 | { 78 | string testId2 = createTransaction.Data.Id; 79 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(testId2); 80 | testTran2.ShouldNotBe(null); 81 | 82 | } 83 | 84 | // Describe the output you are fulfilling on the previous transaction 85 | FulFill spendFrom = new FulFill(); 86 | 87 | // the asset's ID is equal to the ID of the transaction that created it 88 | spendFrom.TransactionId = createTransaction.Data.Id; 89 | spendFrom.OutputIndex = 0; 90 | 91 | 92 | // we want to transfer 200 tokens to my cat 93 | int amount = 200; 94 | BlockchainAccount catAccount = new BlockchainAccount(); 95 | Details details = null; 96 | TestToken transferData = new TestToken(); 97 | assetData.token = "To my cat"; 98 | assetData.number_tokens = amount; 99 | int amountLeft = tokens - amount; 100 | 101 | // Use the previous transaction's asset and TRANSFER it 102 | var build2 = BigchainDbTransactionBuilder, TestToken>. 103 | init(). 104 | addMetaData(transferData). 105 | addInput(details, spendFrom, publicKeyObj). 106 | addOutput(amountLeft.ToString(), publicKeyObj). 107 | addOutput(amount.ToString(), catAccount.PublicKey). 108 | addAssets(createTransaction.Data.Id). 109 | operation(Operations.TRANSFER). 110 | buildAndSignOnly(publicKeyObj, privateKeyObj); 111 | 112 | var transferTransaction = await TransactionsApi, TestToken>.sendTransactionAsync(build2); 113 | Thread.Sleep(5000); 114 | transferTransaction.Data.ShouldNotBe(null); 115 | 116 | if (transferTransaction != null) 117 | { 118 | string tran2 = transferTransaction.Data.Id; 119 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(tran2); 120 | testTran2.ShouldNotBe(null); 121 | 122 | } 123 | 124 | var useThisKey = transferTransaction.Data.Outputs[0].PublicKeys[0]; 125 | 126 | var compKey = KeyPairUtils.encodePublicKeyInBase58(publicKeyObj); 127 | // get unspent outputs 128 | var list = await OutputsApi.getUnspentOutputsAsync(useThisKey); 129 | 130 | //list.Count.ShouldBe(1); 131 | 132 | // Describe the output you are fulfilling on spent outputs 133 | FulFill spendFrom2 = new FulFill(); 134 | // the asset's ID is equal to the ID of the transaction that created it 135 | spendFrom2.TransactionId = transferTransaction.Data.Id; // list[0].TransactionId; 136 | spendFrom2.OutputIndex = 0; 137 | 138 | // now we want to send 100 tokens to my dog 139 | BlockchainAccount dogAccount = new BlockchainAccount(); 140 | Details details2 = null; 141 | TestToken transferData2 = new TestToken(); 142 | transferData2.token = "To my dog"; 143 | transferData2.number_tokens = amount; 144 | 145 | amountLeft = amountLeft - amount; 146 | // Use the previous transaction's asset and TRANSFER it 147 | var build3 = BigchainDbTransactionBuilder, TestToken>. 148 | init(). 149 | addMetaData(transferData2). 150 | addInput(details2, spendFrom2, publicKeyObj). 151 | addOutput(amountLeft.ToString(), publicKeyObj). 152 | addOutput(amount.ToString(), dogAccount.PublicKey). 153 | addAssets(createTransaction.Data.Id). 154 | operation(Operations.TRANSFER). 155 | buildAndSignOnly(publicKeyObj, privateKeyObj); 156 | 157 | var transferTransaction3 = await TransactionsApi, TestToken>.sendTransactionAsync(build3); 158 | Thread.Sleep(5000); 159 | transferTransaction3.Data.ShouldNotBe(null); 160 | 161 | if (transferTransaction3 != null) 162 | { 163 | string tran2 = transferTransaction3.Data.Id; 164 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(tran2); 165 | testTran2.ShouldNotBe(null); 166 | 167 | } 168 | 169 | // now dog wants to share with puppy 100 tokens 170 | BlockchainAccount puppyAccount = new BlockchainAccount(); 171 | Details details3 = null; 172 | TestToken transferData3 = new TestToken(); 173 | transferData3.token = "To my puppy"; 174 | int topuppy = 100; 175 | transferData3.number_tokens = topuppy; 176 | 177 | FulFill spendFrom3 = new FulFill(); 178 | // the asset's ID is equal to the ID of the transaction that created it 179 | spendFrom3.TransactionId = transferTransaction3.Data.Id; // list[0].TransactionId; 180 | spendFrom3.OutputIndex = 1; 181 | 182 | var dogAmountLeft = amount - topuppy; 183 | // Use the previous transaction's asset and TRANSFER it 184 | var build4 = BigchainDbTransactionBuilder, TestToken>. 185 | init(). 186 | addMetaData(transferData3). 187 | addInput(details3, spendFrom3, dogAccount.PublicKey). 188 | addOutput(dogAmountLeft.ToString(), dogAccount.PublicKey). 189 | addOutput(topuppy.ToString(), puppyAccount.PublicKey). 190 | addAssets(createTransaction.Data.Id). 191 | operation(Operations.TRANSFER). 192 | buildAndSignOnly(dogAccount.PublicKey, dogAccount.Key); 193 | 194 | 195 | 196 | var transferTransaction4 = await TransactionsApi, TestToken>.sendTransactionAsync(build4); 197 | Thread.Sleep(5000); 198 | if (transferTransaction4.Messsage != null) 199 | { 200 | var msg = transferTransaction4.Messsage.Message; 201 | } 202 | 203 | transferTransaction4.Data.ShouldNotBe(null); 204 | 205 | if (transferTransaction4 != null) 206 | { 207 | string tran2 = transferTransaction4.Data.Id; 208 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(tran2); 209 | testTran2.ShouldNotBe(null); 210 | 211 | } 212 | 213 | // now we feel bad for puppy and want to give puppy another 100 214 | 215 | // Describe the output you are fulfilling on the previous transaction 216 | FulFill spendFrom5 = new FulFill(); 217 | // the asset's ID is equal to the ID of the transaction that created it 218 | // last transfer transaction id to dog 219 | spendFrom5.TransactionId = transferTransaction3.Data.Id; 220 | spendFrom5.OutputIndex = 0; 221 | 222 | 223 | // we want to transfer 100 tokens. 224 | int amount5 = 100; 225 | Details details5 = null; 226 | TestToken transferData5 = new TestToken(); 227 | transferData5.token = "To my puppy extra 100"; 228 | transferData5.number_tokens = amount5; 229 | amountLeft = amountLeft - amount5; 230 | // Use the previous transaction's asset and TRANSFER it 231 | var build5 = BigchainDbTransactionBuilder, TestToken>. 232 | init(). 233 | addMetaData(transferData5). 234 | addInput(details5, spendFrom5, publicKeyObj). 235 | addOutput(amountLeft.ToString(), publicKeyObj). 236 | addOutput(amount5.ToString(), puppyAccount.PublicKey). 237 | addAssets(createTransaction.Data.Id). 238 | operation(Operations.TRANSFER). 239 | buildAndSignOnly(publicKeyObj, privateKeyObj); 240 | 241 | var transferTransaction5 = await TransactionsApi, TestToken>.sendTransactionAsync(build5); 242 | Thread.Sleep(5000); 243 | transferTransaction5.Data.ShouldNotBe(null); 244 | 245 | if (transferTransaction5 != null) 246 | { 247 | string tran5 = transferTransaction5.Data.Id; 248 | var testTran5 = await TransactionsApi.getTransactionByIdAsync(tran5); 249 | testTran5.ShouldNotBe(null); 250 | 251 | } 252 | 253 | // at this point, puppy has 2 transactions, with 100 tokens each. we want to combine those into 254 | Details details6 = null; 255 | TestToken transferData6 = new TestToken(); 256 | transferData5.token = "Puppy combined account"; 257 | transferData5.number_tokens = amount5 + topuppy; 258 | // we need to spend 2 previous transactions and create new one 259 | FulFill spendFromA = new FulFill(); 260 | // the asset's ID is equal to the ID of the transaction that created it 261 | spendFromA.TransactionId = transferTransaction4.Data.Id; // list[0].TransactionId; 262 | spendFromA.OutputIndex = 1; 263 | 264 | FulFill spendFromB = new FulFill(); 265 | // the asset's ID is equal to the ID of the transaction that created it 266 | spendFromB.TransactionId = transferTransaction5.Data.Id; // list[0].TransactionId; 267 | spendFromB.OutputIndex = 1; 268 | var combinedAmount = amount5 + topuppy; 269 | var build6 = BigchainDbTransactionBuilder, TestToken>. 270 | init(). 271 | addMetaData(transferData5). 272 | addInput(details6, spendFromA, puppyAccount.PublicKey). 273 | addInput(details6, spendFromB, puppyAccount.PublicKey). 274 | addOutput(combinedAmount.ToString(), puppyAccount.PublicKey). 275 | addAssets(createTransaction.Data.Id). 276 | operation(Operations.TRANSFER). 277 | buildAndSignOnly(puppyAccount.PublicKey, puppyAccount.Key); 278 | 279 | var transferTransaction6 = await TransactionsApi, TestToken>.sendTransactionAsync(build6); 280 | Thread.Sleep(5000); 281 | transferTransaction6.Data.ShouldNotBe(null); 282 | transferTransaction6.Data.Outputs[0].Amount.ShouldBe("200"); 283 | 284 | if (transferTransaction6 != null) 285 | { 286 | string tran6 = transferTransaction6.Data.Id; 287 | var testTran6 = await TransactionsApi.getTransactionByIdAsync(tran6); 288 | testTran6.ShouldNotBe(null); 289 | 290 | } 291 | } 292 | 293 | 294 | } 295 | 296 | } 297 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/TransactionCreateApiTest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using NSec.Cryptography; 3 | using Omnibasis.BigchainCSharp.Api; 4 | using Omnibasis.BigchainCSharp.Builders; 5 | using Omnibasis.BigchainCSharp.Constants; 6 | using Omnibasis.BigchainCSharp.Model; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using Xunit; 12 | using Shouldly; 13 | namespace BigchainCSharp_XUnitTest 14 | { 15 | /** 16 | * The Class TransactionCreateApiTest. 17 | */ 18 | public class TransactionCreateApiTest : AppTestBase 19 | { 20 | 21 | public TransactionCreateApiTest() : base() 22 | { 23 | 24 | } 25 | public static string TRANSACTION_ID = "4957744b3ac54434b8270f2c854cc1040228c82ea4e72d66d2887a4d3e30b317"; 26 | public static string V1_GET_TRANSACTION_JSON = "{\n" + 27 | " \"asset\": {\n" + 28 | " \"data\": {\n" + 29 | " \"msg\": \"Hello BigchainDB!\"\n" + 30 | " }\n" + 31 | " },\n" + 32 | " \"id\": \"4957744b3ac54434b8270f2c854cc1040228c82ea4e72d66d2887a4d3e30b317\",\n" + 33 | " \"inputs\": [\n" + 34 | " {\n" + 35 | " \"fulfillment\": \"pGSAIDE5i63cn4X8T8N1sZ2mGkJD5lNRnBM4PZgI_zvzbr-cgUCy4BR6gKaYT-tdyAGPPpknIqI4JYQQ-p2nCg3_9BfOI-15vzldhyz-j_LZVpqAlRmbTzKS-Q5gs7ZIFaZCA_UD\",\n" + 36 | " \"fulfills\": null,\n" + 37 | " \"owners_before\": [\n" + 38 | " \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\"\n" + 39 | " ]\n" + 40 | " }\n" + 41 | " ],\n" + 42 | " \"metadata\": {\n" + 43 | " \"sequence\": 0\n" + 44 | " },\n" + 45 | " \"operation\": \"CREATE\",\n" + 46 | " \"outputs\": [\n" + 47 | " {\n" + 48 | " \"amount\": \"1\",\n" + 49 | " \"condition\": {\n" + 50 | " \"details\": {\n" + 51 | " \"public_key\": \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\",\n" + 52 | " \"type\": \"ed25519-sha-256\"\n" + 53 | " },\n" + 54 | " \"uri\": \"ni:///sha-256;PNYwdxaRaNw60N6LDFzOWO97b8tJeragczakL8PrAPc?fpt=ed25519-sha-256&cost=131072\"\n" + 55 | " },\n" + 56 | " \"public_keys\": [\n" + 57 | " \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\"\n" + 58 | " ]\n" + 59 | " }\n" + 60 | " ],\n" + 61 | " \"version\": \"2.0\"\n" + 62 | "}"; 63 | 64 | public static string V1_GET_TRANSACTION_BY_ASSETS_JSON = "[{\n" + 65 | " \"asset\": {\n" + 66 | " \"id\": \"4957744b3ac54434b8270f2c854cc1040228c82ea4e72d66d2887a4d3e30b317\"\n" + 67 | " },\n" + 68 | " \"id\": \"79ef6803210c941903d63d08b40fa17f0a5a04f11ac0ff04451553a187d97a30\",\n" + 69 | " \"inputs\": [\n" + 70 | " {\n" + 71 | " \"fulfillment\": \"pGSAIDE5i63cn4X8T8N1sZ2mGkJD5lNRnBM4PZgI_zvzbr-cgUAYRI8kzKaZcrW-_avQrAIk5q-7o_7U6biBvoHk1ioBLqHSBcE_PAdNEaeWesAAW_HeCqNUWKaJ5Lzo5Nfz7QgN\",\n" + 72 | " \"fulfills\": {\n" + 73 | " \"output_index\": 0,\n" + 74 | " \"transaction_id\": \"4957744b3ac54434b8270f2c854cc1040228c82ea4e72d66d2887a4d3e30b317\"\n" + 75 | " },\n" + 76 | " \"owners_before\": [\n" + 77 | " \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\"\n" + 78 | " ]\n" + 79 | " }\n" + 80 | " ],\n" + 81 | " \"metadata\": {\n" + 82 | " \"sequence\": 1\n" + 83 | " },\n" + 84 | " \"operation\": \"TRANSFER\",\n" + 85 | " \"outputs\": [\n" + 86 | " {\n" + 87 | " \"amount\": \"1\",\n" + 88 | " \"condition\": {\n" + 89 | " \"details\": {\n" + 90 | " \"public_key\": \"3yfQPHeWAa1MxTX9Zf9176QqcpcnWcanVZZbaHb8B3h9\",\n" + 91 | " \"type\": \"ed25519-sha-256\"\n" + 92 | " },\n" + 93 | " \"uri\": \"ni:///sha-256;lu6ov4AKkee6KWGnyjOVLBeyuP0bz4-O6_dPi15eYUc?fpt=ed25519-sha-256&cost=131072\"\n" + 94 | " },\n" + 95 | " \"public_keys\": [\n" + 96 | " \"3yfQPHeWAa1MxTX9Zf9176QqcpcnWcanVZZbaHb8B3h9\"\n" + 97 | " ]\n" + 98 | " }\n" + 99 | " ],\n" + 100 | " \"version\": \"2.0\"\n" + 101 | "},\n" + 102 | "{\n" + 103 | " \"asset\": {\n" + 104 | " \"id\": \"4957744b3ac54434b8270f2c854cc1040228c82ea4e72d66d2887a4d3e30b317\"\n" + 105 | " },\n" + 106 | " \"id\": \"1fec726a3b426498147f1a1f19a92c187d551a7f66db4b88d666d7dcc10e86a4\",\n" + 107 | " \"inputs\": [\n" + 108 | " {\n" + 109 | " \"fulfillment\": \"pGSAICw7Ul-c2lG6NFbHp3FbKRC7fivQcNGO7GS4wV3A-1QggUARCMty2JBK_OyPJntWEFxDG4-VbKMy853NtqwnPib5QUJIuwPQa1Y4aN2iIBuoqGE85Pmjcc1ScG9FCPSQHacK\",\n" + 110 | " \"fulfills\": {\n" + 111 | " \"output_index\": 0,\n" + 112 | " \"transaction_id\": \"79ef6803210c941903d63d08b40fa17f0a5a04f11ac0ff04451553a187d97a30\"\n" + 113 | " },\n" + 114 | " \"owners_before\": [\n" + 115 | " \"3yfQPHeWAa1MxTX9Zf9176QqcpcnWcanVZZbaHb8B3h9\"\n" + 116 | " ]\n" + 117 | " }\n" + 118 | " ],\n" + 119 | " \"metadata\": {\n" + 120 | " \"sequence\": 2\n" + 121 | " },\n" + 122 | " \"operation\": \"TRANSFER\",\n" + 123 | " \"outputs\": [\n" + 124 | " {\n" + 125 | " \"amount\": \"1\",\n" + 126 | " \"condition\": {\n" + 127 | " \"details\": {\n" + 128 | " \"public_key\": \"3Af3fhhjU6d9WecEM9Uw5hfom9kNEwE7YuDWdqAUssqm\",\n" + 129 | " \"type\": \"ed25519-sha-256\"\n" + 130 | " },\n" + 131 | " \"uri\": \"ni:///sha-256;Ll1r0LzgHUvWB87yIrNFYo731MMUEypqvrbPATTbuD4?fpt=ed25519-sha-256&cost=131072\"\n" + 132 | " },\n" + 133 | " \"public_keys\": [\n" + 134 | " \"3Af3fhhjU6d9WecEM9Uw5hfom9kNEwE7YuDWdqAUssqm\"\n" + 135 | " ]\n" + 136 | " }\n" + 137 | " ],\n" + 138 | " \"version\": \"2.0\"\n" + 139 | "}]"; 140 | public static string V1_POST_TRANSACTION_REQUEST = "{\n" + 141 | " \"asset\": {\n" + 142 | " \"data\": {\n" + 143 | " \"msg\": \"Hello BigchainDB!\"\n" + 144 | " }\n" + 145 | " },\n" + 146 | " \"id\": \"4957744b3ac54434b8270f2c854cc1040228c82ea4e72d66d2887a4d3e30b317\",\n" + 147 | " \"inputs\": [\n" + 148 | " {\n" + 149 | " \"fulfillment\": \"pGSAIDE5i63cn4X8T8N1sZ2mGkJD5lNRnBM4PZgI_zvzbr-cgUCy4BR6gKaYT-tdyAGPPpknIqI4JYQQ-p2nCg3_9BfOI-15vzldhyz-j_LZVpqAlRmbTzKS-Q5gs7ZIFaZCA_UD\",\n" + 150 | " \"fulfills\": null,\n" + 151 | " \"owners_before\": [\n" + 152 | " \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\"\n" + 153 | " ]\n" + 154 | " }\n" + 155 | " ],\n" + 156 | " \"metadata\": {\n" + 157 | " \"sequence\": 0\n" + 158 | " },\n" + 159 | " \"operation\": \"CREATE\",\n" + 160 | " \"outputs\": [\n" + 161 | " {\n" + 162 | " \"amount\": \"1\",\n" + 163 | " \"condition\": {\n" + 164 | " \"details\": {\n" + 165 | " \"public_key\": \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\",\n" + 166 | " \"type\": \"ed25519-sha-256\"\n" + 167 | " },\n" + 168 | " \"uri\": \"ni:///sha-256;PNYwdxaRaNw60N6LDFzOWO97b8tJeragczakL8PrAPc?fpt=ed25519-sha-256&cost=131072\"\n" + 169 | " },\n" + 170 | " \"public_keys\": [\n" + 171 | " \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\"\n" + 172 | " ]\n" + 173 | " }\n" + 174 | " ],\n" + 175 | " \"version\": \"2.0\"\n" + 176 | "}"; 177 | 178 | public static string V1_POST_TRANSACTION_JSON = "{\n" + 179 | " \"asset\": {\n" + 180 | " \"data\": {\n" + 181 | " \"msg\": \"Hello BigchainDB!\"\n" + 182 | " }\n" + 183 | " },\n" + 184 | " \"id\": \"4957744b3ac54434b8270f2c854cc1040228c82ea4e72d66d2887a4d3e30b317\",\n" + 185 | " \"inputs\": [\n" + 186 | " {\n" + 187 | " \"fulfillment\": \"pGSAIDE5i63cn4X8T8N1sZ2mGkJD5lNRnBM4PZgI_zvzbr-cgUCy4BR6gKaYT-tdyAGPPpknIqI4JYQQ-p2nCg3_9BfOI-15vzldhyz-j_LZVpqAlRmbTzKS-Q5gs7ZIFaZCA_UD\",\n" + 188 | " \"fulfills\": null,\n" + 189 | " \"owners_before\": [\n" + 190 | " \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\"\n" + 191 | " ]\n" + 192 | " }\n" + 193 | " ],\n" + 194 | " \"metadata\": {\n" + 195 | " \"sequence\": 0\n" + 196 | " },\n" + 197 | " \"operation\": \"CREATE\",\n" + 198 | " \"outputs\": [\n" + 199 | " {\n" + 200 | " \"amount\": \"1\",\n" + 201 | " \"condition\": {\n" + 202 | " \"details\": {\n" + 203 | " \"public_key\": \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\",\n" + 204 | " \"type\": \"ed25519-sha-256\"\n" + 205 | " },\n" + 206 | " \"uri\": \"ni:///sha-256;PNYwdxaRaNw60N6LDFzOWO97b8tJeragczakL8PrAPc?fpt=ed25519-sha-256&cost=131072\"\n" + 207 | " },\n" + 208 | " \"public_keys\": [\n" + 209 | " \"4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD\"\n" + 210 | " ]\n" + 211 | " }\n" + 212 | " ],\n" + 213 | " \"version\": \"2.0\"\n" + 214 | "}"; 215 | 216 | 217 | 218 | 219 | 220 | /// 221 | /// Test get transaction. 222 | /// 223 | [Fact] 224 | public async Task testGetTransaction() 225 | { 226 | 227 | Transaction transaction = await TransactionsApi.getTransactionByIdAsync(TRANSACTION_ID); 228 | transaction.Id.ShouldBe(TRANSACTION_ID); 229 | } 230 | 231 | /// 232 | /// Test get transactions by assets id 233 | /// 234 | [Fact] 235 | public async Task testGetTransactionsByAsset() 236 | { 237 | var transactions = await TransactionsApi.getTransactionsByAssetIdAsync(TRANSACTION_ID, Operations.TRANSFER); 238 | transactions.Count.ShouldBe(2); 239 | } 240 | 241 | /// 242 | /// Test build transaction using builder. 243 | /// 244 | /// 245 | [Fact] 246 | public async Task testBuildCreateTransaction() 247 | { 248 | HelloAsset assetData = new HelloAsset("Hello!"); 249 | 250 | 251 | MetaData metaData = new MetaData(); 252 | metaData.Id = "51ce82a14ca274d43e4992bbce41f6fdeb755f846e48e710a3bbb3b0cf8e4204"; 253 | HelloMetadata data = new HelloMetadata(); 254 | data.msg = "My first transaction"; 255 | metaData.Metadata = data; 256 | 257 | Transaction transaction = 258 | BigchainDbTransactionBuilder 259 | .init() 260 | .addAssets(assetData) 261 | .addMetaData(metaData) 262 | .operation(Operations.CREATE) 263 | .buildAndSignOnly(BlockchainAccount.publicKeyFromHex(publicKey), 264 | BlockchainAccount.privateKeyFromHex(privateKey)); 265 | 266 | //string info = transaction.toHashInput(); 267 | transaction.Version.ShouldBe("2.0"); 268 | transaction.Asset.Data.ShouldNotBe(null); 269 | transaction.Operation.ShouldBe("CREATE"); 270 | 271 | Input input = transaction.Inputs[0]; 272 | input.OwnersBefore.ShouldNotBe(null); 273 | input.FulFillment.ShouldNotBe(null); 274 | // was null 275 | //input.FulFills.ShouldNotBe(null); 276 | 277 | Output output = transaction.Outputs[0]; 278 | output.Amount.ShouldNotBe(null); 279 | output.Condition.Uri.ShouldNotBe(null); 280 | output.Condition.Details.PublicKey.ShouldNotBe(null); 281 | output.Condition.Details.Type.ShouldNotBe(null); 282 | output.PublicKeys.ShouldNotBe(null); 283 | 284 | transaction.MetaData.Metadata.msg.ShouldBe("My first transaction"); 285 | } 286 | 287 | [Serializable] 288 | private class HelloAsset 289 | { 290 | [JsonProperty] 291 | public string msg { get; set; } 292 | 293 | public HelloAsset(string _msg) 294 | { 295 | this.msg = _msg; 296 | } 297 | 298 | } 299 | 300 | [Serializable] 301 | private class HelloMetadata 302 | { 303 | [JsonProperty] 304 | public string msg { get; set; } 305 | 306 | public HelloMetadata() 307 | { 308 | this.msg = "Hello bigchain!"; 309 | } 310 | 311 | } 312 | /// 313 | /// Test build only transaction. 314 | /// 315 | /// 316 | [Fact] 317 | public async Task testBuildOnlyCreateTransaction() 318 | { 319 | HelloAsset assetData = new HelloAsset("Hello BigchainDB!"); 320 | 321 | PublicKey edDSAPublicKey = BlockchainAccount.publicKeyFromHex(publicKey); 322 | FulFill fulFill = new FulFill(); 323 | fulFill.OutputIndex = 0; 324 | fulFill.TransactionId = "2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e"; 325 | 326 | Transaction transaction = BigchainDbTransactionBuilder 327 | .init() 328 | .addAssets(assetData) 329 | .addInput("pGSAIDE5i63cn4X8T8N1sZ2mGkJD5lNRnBM4PZgI_zvzbr-cgUCy4BR6gKaYT-tdyAGPPpknIqI4JYQQ-p2nCg3_9BfOI-15vzldhyz-j_LZVpqAlRmbTzKS-Q5gs7ZIFaZCA_UD", 330 | fulFill, edDSAPublicKey) 331 | .addOutput("1", edDSAPublicKey) 332 | .operation(Operations.CREATE).buildOnly(edDSAPublicKey); 333 | 334 | transaction.Version.ShouldBe("2.0"); 335 | transaction.Operation.ShouldBe("CREATE"); 336 | 337 | Input input = transaction.Inputs[0]; 338 | input.OwnersBefore.ShouldNotBe(null); 339 | input.FulFillment.ShouldNotBe(null); 340 | input.FulFills.ShouldNotBe(null); 341 | input.FulFills.OutputIndex.ShouldBe(0); 342 | input.FulFills.TransactionId.ShouldBe("2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e"); 343 | 344 | Output output = transaction.Outputs[0]; 345 | output.Amount.ShouldNotBe(null); 346 | output.Condition.Uri.ShouldNotBe(null); 347 | output.Condition.Details.PublicKey.ShouldNotBe(null); 348 | output.Condition.Details.Type.ShouldNotBe(null); 349 | output.PublicKeys.ShouldNotBe(null); 350 | 351 | } 352 | 353 | 354 | [Fact] 355 | public async Task testPostTransactionOfCreateUsingBuilder() 356 | { 357 | BlockchainAccount account = new BlockchainAccount(); 358 | ObjectDummy dummyAsset = new ObjectDummy(); 359 | dummyAsset.id = "id"; 360 | dummyAsset.description = "asset"; 361 | 362 | ObjectDummy dummyMeta = new ObjectDummy(); 363 | dummyMeta.id = "id"; 364 | dummyMeta.description = "meta"; 365 | 366 | var transaction = await BigchainDbTransactionBuilder 367 | .init().addAssets(dummyAsset) 368 | .addMetaData(dummyMeta) 369 | .operation(Operations.CREATE) 370 | .buildAndSign(account.PublicKey, account.Key).sendTransactionAsync(); 371 | 372 | transaction.Data.ShouldNotBe(null); 373 | transaction.Data.Id.ShouldNotBe(null); 374 | transaction.Data.Operation.ShouldBe("CREATE"); 375 | 376 | } 377 | /// 378 | /// Test post transaction using builder with call back. 379 | /// 380 | [Fact] 381 | public async Task testPostCreateTransactionUsingBuilderWithCallBack() 382 | { 383 | BlockchainAccount account = new BlockchainAccount(); 384 | 385 | Dictionary metaData = new Dictionary(); 386 | metaData.Add("what", "bigchaintrans"); 387 | 388 | Dictionary assetData = new Dictionary(); 389 | assetData.Add("firstname", "alvin"); 390 | 391 | var t = await BigchainDbTransactionBuilder, Dictionary> 392 | .init() 393 | .addAssets(assetData) 394 | .addMetaData(metaData) 395 | .operation(Operations.CREATE) 396 | .buildAndSign(account.PublicKey, account.Key) 397 | .sendTransactionAsync(new GenericCallbackAnonymousInnerClass()); 398 | 399 | } 400 | 401 | 402 | 403 | private class GenericCallbackAnonymousInnerClass : GenericCallback 404 | { 405 | 406 | public GenericCallbackAnonymousInnerClass() 407 | { 408 | 409 | } 410 | 411 | 412 | public void transactionMalformed(string response) 413 | { 414 | // System.out.println(response.message()); 415 | Console.WriteLine("malformed " + response); 416 | } 417 | 418 | public void pushedSuccessfully(string response) 419 | { 420 | Console.WriteLine("pushedSuccessfully"); 421 | } 422 | 423 | public void otherError(string response) 424 | { 425 | Console.WriteLine("otherError"); 426 | 427 | } 428 | } 429 | 430 | [Fact] 431 | public async Task testPostCreateTransactionOfObjectMetaDataUsingBuilder() 432 | { 433 | BlockchainAccount account = new BlockchainAccount(); 434 | 435 | ObjectDummy dummyAsset = new ObjectDummy(); 436 | dummyAsset.id = "id"; 437 | dummyAsset.description = "asset"; 438 | 439 | SomeMetaData metaData = new SomeMetaData(); 440 | metaData.properties.Add("one"); 441 | metaData.properties.Add("two"); 442 | metaData.properties.Add("three"); 443 | 444 | 445 | var transaction = await BigchainDbTransactionBuilder 446 | .init() 447 | .addAssets(dummyAsset) 448 | .addMetaData(metaData) 449 | .operation(Operations.CREATE) 450 | .buildAndSign(account.PublicKey, account.Key) 451 | .sendTransactionAsync(); 452 | 453 | transaction.Data.ShouldNotBe(null); 454 | transaction.Data.Id.ShouldNotBe(null); 455 | transaction.Data.Operation.ShouldBe("CREATE"); 456 | 457 | // check returned transaction to match properties 458 | transaction.Data.MetaData.Metadata.porperty2.ShouldBe(2); 459 | transaction.Data.MetaData.Metadata.properties.Count.ShouldBe(3); 460 | transaction.Data.MetaData.Metadata.properties[2].ShouldBe("three"); 461 | 462 | } 463 | 464 | [Serializable] 465 | private class ObjectDummy 466 | { 467 | [JsonProperty] 468 | public string id { get; set; } 469 | 470 | [JsonProperty] 471 | public string description { get; set; } 472 | 473 | public ObjectDummy() 474 | { 475 | 476 | } 477 | 478 | } 479 | 480 | [Serializable] 481 | public class SomeMetaData 482 | { 483 | [JsonProperty] 484 | public string property1 = "property1"; 485 | 486 | [JsonProperty] 487 | public int? porperty2 = 2; 488 | 489 | [JsonProperty] 490 | public decimal property3 = 3.3M; 491 | 492 | [JsonProperty] 493 | public int property4 = 4; 494 | 495 | [JsonProperty] 496 | public List properties = new List(); 497 | 498 | 499 | [JsonProperty] 500 | public DateTime date = DateTime.Now; 501 | 502 | public SomeMetaData() 503 | { 504 | } 505 | 506 | } 507 | 508 | } 509 | } 510 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/TransactionTransferApiTest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Omnibasis.BigchainCSharp.Api; 3 | using Omnibasis.BigchainCSharp.Builders; 4 | using Omnibasis.BigchainCSharp.Constants; 5 | using Omnibasis.BigchainCSharp.Model; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using Xunit; 11 | using Shouldly; 12 | using Omnibasis.CryptoConditionsCSharp; 13 | 14 | namespace BigchainCSharp_XUnitTest 15 | { 16 | /** 17 | * The Class TransactionTransferApiTest. 18 | */ 19 | public class TransactionTransferApiTest : AppTestBase 20 | { 21 | 22 | public TransactionTransferApiTest() : base() 23 | { 24 | 25 | } 26 | 27 | /// 28 | /// Test build transaction using builder. 29 | /// 30 | /// 31 | [Fact] 32 | public async Task testBuildTransferTransaction() 33 | { 34 | HelloAsset assetData = new HelloAsset("Hello BigchainDB!"); 35 | MetaData metaData = new MetaData(); 36 | 37 | Transaction transaction = BigchainDbTransactionBuilder 38 | .init() 39 | .addAssets(assetData) 40 | .operation(Operations.TRANSFER) 41 | .addMetaData(metaData) 42 | .buildAndSignOnly(BlockchainAccount.publicKeyFromHex(publicKey), BlockchainAccount.privateKeyFromHex(privateKey)); 43 | 44 | transaction.Version.ShouldBe("2.0"); 45 | transaction.Operation.ShouldBe("TRANSFER"); 46 | } 47 | 48 | [Serializable] 49 | private class HelloAsset 50 | { 51 | [JsonProperty] 52 | public string msg { get; set; } 53 | 54 | public HelloAsset(string _msg) 55 | { 56 | this.msg = _msg; 57 | } 58 | 59 | } 60 | 61 | [Serializable] 62 | private class HelloMetadata 63 | { 64 | [JsonProperty] 65 | public string msg { get; set; } 66 | 67 | public HelloMetadata() 68 | { 69 | } 70 | 71 | } 72 | 73 | [Serializable] 74 | private class TestToken 75 | { 76 | [JsonProperty] 77 | public string token { get; set; } 78 | [JsonProperty] 79 | public int number_tokens { get; set; } 80 | } 81 | 82 | [Serializable] 83 | private class TestAsset 84 | { 85 | [JsonProperty] 86 | public string msg { get; set; } 87 | [JsonProperty] 88 | public string city { get; set; } 89 | [JsonProperty] 90 | public string temperature { get; set; } 91 | [JsonProperty] 92 | public DateTime datetime { get; set; } 93 | } 94 | 95 | [Serializable] 96 | private class TestMetadata 97 | { 98 | [JsonProperty] 99 | public string msg { get; set; } 100 | } 101 | 102 | /// Test build transaction using builder. 103 | /// 104 | /// 105 | [Fact] 106 | public async Task testBuildAndTransferPartingTransaction() 107 | { 108 | var publicKeyObj = BlockchainAccount.publicKeyFromHex(publicKey); 109 | var privateKeyObj = BlockchainAccount.privateKeyFromHex(privateKey); 110 | 111 | TestAsset assetData = new TestAsset(); 112 | assetData.msg = "Hello!"; 113 | assetData.city = "San Diego"; 114 | assetData.temperature = "74"; 115 | assetData.datetime = DateTime.Now; 116 | 117 | TestMetadata metaData = new TestMetadata(); 118 | metaData.msg = "My first transaction"; 119 | 120 | // Set up, sign, and send your transaction 121 | var transaction = BigchainDbTransactionBuilder 122 | .init() 123 | .addAssets(assetData) 124 | .addMetaData(metaData) 125 | .operation(Operations.CREATE) 126 | .buildAndSignOnly(publicKeyObj, privateKeyObj); 127 | //.buildAndSign(account.PublicKey, account.PrivateKey); 128 | 129 | //var info = transaction.toHashInput(); 130 | var createTransaction = await TransactionsApi.sendTransactionAsync(transaction); 131 | 132 | createTransaction.Data.ShouldNotBe(null); 133 | // the asset's ID is equal to the ID of the transaction that created it 134 | if (createTransaction != null) 135 | { 136 | string testId2 = createTransaction.Data.Id; 137 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(testId2); 138 | testTran2.ShouldNotBe(null); 139 | 140 | } 141 | 142 | // Describe the output you are fulfilling on the previous transaction 143 | FulFill spendFrom = new FulFill(); 144 | // the asset's ID is equal to the ID of the transaction that created it 145 | spendFrom.TransactionId = createTransaction.Data.Id; 146 | spendFrom.OutputIndex = 0; 147 | 148 | // Change the metadata if you want 149 | TestMetadata transferMetadata = new TestMetadata(); 150 | transferMetadata.msg = "My second transaction"; 151 | 152 | // By default, the 'amount' of a created digital asset == "1". So we spend "1" in our TRANSFER. 153 | string amount = "1"; 154 | BlockchainAccount account = new BlockchainAccount(); 155 | Details details = null; 156 | // Use the previous transaction's asset and TRANSFER it 157 | var build2 = BigchainDbTransactionBuilder, TestMetadata>. 158 | init(). 159 | addMetaData(transferMetadata). 160 | addInput(details, spendFrom, publicKeyObj). 161 | addOutput(amount, account.Key.PublicKey). 162 | addAssets(createTransaction.Data.Id). 163 | operation(Operations.TRANSFER). 164 | buildAndSignOnly(publicKeyObj, privateKeyObj); 165 | 166 | var transferTransaction = await TransactionsApi, TestMetadata>.sendTransactionAsync(build2); 167 | transferTransaction.Data.ShouldNotBe(null); 168 | 169 | if (transferTransaction != null) 170 | { 171 | string tran2 = transferTransaction.Data.Id; 172 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(tran2); 173 | testTran2.ShouldNotBe(null); 174 | 175 | } 176 | 177 | 178 | 179 | } 180 | 181 | //https://www.bigchaindb.com/developers/guide/tutorial-token-launch/ 182 | [Fact] 183 | public async Task testTokensBuildAndTransferPartingTransaction() 184 | { 185 | var publicKeyObj = BlockchainAccount.publicKeyFromHex(publicKey); 186 | var privateKeyObj = BlockchainAccount.privateKeyFromHex(privateKey); 187 | 188 | int tokens = 10000; 189 | TestToken assetData = new TestToken(); 190 | assetData.token = "My Token on" + DateTime.Now.Ticks.ToString(); 191 | assetData.number_tokens = tokens; 192 | 193 | TestMetadata metaData = new TestMetadata(); 194 | metaData.msg = "My first transaction"; 195 | 196 | // Set up, sign, and send your transaction 197 | var transaction = BigchainDbTransactionBuilder 198 | .init() 199 | .addAssets(assetData) 200 | .addMetaData(metaData) 201 | .addOutput(tokens.ToString(), publicKeyObj) 202 | .operation(Operations.CREATE) 203 | .buildAndSignOnly(publicKeyObj, privateKeyObj); 204 | //.buildAndSign(account.PublicKey, account.PrivateKey); 205 | 206 | //var info = transaction.toHashInput(); 207 | var createTransaction = await TransactionsApi.sendTransactionAsync(transaction); 208 | 209 | createTransaction.Data.ShouldNotBe(null); 210 | // the asset's ID is equal to the ID of the transaction that created it 211 | if (createTransaction.Data != null) 212 | { 213 | string testId2 = createTransaction.Data.Id; 214 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(testId2); 215 | testTran2.ShouldNotBe(null); 216 | 217 | } 218 | 219 | // Describe the output you are fulfilling on the previous transaction 220 | FulFill spendFrom = new FulFill(); 221 | // the asset's ID is equal to the ID of the transaction that created it 222 | spendFrom.TransactionId = createTransaction.Data.Id; 223 | spendFrom.OutputIndex = 0; 224 | 225 | 226 | // we want to transfer 200 tokens. 227 | int amount = 200; 228 | //int amountFake = 20000; 229 | BlockchainAccount account = new BlockchainAccount(); 230 | Details details = null; 231 | TestToken transferData = new TestToken(); 232 | assetData.token = "To my cat"; 233 | assetData.number_tokens = amount; 234 | int amountLeft = tokens - amount; 235 | // Use the previous transaction's asset and TRANSFER it 236 | var build2 = BigchainDbTransactionBuilder, TestToken>. 237 | init(). 238 | addMetaData(transferData). 239 | addInput(details, spendFrom, publicKeyObj). 240 | addOutput(amountLeft.ToString(), publicKeyObj). 241 | addOutput(amount.ToString(), account.PublicKey). 242 | addAssets(createTransaction.Data.Id). 243 | operation(Operations.TRANSFER). 244 | buildAndSignOnly(publicKeyObj, privateKeyObj); 245 | 246 | var transferTransaction = await TransactionsApi, TestToken>.sendTransactionAsync(build2); 247 | transferTransaction.Data.ShouldNotBe(null); 248 | 249 | if (transferTransaction != null) 250 | { 251 | string tran2 = transferTransaction.Data.Id; 252 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(tran2); 253 | testTran2.ShouldNotBe(null); 254 | 255 | } 256 | var useThisKey = transferTransaction.Data.Outputs[0].PublicKeys[0]; 257 | var compKey = KeyPairUtils.encodePublicKeyInBase58(publicKeyObj); 258 | // get unspent outputs 259 | var list = await OutputsApi.getUnspentOutputsAsync(useThisKey); 260 | //list.Count.ShouldBe(1); 261 | // Describe the output you are fulfilling on spent outputs 262 | FulFill spendFrom2 = new FulFill(); 263 | // the asset's ID is equal to the ID of the transaction that created it 264 | spendFrom2.TransactionId = transferTransaction.Data.Id; // list[0].TransactionId; 265 | spendFrom2.OutputIndex = 0; 266 | 267 | BlockchainAccount dogAccount = new BlockchainAccount(); 268 | Details details2 = null; 269 | TestToken transferData2 = new TestToken(); 270 | transferData2.token = "To my dog"; 271 | transferData2.number_tokens = amount; 272 | 273 | amountLeft = amountLeft - amount; 274 | // Use the previous transaction's asset and TRANSFER it 275 | var build3 = BigchainDbTransactionBuilder, TestToken>. 276 | init(). 277 | addMetaData(transferData2). 278 | addInput(details2, spendFrom2, publicKeyObj). 279 | addOutput(amountLeft.ToString(), publicKeyObj). 280 | addOutput(amount.ToString(), dogAccount.PublicKey). 281 | addAssets(createTransaction.Data.Id). 282 | operation(Operations.TRANSFER). 283 | buildAndSignOnly(publicKeyObj, privateKeyObj); 284 | 285 | var transferTransaction3 = await TransactionsApi, TestToken>.sendTransactionAsync(build3); 286 | transferTransaction3.Data.ShouldNotBe(null); 287 | 288 | if (transferTransaction3 != null) 289 | { 290 | string tran2 = transferTransaction3.Data.Id; 291 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(tran2); 292 | testTran2.ShouldNotBe(null); 293 | 294 | } 295 | 296 | 297 | // now dog wants to share with puppy 298 | BlockchainAccount puppyAccount = new BlockchainAccount(); 299 | Details details3 = null; 300 | TestToken transferData3 = new TestToken(); 301 | transferData3.token = "To my puppy"; 302 | int topuppy = 100; 303 | transferData3.number_tokens = topuppy; 304 | 305 | FulFill spendFrom3 = new FulFill(); 306 | // the asset's ID is equal to the ID of the transaction that created it 307 | spendFrom3.TransactionId = transferTransaction3.Data.Id; // list[0].TransactionId; 308 | spendFrom3.OutputIndex = 1; 309 | 310 | amountLeft = amount - topuppy; 311 | // Use the previous transaction's asset and TRANSFER it 312 | var build4 = BigchainDbTransactionBuilder, TestToken>. 313 | init(). 314 | addMetaData(transferData3). 315 | addInput(details3, spendFrom3, dogAccount.PublicKey). 316 | addOutput(amountLeft.ToString(), dogAccount.PublicKey). 317 | addOutput(topuppy.ToString(), puppyAccount.PublicKey). 318 | addAssets(createTransaction.Data.Id). 319 | operation(Operations.TRANSFER). 320 | buildAndSignOnly(dogAccount.PublicKey, dogAccount.Key); 321 | 322 | 323 | 324 | var transferTransaction4 = await TransactionsApi, TestToken>.sendTransactionAsync(build4); 325 | if(transferTransaction4.Messsage != null) 326 | { 327 | var msg = transferTransaction4.Messsage.Message; 328 | } 329 | 330 | transferTransaction4.Data.ShouldNotBe(null); 331 | 332 | if (transferTransaction4 != null) 333 | { 334 | string tran2 = transferTransaction4.Data.Id; 335 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(tran2); 336 | testTran2.ShouldNotBe(null); 337 | 338 | } 339 | 340 | 341 | } 342 | 343 | 344 | } 345 | 346 | } 347 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/TransactionUpdateApiTest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Omnibasis.BigchainCSharp.Api; 3 | using Omnibasis.BigchainCSharp.Builders; 4 | using Omnibasis.BigchainCSharp.Constants; 5 | using Omnibasis.BigchainCSharp.Model; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using Xunit; 11 | using Shouldly; 12 | using Omnibasis.BigchainCSharp.Util; 13 | 14 | namespace BigchainCSharp_XUnitTest 15 | { 16 | /** 17 | * The Class TransactionUpdateApiTest. 18 | * https://www.bigchaindb.com/developers/guide/tutorial-car-telemetry-app/#update-of-an-asset-on-bigchaindb 19 | */ 20 | public class TransactionUpdateApiTest : AppTestBase 21 | { 22 | 23 | public TransactionUpdateApiTest() : base() 24 | { 25 | 26 | } 27 | 28 | [Serializable] 29 | private class Person 30 | { 31 | [JsonProperty] 32 | public string name { get; set; } 33 | 34 | [JsonProperty] 35 | public string birthday { get; set; } 36 | 37 | 38 | } 39 | 40 | [Serializable] 41 | private class Vehicle 42 | { 43 | [JsonProperty] 44 | public string id { get; set; } 45 | 46 | [JsonProperty] 47 | public string consumption { get; set; } 48 | 49 | 50 | } 51 | 52 | [Serializable] 53 | private class Gps 54 | { 55 | [JsonProperty] 56 | public string gps_identifier { get; set; } 57 | 58 | } 59 | 60 | 61 | 62 | [Serializable] 63 | private class Mileage 64 | { 65 | [JsonProperty] 66 | public string Amount { get; set; } 67 | } 68 | 69 | [Serializable] 70 | private class Status 71 | { 72 | [JsonProperty] 73 | public string Value { get; set; } 74 | } 75 | 76 | 77 | 78 | 79 | /// Test build transaction using builder. 80 | /// 81 | /// 82 | [Fact] 83 | public async Task testBuildAndTransferPartingTransaction() 84 | { 85 | var publicKeyObj = BlockchainAccount.publicKeyFromHex(publicKey); 86 | var privateKeyObj = BlockchainAccount.privateKeyFromHex(privateKey); 87 | 88 | Vehicle car = new Vehicle(); 89 | car.id = "92832938203903" + DateTime.Now.ToLongDateString(); 90 | car.consumption = "20.9"; 91 | 92 | // Set up, sign, and send your transaction 93 | var transaction = BigchainDbTransactionBuilder 94 | .init() 95 | .addAssets(car) 96 | .operation(Operations.CREATE) 97 | .buildAndSignOnly(publicKeyObj, privateKeyObj); 98 | //.buildAndSign(account.PublicKey, account.PrivateKey); 99 | 100 | //var info = transaction.toHashInput(); 101 | var createTransaction = await TransactionsApi.sendTransactionAsync(transaction); 102 | 103 | createTransaction.Data.ShouldNotBe(null); 104 | // the asset's ID is equal to the ID of the transaction that created it 105 | if (createTransaction != null) 106 | { 107 | string testId2 = createTransaction.Data.Id; 108 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(testId2); 109 | testTran2.ShouldNotBe(null); 110 | 111 | } 112 | 113 | // Describe the output you are fulfilling on the previous transaction 114 | FulFill spendFrom = new FulFill(); 115 | // the asset's ID is equal to the ID of the transaction that created it 116 | spendFrom.TransactionId = createTransaction.Data.Id; 117 | spendFrom.OutputIndex = 0; 118 | 119 | Mileage m = new Mileage(); 120 | m.Amount = "2000"; 121 | 122 | // By default, the 'amount' of a created digital asset == "1". So we spend "1" in our TRANSFER. 123 | string amount = "1"; 124 | Details details = null; 125 | // Use the previous transaction's asset and TRANSFER it 126 | var build2 = BigchainDbTransactionBuilder. 127 | init(). 128 | addInput(details, spendFrom, publicKeyObj). 129 | addOutput(amount, publicKeyObj). 130 | addAssets(createTransaction.Data.Id). 131 | operation(Operations.TRANSFER). 132 | buildAndSignOnly(publicKeyObj, privateKeyObj); 133 | 134 | var transferTransaction = await TransactionsApi.sendTransactionAsync(build2); 135 | transferTransaction.Data.ShouldNotBe(null); 136 | 137 | if (transferTransaction != null) 138 | { 139 | string tran2 = transferTransaction.Data.Id; 140 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(tran2); 141 | testTran2.ShouldNotBe(null); 142 | 143 | } 144 | 145 | 146 | 147 | } 148 | 149 | /// Test build transaction using builder. 150 | /// 151 | /// 152 | [Fact] 153 | public async Task testBurnTransaction() 154 | { 155 | var publicKeyObj = BlockchainAccount.publicKeyFromHex(publicKey); 156 | var privateKeyObj = BlockchainAccount.privateKeyFromHex(privateKey); 157 | 158 | Vehicle car = new Vehicle(); 159 | car.id = "92832938203903-" + DateTime.Now.Ticks.ToString(); 160 | car.consumption = "20.9"; 161 | 162 | // Set up, sign, and send your transaction 163 | var transaction = BigchainDbTransactionBuilder 164 | .init() 165 | .addAssets(car) 166 | .operation(Operations.CREATE) 167 | .buildAndSignOnly(publicKeyObj, privateKeyObj); 168 | //.buildAndSign(account.PublicKey, account.PrivateKey); 169 | 170 | //var info = transaction.toHashInput(); 171 | var createTransaction = await TransactionsApi.sendTransactionAsync(transaction); 172 | 173 | createTransaction.Data.ShouldNotBe(null); 174 | // the asset's ID is equal to the ID of the transaction that created it 175 | if (createTransaction != null) 176 | { 177 | string testId2 = createTransaction.Data.Id; 178 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(testId2); 179 | testTran2.ShouldNotBe(null); 180 | 181 | } 182 | 183 | // Describe the output you are fulfilling on the previous transaction 184 | FulFill spendFrom = new FulFill(); 185 | // the asset's ID is equal to the ID of the transaction that created it 186 | spendFrom.TransactionId = createTransaction.Data.Id; 187 | spendFrom.OutputIndex = 0; 188 | 189 | 190 | // By default, the 'amount' of a created digital asset == "1". So we spend "1" in our TRANSFER. 191 | string amount = "1"; 192 | var burnKey = new BlockchainAccount(); 193 | var burnKeyStr = Utils.ByteArrayToString(burnKey.ExportPublic()); 194 | var s = new Status(); 195 | s.Value = "BURNED"; 196 | Details details = null; 197 | // Use the previous transaction's asset and TRANSFER it 198 | var build2 = BigchainDbTransactionBuilder. 199 | init(). 200 | addInput(details, spendFrom, publicKeyObj). 201 | addOutput(amount, burnKey.PublicKey). 202 | addAssets(createTransaction.Data.Id). 203 | addMetaData(s). 204 | operation(Operations.TRANSFER). 205 | buildAndSignOnly(publicKeyObj, privateKeyObj); 206 | 207 | var transferTransaction = await TransactionsApi.sendTransactionAsync(build2); 208 | transferTransaction.Data.ShouldNotBe(null); 209 | 210 | if (transferTransaction != null) 211 | { 212 | string tran2 = transferTransaction.Data.Id; 213 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(tran2); 214 | testTran2.ShouldNotBe(null); 215 | 216 | string tran3 = transferTransaction.Data.Asset.Id; 217 | var testTran3 = await TransactionsApi.getTransactionByIdAsync(tran3); 218 | testTran3.ShouldNotBe(null); 219 | 220 | } 221 | 222 | 223 | 224 | } 225 | 226 | 227 | 228 | 229 | } 230 | 231 | } 232 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/ValidatorsApiTest.cs: -------------------------------------------------------------------------------- 1 | using Omnibasis.BigchainCSharp.Api; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Xunit; 7 | using Shouldly; 8 | 9 | namespace BigchainCSharp_XUnitTest 10 | { 11 | /** 12 | * The Class ValidatorsApiTest. 13 | */ 14 | public class ValidatorsApiTest : AppTestBase 15 | { 16 | 17 | public ValidatorsApiTest() : base() 18 | { 19 | 20 | } 21 | 22 | public static string V1_VALIDATORS_JSON = "[\n" + 23 | " {\n" + 24 | " \"pub_key\": {\n" + 25 | " \"data\":\"4E2685D9016126864733225BE00F005515200727FBAB1312FC78C8B76831255A\",\n" + 26 | " \"type\":\"ed25519\"\n" + 27 | " },\n" + 28 | " \"power\": 10\n" + 29 | " },\n" + 30 | " {\n" + 31 | " \"pub_key\": {\n" + 32 | " \"data\":\"608D839D7100466D6BA6BE79C320F8B81DE93CFAA58CF9768CF921C6371F2553\",\n" + 33 | " \"type\":\"ed25519\"\n" + 34 | " },\n" + 35 | " \"power\": 5\n" + 36 | " }\n" + 37 | "]"; 38 | 39 | /// 40 | /// Test get validators. 41 | /// 42 | [Fact] 43 | public async Task testGetValidators() 44 | { 45 | var validatorsArray = await ValidatorsApi.ValidatorsAsync(); 46 | validatorsArray.Count.ShouldBe(1); 47 | validatorsArray[0].VotingPower.ShouldBe(10); 48 | validatorsArray[0].PublicKey.Value.ShouldBe("DTbfPGcrWLynkLh0pv1ohnlsT41aozMpf8yMv1CV9zU="); 49 | validatorsArray[0].PublicKey.Type.ShouldBe("ed25519-base64"); 50 | } 51 | 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /BigchainCSharp_XUnitTest/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AppConfig": { 3 | "api:url": "https://test.ipdb.io", 4 | "status:retries": "300" 5 | } 6 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 4 | 5 | # Microsoft Net.core and Microsoft Dot.Net Driver for BigchainDB 6 | 7 | If you do not want to write code to run Blockchain, visit [omnibasis.com](https://omnibasis.com/) and use our simple to use user interface to build your distributed application on Blockchain. 8 | 9 | Looking to build Blockchain solution utilizing Microsoft .Net Core or .Net Framework? Omnibasis developed Microsoft drivers for BigchainDB. 10 | 11 | **Please note**: This driver is compatible with .Net Core 2.0 and later, and .Net Framework 4.6.x and later. It might work with earlier versions but was not tested. 12 | 13 | 14 | ## Compatibility 15 | 16 | | BigchainDB Server | Microsoft .Net Core and .Net Framework Driver | 17 | | ----------------- |-----------------------------------------------| 18 | | `2.x` | `2.x` | 19 | 20 | ## Contents 21 | 22 | * [Installation](#installation) 23 | * [Usage](#usage) 24 | * [API Wrappers](#api-wrappers) 25 | * [BigchainDB Documentation](#bigchaindb-documentation) 26 | * [Authors](#authors) 27 | * [Support](#support) 28 | 29 | ## Installation 30 | 31 | Download needed DLLs via nuget package manager. 32 | You will need to add Omnibasis.CryptoConditionsCSharp, Omnibasis.BigchainCSharp, NSec.Cryptography package dependency to your solution. 33 | 34 | 35 | 36 | ## Usage 37 | 38 | > .Net Core sample of an end-to-end CREATE and TRANSFER operation is available in the BigchainCSharp_Test directory 39 | 40 | > .Dot Framework sample of an end-to-end CREATE and TRANSFER operation is available in the BigchainCSharp_SimpleTest directory. 41 | 42 | > Test of ALL available APIs is available in the Test Solution BigchainCSharp_XUnitTest directory 43 | 44 | > Test of web socket monitor available APIs is available in the Test Solution BigchainCSharp_WS_Test directory 45 | 46 | ### Set Up Your Configuration 47 | 48 | #### Single-Node Setup 49 | 50 | ```c# 51 | var builder = BigchainDbConfigBuilder 52 | .baseUrl("https://test.ipdb.io/") 53 | .addToken("header1", ) 54 | .addToken("header2", ); 55 | await builder.setup(); 56 | ``` 57 | 58 | If you run synchronously, you can wrap the call to setup, like this: 59 | ```c# 60 | if (!AsyncContext.Run(() => builder.setup())) 61 | { 62 | Console.WriteLine("Failed to setup"); 63 | }; 64 | ``` 65 | 66 | #### Multi-Node Setup (More Robust and Reliable) 67 | 68 | > 69 | > **Assumption** - The following setup assumes that all nodes are all connected within same BigchainDB network. 70 | 71 | ```c# 72 | //define connections 73 | var conn1Config = new Dictionary(); 74 | 75 | //config connection 1 76 | conn1Config.Add("baseUrl", "https://test.ipdb.io"); 77 | BlockchainConnection conn1 = new BlockchainConnection(conn1Config); 78 | 79 | var conn2Config = new Dictionary(); 80 | var headers2 = new Dictionary(); 81 | //config connection 2 82 | conn2Config.Add("baseUrl", "https://test.ipdb.io"); 83 | BlockchainConnection conn2 = new BlockchainConnection(conn2Config); 84 | 85 | 86 | //add connections 87 | IList connections = new List(); 88 | connections.Add(conn1); 89 | connections.Add(conn2); 90 | //...You can add as many nodes as you want 91 | 92 | //multiple connections 93 | var builderWithConnections = BigchainDbConfigBuilder 94 | .addConnections(connections) 95 | .setTimeout(60000); //override default timeout of 20000 milliseconds 96 | 97 | await builderWithConnections.setup(); 98 | 99 | ``` 100 | 101 | ### Example: Prepare Keys, Assets and Metadata 102 | 103 | ```c# 104 | // prepare your key 105 | var algorithm = SignatureAlgorithm.Ed25519; 106 | var privateKey = Key.Import(algorithm, Utils.StringToByteArray(privateKeyString), KeyBlobFormat.PkixPrivateKey); 107 | var publicKey = PublicKey.Import(algorithm, Utils.StringToByteArray(publicKeyString), KeyBlobFormat.PkixPublicKey); 108 | 109 | Random random = new Random(); 110 | TestAsset assetData = new TestAsset(); 111 | assetData.msg = "Hello Omnibasis!"; 112 | assetData.city = "I was born in San Diego"; 113 | // note, need random temp, as the same asset cannot be stored twice as BigchainDB creates unique hash based on the asset content. 114 | assetData.temperature = random.Next(60, 80); 115 | assetData.datetime = DateTime.Now; 116 | 117 | TestMetadata metaData = new TestMetadata(); 118 | metaData.msg = "My first transaction"; 119 | ``` 120 | 121 | ### Example: Create an Asset 122 | 123 | Performing a CREATE transaction in BigchainDB allocates or issues a digital asset. 124 | 125 | ```c# 126 | // Set up, sign, and send your transaction 127 | var transaction = BigchainDbTransactionBuilder 128 | .init() 129 | .addAssets(assetData) 130 | .addMetaData(metaData) 131 | .operation(Operations.CREATE) 132 | .buildAndSignOnly(publicKey, privateKey); 133 | 134 | var createTransaction = await TransactionsApi.sendTransactionAsync(transaction); 135 | 136 | string assetId2 = ""; 137 | // the asset's ID is equal to the ID of the transaction that created it 138 | if (createTransaction != null && createTransaction.Data != null) 139 | { 140 | assetId2 = createTransaction.Data.Id; 141 | var testTran2 = await TransactionsApi.getTransactionByIdAsync(assetId2); 142 | if(testTran2 != null) 143 | Console.WriteLine("Hello assetId: " + assetId2); 144 | else 145 | Console.WriteLine("Failed to find assetId: " + assetId2); 146 | 147 | } 148 | else if (createTransaction != null) 149 | { 150 | Console.WriteLine("Failed to send transaction: " + createTransaction.Messsage.Message); 151 | } 152 | ``` 153 | 154 | ### Example: Transfer an Asset 155 | 156 | Performing a TRANSFER transaction in BigchainDB changes an asset's ownership (or, more accurately, authorized signers): 157 | 158 | ```c# 159 | // continue from example above, where we know the asset id 160 | 161 | if(!string.IsNullOrEmpty(assetId2) && testTransfer) 162 | { 163 | // Describe the output you are fulfilling on the previous transaction 164 | FulFill spendFrom = new FulFill(); 165 | spendFrom.TransactionId = assetId2; 166 | spendFrom.OutputIndex = 0; 167 | 168 | // Change the metadata if you want 169 | TestMetadata transferMetadata = new TestMetadata(); 170 | transferMetadata.msg = "My second transaction"; 171 | 172 | // the asset's ID is equal to the ID of the transaction that created it 173 | // By default, the 'amount' of a created digital asset == "1". So we spend "1" in our TRANSFER. 174 | string amount = "1"; 175 | BlockchainAccount account = new BlockchainAccount(); 176 | Details details = null; 177 | // Use the previous transaction's asset and TRANSFER it 178 | var build2 = BigchainDbTransactionBuilder, TestMetadata>. 179 | init(). 180 | addMetaData(metaData). 181 | addInput(details, spendFrom, publicKey). 182 | addOutput("1", account.Key.PublicKey). 183 | addAssets(assetId2). 184 | operation(Operations.TRANSFER). 185 | buildAndSignOnly(publicKey, privateKey); 186 | 187 | var transferTransaction = await TransactionsApi, TestMetadata>.sendTransactionAsync(build2); 188 | 189 | if (transferTransaction != null && transferTransaction.Data != null) 190 | { 191 | string assetIdTransfer = transferTransaction.Data.Id; 192 | var testTran2 = AsyncContext.Run(() => TransactionsApi.getTransactionByIdAsync(assetIdTransfer)); 193 | if (testTran2 != null) 194 | Console.WriteLine("Hello transfer assetId: " + assetIdTransfer); 195 | else 196 | Console.WriteLine("Failed to find transfer assetId: " + assetIdTransfer); 197 | 198 | } 199 | else if (transferTransaction !=webSocketMonitornull) 200 | { 201 | Console.WriteLine("Failed to send transaction: " + createTransaction.Messsage.Message); 202 | } 203 | 204 | } 205 | ``` 206 | 207 | ### Example: Setup Config with WebSocket Listener 208 | 209 | ```c# 210 | public class ValidTransactionMessageHandler : MessageHandler 211 | { 212 | public void handleMessage(string message) 213 | { 214 | ValidTransaction validTransaction = JsonConvert.DeserializeObject(message); 215 | Console.WriteLine("validTransaction: " + validTransaction.TransactionId); 216 | } 217 | 218 | } 219 | 220 | // config 221 | BigchainDbConfigBuilder 222 | .baseUrl("https://test.ipdb.io/") 223 | .webSocketMonitor(new ValidTransactionMessageHandler()) 224 | .setup(); 225 | ``` 226 | 227 | ### More Examples 228 | 229 | #### Example: Create a Transaction (without signing and without sending) 230 | 231 | ```c# 232 | HelloAsset assetData = new HelloAsset("Hello!"); 233 | 234 | MetaData metaData = new MetaData(); 235 | metaData.Id = "51ce82a14ca274d43e4992bbce41f6fdeb755f846e48e710a3bbb3b0cf8e4204"; 236 | HelloMetadata data = new HelloMetadata(); 237 | data.msg = "My first transaction"; 238 | metaData.Metadata = data; 239 | 240 | Transaction transaction = 241 | BigchainDbTransactionBuilder 242 | .init() 243 | .addAssets(assetData) 244 | .addMetaData(metaData) 245 | .operation(Operations.CREATE); 246 | ``` 247 | 248 | #### Example: Create and Sign Transaction (without sending it to the ledger) 249 | 250 | ```c# 251 | HelloAsset assetData = new HelloAsset("Hello!"); 252 | 253 | MetaData metaData = new MetaData(); 254 | metaData.Id = "51ce82a14ca274d43e4992bbce41f6fdeb755f846e48e710a3bbb3b0cf8e4204"; 255 | HelloMetadata data = new HelloMetadata(); 256 | data.msg = "My first transaction"; 257 | metaData.Metadata = data; 258 | 259 | Transaction transaction = 260 | BigchainDbTransactionBuilder 261 | .init() 262 | .addAssets(assetData) 263 | .addMetaData(metaData) 264 | .operation(Operations.CREATE) 265 | .buildAndSignOnly(BlockchainAccount.publicKeyFromHex(publicKey), 266 | BlockchainAccount.privateKeyFromHex(privateKey)); 267 | ``` 268 | 269 | ## API Wrappers 270 | 271 | ### Configuration Builder 272 | Default configuration builder is used inside API if none is provided with API call. 273 | 274 | You can override a default builder by implementing IBlockchainConfigurationBuilder 275 | ```c# 276 | /// 277 | /// The Interface IBlockchainConfigurationBuilder. 278 | /// 279 | public interface IBlockchainConfigurationBuilder 280 | { 281 | 282 | /// 283 | /// Adds the token. 284 | /// 285 | /// the key 286 | /// the map 287 | /// the i tokens 288 | IBlockchainConfigurationBuilder addToken(string key, string map); 289 | 290 | /// 291 | /// Web socket monitor. 292 | /// 293 | /// the message handler 294 | /// the i tokens 295 | IBlockchainConfigurationBuilder webSocketMonitor(MessageHandler messageHandler); 296 | 297 | /// 298 | /// override timeout for connections discovery and requests 299 | /// timeout in milliseconds 300 | /// i tokens 301 | IBlockchainConfigurationBuilder setTimeout(int timeInMs); 302 | 303 | /// 304 | /// Setup. 305 | /// 306 | Task setup(bool verifyConnection = true); 307 | 308 | /// 309 | /// indicates if connection to a current node still successful 310 | /// 311 | bool Connected { get; set; } 312 | 313 | /// 314 | /// handle connection failure and update meta values for current connection 315 | void processConnectionFailure(); 316 | 317 | /// 318 | /// handle successful connection and reset meta values for current connection 319 | /// 320 | void processConnectionSuccess(); 321 | 322 | /// 323 | /// configure nodes and reset timeout 324 | /// exception on timeout 325 | Task configure(bool verifyConnection = true); 326 | 327 | /// 328 | /// timeout (defaults to 20000 ms) 329 | /// 330 | int Timeout { get; } 331 | 332 | /// 333 | /// Gets the base url. 334 | /// 335 | /// the base url 336 | string BaseUrl { get; } 337 | 338 | /// 339 | /// Gets the authorization tokens. 340 | /// 341 | /// the authorization tokens 342 | IDictionary AuthorizationTokens { get; } 343 | 344 | 345 | } 346 | ``` 347 | 348 | ### Transactions 349 | 350 | #### Send a Transaction 351 | 352 | ```c# 353 | public static async Task>> sendTransactionAsync(Transaction transaction, IBlockchainConfigurationBuilder builder = null) 354 | ``` 355 | 356 | #### Send a Transaction with Callback 357 | 358 | ```c# 359 | public static async Task>> sendTransactionAsync(Transaction transaction, 360 | GenericCallback callback, 361 | IBlockchainConfigurationBuilder builder = null) 362 | ``` 363 | 364 | #### Get Transaction given a Transaction Id 365 | 366 | ```c# 367 | public static async Task> getTransactionByIdAsync(string id, IBlockchainConfigurationBuilder builder = null) 368 | ``` 369 | 370 | #### Get Transaction given an Asset Id 371 | 372 | ```c# 373 | public static async Task>> getTransactionsByAssetIdAsync(string assetId, 374 | string operation = null, 375 | IBlockchainConfigurationBuilder builder = null) 376 | ``` 377 | 378 | ### Outputs 379 | 380 | #### Get Outputs given a public key 381 | 382 | ```c# 383 | public static async Task> getOutputsAsync(string publicKey, 384 | IBlockchainConfigurationBuilder builder = null) 385 | ``` 386 | 387 | #### Get Spent Outputs given a public key 388 | 389 | ```c# 390 | public static async Task> getSpentOutputsAsync(string publicKey, 391 | IBlockchainConfigurationBuilder builder = null) 392 | ``` 393 | 394 | #### Get Unspent Outputs given a public key 395 | 396 | ```c# 397 | public static async Task> getUnspentOutputsAsync(string publicKey, 398 | IBlockchainConfigurationBuilder builder = null) 399 | ``` 400 | 401 | ### Assets 402 | 403 | #### Get Assets given search key 404 | 405 | ```c# 406 | public static async Task>> getAssetsAsync(string searchKey, 407 | IBlockchainConfigurationBuilder builder = null) 408 | ``` 409 | 410 | #### Get Assets given search key and limit 411 | 412 | ```c# 413 | public static async Task>> getAssetsWithLimitAsync(string searchKey, int limit, 414 | IBlockchainConfigurationBuilder builder = null) 415 | ``` 416 | 417 | ### Blocks 418 | 419 | #### Get Blocks given block id 420 | 421 | ```c# 422 | public static async Task getBlock(int blockId, 423 | IBlockchainConfigurationBuilder builder = null) 424 | ``` 425 | 426 | #### Get Blocks given transaction id 427 | 428 | ```c# 429 | public static async Task> getBlocksByTransactionIdAsync(string transactionId, 430 | IBlockchainConfigurationBuilder builder = null) 431 | ``` 432 | 433 | ### MetaData 434 | 435 | #### Get MetaData given search key 436 | 437 | ```c# 438 | public static async Task>> getMetaDataAsync(string searchKey, 439 | IBlockchainConfigurationBuilder builder = null) 440 | ``` 441 | 442 | #### Get MetaData given search key and limit 443 | 444 | ```c# 445 | public static async Task>> getMetaDataWithLimitAsync(string searchKey, int limit, 446 | IBlockchainConfigurationBuilder builder = null) 447 | ``` 448 | 449 | ### Validators 450 | 451 | #### Gets the the local validators set of a given node 452 | 453 | ```c# 454 | public static async Task> ValidatorsAsync(IBlockchainConfigurationBuilder builder = null) 455 | ``` 456 | 457 | ## BigchainDB Documentation 458 | 459 | * [HTTP API Reference](https://docs.bigchaindb.com/projects/server/en/latest/http-client-server-api.html) 460 | * [The Transaction Model](https://docs.bigchaindb.com/projects/server/en/latest/metadata-models/transaction-model.html?highlight=crypto%20conditions) 461 | * [Inputs and Outputs](https://docs.bigchaindb.com/projects/server/en/latest/metadata-models/inputs-outputs.html) 462 | * [Asset Transfer](https://docs.bigchaindb.com/projects/py-driver/en/latest/usage.html#asset-transfer) 463 | * [All BigchainDB Documentation](https://docs.bigchaindb.com/) 464 | 465 | ## Authors 466 | 467 | The [Omnibasis](https://omnibasis.com) team. 468 | 469 | ## Support 470 | 471 | Included APIs provided as is. If you find an issue with API, please submit the issue. Help is always available at [Omnibasis Developer Site](https://help.omnibasis.com) 472 | 473 | 474 | --------------------------------------------------------------------------------