Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove IActionContext.NewGuid() & Add RandomExtension.GenerateRandomGuid() #508

Merged
merged 4 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Libplanet/Action/IActionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,5 @@ public interface IActionContext
/// <returns>A random object that shares interface mostly equivalent
/// to <see cref="System.Random"/>.</returns>
IRandom Random { get; }

/// <summary>
/// Creates new <see cref="Guid"/>. Its seed (state) is determined by a block and
/// a transaction, which is deterministic as like <see cref="Random"/>.
/// </summary>
/// <returns>A deterministic guid.</returns>
Guid NewGuid();
}
}
26 changes: 26 additions & 0 deletions Libplanet/Action/RandomExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace Libplanet.Action
{
/// <summary>
/// This extension class provides some convenient methods
/// to deal with <see cref="IRandom"/>.
/// </summary>
public static class RandomExtension
{
/// <summary>
/// Generates a random <see cref="Guid"/>.
/// </summary>
/// <param name="random"> <see cref="IRandom"/> to generate
/// a random <see cref="Guid"/>.</param>
/// <returns> Generated random <see cref="Guid"/>.
/// </returns>
/// <seealso cref="IRandom"/>
public static Guid GenerateRandomGuid(this IRandom random)
{
var bytes = new byte[16];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if there is mention as this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are fixed! Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Unengine Still not addressed I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I forgot to commit. I'll also commit your suggestions at once!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Job's done!

random.NextBytes(bytes);
return new Guid(bytes);
}
}
}