-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathProgram.cs
More file actions
90 lines (76 loc) · 2.85 KB
/
Program.cs
File metadata and controls
90 lines (76 loc) · 2.85 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Linq;
using NBitcoin;
using NBitcoin.OpenAsset;
// ReSharper disable All
namespace _4._1UnitTests
{
internal class Program
{
private static void Main()
{
var gold = new Key();
var silver = new Key();
var goldId = gold.PubKey.ScriptPubKey.Hash.ToAssetId();
var silverId = silver.PubKey.ScriptPubKey.Hash.ToAssetId();
var bob = new Key();
var alice = new Key();
var satoshi = new Key();
var init = new Transaction
{
Outputs =
{
new TxOut("1.0", gold),
new TxOut("1.0", silver),
new TxOut("1.0", satoshi)
}
};
var repo = new NoSqlColoredTransactionRepository();
repo.Transactions.Put(init);
ColoredTransaction color = ColoredTransaction.FetchColors(init, repo);
Console.WriteLine(color);
var issuanceCoins =
init
.Outputs
.AsCoins()
.Take(2)
.Select((c, i) => new IssuanceCoin(c))
.OfType<ICoin>()
.ToArray();
var builder = new TransactionBuilder();
var sendGoldToSatoshi =
builder
.AddKeys(gold)
.AddCoins(issuanceCoins[0])
.IssueAsset(satoshi, new AssetMoney(goldId, 10))
.SetChange(gold)
.BuildTransaction(true);
repo.Transactions.Put(sendGoldToSatoshi);
color = ColoredTransaction.FetchColors(sendGoldToSatoshi, repo);
Console.WriteLine(color);
var goldCoin = ColoredCoin.Find(sendGoldToSatoshi, color).FirstOrDefault();
builder = new TransactionBuilder();
var sendToBobAndAlice =
builder
.AddKeys(satoshi)
.AddCoins(goldCoin)
.SendAsset(alice, new AssetMoney(goldId, 4))
.SetChange(satoshi)
.BuildTransaction(true);
var satoshiBtc = init.Outputs.AsCoins().Last();
builder = new TransactionBuilder();
var sendToAlice =
builder
.AddKeys(satoshi)
.AddCoins(goldCoin, satoshiBtc)
.SendAsset(alice, new AssetMoney(goldId, 4))
.SetChange(satoshi)
.BuildTransaction(true);
repo.Transactions.Put(sendToAlice);
color = ColoredTransaction.FetchColors(sendToAlice, repo);
Console.WriteLine(sendToAlice);
Console.WriteLine(color);
Console.ReadLine();
}
}
}