Skip to content
Permalink
Browse files

Merge pull request #350 from earlbread/change-lookup-state-reference

Change return value of LookupStateReference
  • Loading branch information...
earlbread committed Jul 11, 2019
2 parents b889e9a + 7c8a845 commit f418686a0ed40e8468550fe57c4605adbc60e7fd
@@ -8,13 +8,20 @@ To be released.

### Backward-incompatible interface changes

- `StoreExtension.LookupStateReference<T>()` method became to return
`Tuple<HashDigest<SHA256>, long>` which is a nullable tuple of `Block<T>.Hash`
and `Block<T>.Index`. [[#350]]

### Added interfaces

### Behavioral changes

### Bug fixes


[#350]: https://github.com/planetarium/libplanet/pull/350


Version 0.4.1
-------------

@@ -417,20 +417,20 @@ public void ForkStateReferences()

Assert.Equal(
Tuple.Create(b1.Hash, b1.Index),
forked.Store.LookupStateReferenceWithIndex(fId, addr1, forked.Tip));
forked.Store.LookupStateReference(fId, addr1, forked.Tip));
Assert.Null(
forked.Store.LookupStateReferenceWithIndex(fId, addr2, forked.Tip));
forked.Store.LookupStateReference(fId, addr2, forked.Tip));

// Fork from b2.
forked = _blockChain.Fork(b2.Hash);
fId = forked.Id.ToString();

Assert.Equal(
Tuple.Create(b1.Hash, b1.Index),
forked.Store.LookupStateReferenceWithIndex(fId, addr1, forked.Tip));
forked.Store.LookupStateReference(fId, addr1, forked.Tip));
Assert.Equal(
Tuple.Create(b2.Hash, b2.Index),
forked.Store.LookupStateReferenceWithIndex(fId, addr2, forked.Tip));
forked.Store.LookupStateReference(fId, addr2, forked.Tip));
}

[Fact]
@@ -787,7 +787,7 @@ HashDigest<SHA256>[] ListStateReferences(Address address)
while (true)
{
Tuple<HashDigest<SHA256>, long> sr =
store.LookupStateReferenceWithIndex(@namespace, address, block);
store.LookupStateReference(@namespace, address, block);
if (sr?.Item1 is HashDigest<SHA256> reference)
{
refs.Add(reference);
@@ -47,31 +47,31 @@ public void LookupStateReference(StoreFixture fx)
Assert.Null(fx.Store.LookupStateReference(fx.StoreNamespace, address, fx.Block3));
Assert.Equal(
Tuple.Create(block4.Hash, block4.Index),
fx.Store.LookupStateReferenceWithIndex(fx.StoreNamespace, address, block4)
fx.Store.LookupStateReference(fx.StoreNamespace, address, block4)
);
Assert.Equal(
Tuple.Create(block4.Hash, block4.Index),
fx.Store.LookupStateReferenceWithIndex(fx.StoreNamespace, address, block5)
fx.Store.LookupStateReference(fx.StoreNamespace, address, block5)
);
Assert.Equal(
Tuple.Create(block4.Hash, block4.Index),
fx.Store.LookupStateReferenceWithIndex(fx.StoreNamespace, address, block6)
fx.Store.LookupStateReference(fx.StoreNamespace, address, block6)
);

fx.Store.StoreStateReference(fx.StoreNamespace, tx5.UpdatedAddresses, block5);
Assert.Null(fx.Store.LookupStateReferenceWithIndex(
Assert.Null(fx.Store.LookupStateReference(
fx.StoreNamespace, address, fx.Block3));
Assert.Equal(
Tuple.Create(block4.Hash, block4.Index),
fx.Store.LookupStateReferenceWithIndex(fx.StoreNamespace, address, block4)
fx.Store.LookupStateReference(fx.StoreNamespace, address, block4)
);
Assert.Equal(
Tuple.Create(block5.Hash, block5.Index),
fx.Store.LookupStateReferenceWithIndex(fx.StoreNamespace, address, block5)
fx.Store.LookupStateReference(fx.StoreNamespace, address, block5)
);
Assert.Equal(
Tuple.Create(block5.Hash, block5.Index),
fx.Store.LookupStateReferenceWithIndex(fx.StoreNamespace, address, block6)
fx.Store.LookupStateReference(fx.StoreNamespace, address, block6)
);
}
}
@@ -350,13 +350,13 @@ public void ForkStateReferences(int branchPointIndex)

Assert.Equal(
Tuple.Create(blocks[2].Hash, blocks[2].Index),
Fx.Store.LookupStateReferenceWithIndex(Fx.StoreNamespace, address1, blocks[3]));
Fx.Store.LookupStateReference(Fx.StoreNamespace, address1, blocks[3]));
Assert.Equal(
Tuple.Create(blocks[3].Hash, blocks[3].Index),
Fx.Store.LookupStateReferenceWithIndex(Fx.StoreNamespace, address2, blocks[3]));
Fx.Store.LookupStateReference(Fx.StoreNamespace, address2, blocks[3]));
Assert.Equal(
Tuple.Create(blocks[branchPointIndex].Hash, blocks[branchPointIndex].Index),
Fx.Store.LookupStateReferenceWithIndex(targetNamespace, address1, blocks[3]));
Fx.Store.LookupStateReference(targetNamespace, address1, blocks[3]));
Assert.Null(
Fx.Store.LookupStateReference(targetNamespace, address2, blocks[3]));
}
@@ -220,7 +220,7 @@ IEnumerator IEnumerable.GetEnumerator()

foreach (var address in requestedAddresses)
{
Tuple<HashDigest<SHA256>, long> sr = Store.LookupStateReferenceWithIndex(
Tuple<HashDigest<SHA256>, long> sr = Store.LookupStateReference(
Id.ToString(), address, block);
if (!(sr is null))
{
@@ -18,27 +18,15 @@ public static class StoreExtension
/// <param name="address">The <see cref="Address"/> to look up.</param>
/// <param name="lookupUntil">The upper bound (i.e., the latest block) of the search range.
/// <see cref="Block{T}"/>s after <paramref name="lookupUntil"/> are ignored.</param>
/// <returns>A <see cref="Block{T}.Hash"/> which has the state of
/// the <paramref name="address"/>.</returns>
/// <returns>Returns a nullable tuple consisting of <see cref="Block{T}.Hash"/> and
/// <see cref="Block{T}.Index"/> of the <see cref="Block{T}"/> with the state of the
/// address.</returns>
/// <typeparam name="T">An <see cref="IAction"/> class used with
/// <paramref name="lookupUntil"/>.</typeparam>
/// <seealso
/// cref="IStore.StoreStateReference{T}(string, IImmutableSet{Address}, Block{T})"/>
/// <seealso cref="IStore.IterateStateReferences(string, Address)"/>
public static HashDigest<SHA256>? LookupStateReference<T>(
this IStore store,
string @namespace,
Address address,
Block<T> lookupUntil)
where T : IAction, new()
{
Tuple<HashDigest<SHA256>, long> sr = store.
LookupStateReferenceWithIndex(@namespace, address, lookupUntil);

return sr?.Item1;
}

internal static Tuple<HashDigest<SHA256>, long> LookupStateReferenceWithIndex<T>(
public static Tuple<HashDigest<SHA256>, long> LookupStateReference<T>(
this IStore store,
string @namespace,
Address address,

0 comments on commit f418686

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