Skip to content

Commit

Permalink
NameService: add Renew event
Browse files Browse the repository at this point in the history
Follow the neo-project#11 notation, close neo-project#24.
  • Loading branch information
AnnaShaleva committed Sep 21, 2022
1 parent 36b55cb commit d633cda
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/NameService/NameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ public sealed class NameService : Framework.SmartContract
{
public delegate void OnTransferDelegate(UInt160 from, UInt160 to, BigInteger amount, ByteString tokenId);
public delegate void OnSetAdminDelegate(string name, UInt160 oldAdmin, UInt160 newAdmin);
public delegate void OnRenewDelegate(string name, BigInteger oldExpiration, BigInteger newExpiration);

[DisplayName("Transfer")]
public static event OnTransferDelegate OnTransfer;
[DisplayName("SetAdmin")]
public static event OnSetAdminDelegate OnSetAdmin;
[DisplayName("Renew")]
public static event OnRenewDelegate OnRenew;

private const byte Prefix_TotalSupply = 0x00;
private const byte Prefix_Balance = 0x01;
Expand Down Expand Up @@ -281,10 +284,12 @@ public static ulong Renew(string name, byte years)
ByteString tokenKey = GetKey(name);
NameState token = (NameState)StdLib.Deserialize(nameMap[tokenKey]);
token.EnsureNotExpired();
ulong oldExpiration = token.Expiration;
token.Expiration += OneYear * years;
if (token.Expiration > Runtime.Time + TenYears)
throw new ArgumentException("You can't renew a domain name for more than 10 years in total.");
nameMap[tokenKey] = StdLib.Serialize(token);
OnRenew(name, oldExpiration, token.Expiration);
return token.Expiration;
}

Expand Down

0 comments on commit d633cda

Please sign in to comment.