Skip to content

Commit 9d567e4

Browse files
authored
Merge pull request #3624 from AElfProject/feature/extend-seed-expiration-time
Extend seed NFT expiration time
2 parents f21fc2d + 1404c3e commit 9d567e4

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,35 @@ public override Int32Value GetMaxBatchApproveCount(Empty input)
691691
};
692692
}
693693

694+
public override Empty ExtendSeedExpirationTime(ExtendSeedExpirationTimeInput input)
695+
{
696+
var tokenInfo = GetTokenInfo(input.Symbol);
697+
if (tokenInfo == null)
698+
{
699+
throw new AssertionException("Seed NFT does not exist.");
700+
}
701+
702+
Assert(tokenInfo.Owner == Context.Sender, "Sender is not Seed NFT owner.");
703+
var oldExpireTimeLong = 0L;
704+
if (tokenInfo.ExternalInfo.Value.TryGetValue(TokenContractConstants.SeedExpireTimeExternalInfoKey,
705+
out var oldExpireTime))
706+
{
707+
long.TryParse(oldExpireTime, out oldExpireTimeLong);
708+
}
709+
710+
tokenInfo.ExternalInfo.Value[TokenContractConstants.SeedExpireTimeExternalInfoKey] =
711+
input.ExpirationTime.ToString();
712+
State.TokenInfos[input.Symbol] = tokenInfo;
713+
Context.Fire(new SeedExpirationTimeUpdated
714+
{
715+
ChainId = tokenInfo.IssueChainId,
716+
Symbol = input.Symbol,
717+
OldExpirationTime = oldExpireTimeLong,
718+
NewExpirationTime = input.ExpirationTime
719+
});
720+
return new Empty();
721+
}
722+
694723
private int GetMaxBatchApproveCount()
695724
{
696725
return State.MaxBatchApproveCount.Value == 0

protobuf/token_contract_impl.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ service TokenContractImpl {
182182
rpc GetMaxBatchApproveCount (google.protobuf.Empty) returns (google.protobuf.Int32Value) {
183183

184184
}
185+
186+
rpc ExtendSeedExpirationTime (ExtendSeedExpirationTimeInput) returns (google.protobuf.Empty) {
187+
}
185188
}
186189

187190
message AdvanceResourceTokenInput {
@@ -444,4 +447,17 @@ message ModifyTokenIssuerAndOwnerInput {
444447

445448
message SetTokenIssuerAndOwnerModificationEnabledInput{
446449
bool enabled = 1;
450+
}
451+
452+
message ExtendSeedExpirationTimeInput {
453+
string symbol = 1;
454+
int64 expiration_time = 2;
455+
}
456+
457+
message SeedExpirationTimeUpdated {
458+
option (aelf.is_event) = true;
459+
int32 chain_id = 1;
460+
string symbol = 2;
461+
int64 old_expiration_time = 3;
462+
int64 new_expiration_time = 4;
447463
}

test/AElf.Contracts.MultiToken.Tests/BVT/TokenApplicationTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,4 +1893,15 @@ public async Task TokenIssuerAndOwnerModification_Test()
18931893
result.TransactionResult.Error.ShouldContain("Set token issuer and owner disabled.");
18941894

18951895
}
1896+
1897+
[Theory]
1898+
[InlineData("SEED-0", 1731927992000)]
1899+
public async Task ExtendSeedExpirationTime_Test(string symbol, long expirationTime)
1900+
{
1901+
ExtendSeedExpirationTimeInput input = new ExtendSeedExpirationTimeInput();
1902+
input.Symbol = symbol;
1903+
input.ExpirationTime = expirationTime;
1904+
1905+
await TokenContractStub.ExtendSeedExpirationTime.CallAsync(input);
1906+
}
18961907
}

test/AElf.Contracts.MultiToken.Tests/MultiTokenContractTestBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,7 @@ internal async Task<IExecutionResult<Empty>> CreateMutiTokenWithExceptionAsync(
240240
await CreateSeedNftAsync(stub, createInput);
241241
return await stub.Create.SendWithExceptionAsync(createInput);
242242
}
243+
244+
245+
243246
}

0 commit comments

Comments
 (0)