Skip to content
Permalink
Browse files

Turn singular Recipient to plural UpdatedAddresses

  • Loading branch information...
dahlia committed Mar 8, 2019
1 parent 7571090 commit 31b87ae62332b88f000a3a6a6eaed3f856635f41
@@ -22,6 +22,15 @@ To be released.
`AddressStateMap` to `IAccountStateDelta`.
- Removed `IAction.RequestStates()` method because there is no need for it
and thus it is not used anymore.
- `Transaction<T>.Recipient` and `RawTransaction.Recipient` properties were
replaced by `Transaction<T>.UpdatedAddresses` and
`RawTransaction.UpdatedAddresses` properties.
The corresponding parameter names on constructors and methods were
replaced too.
- Since the schema of `RawTransaction` class was changed, the serialization
format of transactions and blocks were also changed. It affects to
the way to generate `Transaction<T>.Signature`, `Transaction<T>.Id`, and
`Block.Hash` values as well.
- The type of `Peer.Urls` property was changed from `Uri` to `IPEndPoint`.
- Since we decided to depend on TURN ([RFC 5766]) and STUN ([RFC 5389]) to
work around NAT so that `Peer`'s endpoints don't have to be multiple,
@@ -136,7 +136,8 @@ public IActionResult getTransaction(string txIdString)
Signature = tx.Signature,
Timestamp = tx.Timestamp,
Signer = tx.Signer.ToHex(),
Recipient = tx.Recipient.ToHex(),
UpdatedAddresses = tx.UpdatedAddresses
.Select(a => a.ToHex()).ToArray(),
Actions = tx.Actions
.Select(act => new Dictionary<string, object>
{
@@ -11,7 +11,7 @@ public class TransactionViewModel
public byte[] Signature { get; set; }
public DateTimeOffset Timestamp { get; set; }
public string Signer { get; set; }
public string Recipient { get; set; }
public string[] UpdatedAddresses { get; set; }
public IEnumerable<Dictionary<string, object>> Actions { get; set; }
}
}
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Drawing.Design;
using System.Linq;
using System.Security.Cryptography;
using Libplanet.Action;
using Libplanet.Blockchain;
using Libplanet.Blockchain.Policies;
@@ -110,7 +108,7 @@ public void ProcessActions()
};
Transaction<BaseAction> tx1 = Transaction<BaseAction>.Make(
new PrivateKey(),
_fx.Address1,
ImmutableHashSet.Create(_fx.Address1),
actions1,
DateTimeOffset.UtcNow
);
@@ -143,7 +141,7 @@ public void ProcessActions()
};
Transaction<BaseAction> tx2 = Transaction<BaseAction>.Make(
new PrivateKey(),
_fx.Address1,
ImmutableHashSet.Create(_fx.Address1),
actions2,
DateTimeOffset.UtcNow
);
@@ -176,13 +174,31 @@ public void CanStoreAddresses()
{
_fx.Transaction1,
_fx.Transaction2,
_fx.MakeTransaction(
new[]
{
new Attack
{
Weapon = "sword",
Target = "goblin",
TargetAddress = _fx.Address1,
},
},
new[] { _fx.Address1 }.ToImmutableHashSet()
),
};
_blockChain.StageTransactions(txs);
_blockChain.MineBlock(_fx.Address1);

Assert.NotEmpty(_blockChain.Addresses);
Assert.Contains(_fx.Transaction1, _blockChain.Addresses[_fx.Transaction1.Recipient]);
Assert.DoesNotContain(_fx.Transaction2, _blockChain.Addresses[_fx.Transaction1.Recipient]);
Assert.Contains(_fx.Address1, _blockChain.Addresses);
foreach (Address a in _fx.Transaction1.UpdatedAddresses)
{
Assert.Contains(_fx.Transaction1, _blockChain.Addresses[a]);
Assert.DoesNotContain(
_fx.Transaction2,
_blockChain.Addresses[a]
);
}
}

[Fact]
@@ -249,17 +265,20 @@ public void CanGetBlockLocator()
}

[Fact]
public void CanEvaluateActions()
public void EvaluateActions()
{
PrivateKey fromPrivateKey = new PrivateKey();
Address fromAddress = fromPrivateKey.PublicKey.ToAddress();
Address toAddress = _fx.Address1;
long blockIndex = 0;

TestEvaluateAction action = new TestEvaluateAction();
Transaction<BaseAction> tx1 = Transaction<BaseAction>.Make(
fromPrivateKey,
toAddress,
new[]
{
TestEvaluateAction.SignerKey,
TestEvaluateAction.BlockIndexKey,
}.ToImmutableHashSet(),
new List<BaseAction> { action },
DateTimeOffset.UtcNow
);
@@ -81,14 +81,14 @@ public void ToBencodex()
[Fact]
public void FromBencodex()
{
var encoded = new byte[]
byte[] encoded =
{
0x64, 0x31, 0x30, 0x3a, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63,
0x75, 0x6c, 0x74, 0x79, 0x69, 0x31, 0x65, 0x34, 0x3a, 0x68,
0x61, 0x73, 0x68, 0x33, 0x32, 0x3a, 0xc1, 0x04, 0xda, 0xf5,
0xcc, 0x56, 0x6d, 0x81, 0x3d, 0xfc, 0xae, 0xba, 0x32, 0x65,
0x2d, 0x98, 0x87, 0x07, 0x9a, 0x7a, 0x5f, 0x12, 0x22, 0xd7,
0xe0, 0x1f, 0xea, 0x6a, 0xbb, 0x91, 0x4e, 0x50, 0x35, 0x3a,
0x61, 0x73, 0x68, 0x33, 0x32, 0x3a, 0xfd, 0x53, 0xab, 0x50,
0xb0, 0x64, 0xd2, 0xf9, 0x31, 0x08, 0x13, 0xa4, 0x36, 0x27,
0x39, 0xce, 0x1a, 0x8d, 0x1e, 0xbe, 0x84, 0xd2, 0xdc, 0x7f,
0xea, 0x98, 0x32, 0xe3, 0x2a, 0x68, 0x35, 0xf9, 0x35, 0x3a,
0x69, 0x6e, 0x64, 0x65, 0x78, 0x69, 0x31, 0x65, 0x35, 0x3a,
0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x34, 0x3a, 0x02, 0x00, 0x00,
0x00, 0x31, 0x33, 0x3a, 0x70, 0x72, 0x65, 0x76, 0x69, 0x6f,
@@ -130,26 +130,27 @@ public void FromBencodex()
0x09, 0xf7, 0x32, 0x80, 0x87, 0x11, 0xec, 0x97, 0xaf, 0x6e,
0x34, 0x1f, 0x11, 0x0a, 0x32, 0x6d, 0xa1, 0xbd, 0xb8, 0x1f,
0x5a, 0xe3, 0xba, 0xdf, 0x76, 0xa9, 0x0b, 0x22, 0xc8, 0xc4,
0x91, 0xae, 0xd3, 0xaa, 0xa2, 0x96, 0x39, 0x3a, 0x72, 0x65,
0x63, 0x69, 0x70, 0x69, 0x65, 0x6e, 0x74, 0x32, 0x30, 0x3a,
0xc2, 0xa8, 0x60, 0x14, 0x07, 0x3d, 0x66, 0x2a, 0x4a, 0x9b,
0xfc, 0xf9, 0xcb, 0x54, 0x26, 0x3d, 0xfa,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0x8a, 0x02, 0x27, 0x4c, 0x76, 0x30,
0xee, 0x19, 0x6d, 0x26, 0x48, 0x0b, 0xb5, 0x10, 0x7a, 0x3d,
0xf5, 0x6b, 0x80, 0x3d, 0x55, 0x20, 0xcb, 0x4b, 0x23, 0x63,
0xc2, 0x11, 0xda, 0x14, 0x8d, 0x39, 0x3a, 0x74, 0x69, 0x6d,
0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x75, 0x32, 0x37, 0x3a,
0x32, 0x30, 0x31, 0x38, 0x2d, 0x31, 0x31, 0x2d, 0x32, 0x31,
0x54, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x2e,
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x65, 0x65, 0x65,
0xbc, 0x39, 0x3a, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61,
0x6d, 0x70, 0x75, 0x32, 0x37, 0x3a, 0x32, 0x30, 0x31, 0x38,
0x2d, 0x31, 0x31, 0x2d, 0x32, 0x31, 0x54, 0x30, 0x30, 0x3a,
0x30, 0x30, 0x3a, 0x30, 0x30, 0x2e, 0x30, 0x30, 0x30, 0x30,
0x30, 0x30, 0x5a, 0x31, 0x37, 0x3a, 0x75, 0x70, 0x64, 0x61,
0x74, 0x65, 0x64, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73,
0x73, 0x65, 0x73, 0x32, 0x30, 0x3a, 0xc2, 0xa8, 0x60, 0x14,
0x07, 0x3d, 0x66, 0x2a, 0x4a, 0x9b, 0xfc, 0xf9, 0xcb, 0x54,
0x26, 0x3d, 0xfa, 0x4f, 0x5c, 0xbc, 0x65, 0x65, 0x65,
};
Block<BaseAction> actual = Block<BaseAction>.FromBencodex(encoded);
Assert.Equal(_fx.HasTx, actual);

This file was deleted.

Oops, something went wrong.
@@ -19,7 +19,8 @@ public class Sleep : BaseAction

public override IAccountStateDelta Execute(IActionContext context)
{
throw new NotSupportedException();
// No-op.
return context.PreviousStates;
}

public override void LoadPlainValue(
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<IsPackable>false</IsPackable>
@@ -423,7 +423,7 @@ public async Task CanGetTx()

Transaction<BaseAction> tx = Transaction<BaseAction>.Make(
new PrivateKey(),
new PrivateKey().PublicKey.ToAddress(),
ImmutableHashSet<Address>.Empty,
new BaseAction[] { },
DateTimeOffset.UtcNow
);
@@ -469,7 +469,7 @@ public async Task CanBroadcastTx()

Transaction<BaseAction> tx = Transaction<BaseAction>.Make(
new PrivateKey(),
new PrivateKey().PublicKey.ToAddress(),
ImmutableHashSet<Address>.Empty,
new BaseAction[] { },
DateTimeOffset.UtcNow
);
@@ -56,26 +56,33 @@ public void CanIterateItems()
Assert.Empty(_set.Keys);
Assert.Empty(_set.Values);

_fx.Store.AppendAddressTransactionId(
_fx.StoreNamespace,
_fx.Transaction1.Recipient,
_fx.Transaction1.Id
);
_fx.Store.AppendAddressTransactionId(
_fx.StoreNamespace,
_fx.Transaction2.Recipient,
_fx.Transaction2.Id
);
foreach (Address a in _fx.Transaction1.UpdatedAddresses)
{
_fx.Store.AppendAddressTransactionId(
_fx.StoreNamespace,
a,
_fx.Transaction1.Id
);
}

foreach (Address a in _fx.Transaction2.UpdatedAddresses)
{
_fx.Store.AppendAddressTransactionId(
_fx.StoreNamespace,
a,
_fx.Transaction2.Id
);
}

_fx.Store.PutTransaction(_fx.StoreNamespace, _fx.Transaction1);
_fx.Store.PutTransaction(_fx.StoreNamespace, _fx.Transaction2);

Assert.Equal(
new HashSet<Address>()
{
_fx.Transaction1.Recipient,
_fx.Transaction2.Recipient,
},
_set.Keys.ToHashSet());
_fx.Transaction1.UpdatedAddresses.Union(
_fx.Transaction2.UpdatedAddresses
),
_set.Keys.ToHashSet()
);
}

[Fact]
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Security.Cryptography;
using Libplanet.Blocks;
@@ -77,8 +78,8 @@ public FileStoreFixture()
Block2 = TestUtils.MineNext(Block1);
Block3 = TestUtils.MineNext(Block2);

Transaction1 = MakeTransaction();
Transaction2 = MakeTransaction();
Transaction1 = MakeTransaction(new List<BaseAction>(), ImmutableHashSet<Address>.Empty);
Transaction2 = MakeTransaction(new List<BaseAction>(), ImmutableHashSet<Address>.Empty);
}

public string Path { get; }
@@ -121,15 +122,18 @@ public void Dispose()
}
}

private Transaction<BaseAction> MakeTransaction()
public Transaction<BaseAction> MakeTransaction(
IEnumerable<BaseAction> actions = null,
ImmutableHashSet<Address> updatedAddresses = null
)
{
var privateKey = new PrivateKey();
Address recipient = privateKey.PublicKey.ToAddress();
var timestamp = new DateTimeOffset(2018, 11, 21, 0, 0, 0, TimeSpan.Zero);
var timestamp =
new DateTimeOffset(2018, 11, 21, 0, 0, 0, TimeSpan.Zero);
return Transaction<BaseAction>.Make(
privateKey,
recipient,
new List<BaseAction>(),
updatedAddresses ?? ImmutableHashSet<Address>.Empty,
new List<BaseAction>(actions ?? new BaseAction[0]),
timestamp
);
}
Oops, something went wrong.

0 comments on commit 31b87ae

Please sign in to comment.
You can’t perform that action at this time.