Skip to content

Commit

Permalink
Merge pull request #3562 from AElfProject/release/1.9.0
Browse files Browse the repository at this point in the history
Release v1.9.0
  • Loading branch information
JimAelf authored May 23, 2024
2 parents 1842512 + a7c0637 commit 3806c18
Show file tree
Hide file tree
Showing 58 changed files with 2,380 additions and 243 deletions.
16 changes: 15 additions & 1 deletion contract/AElf.Contracts.Genesis/BasicContractZero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ public override Int32Value GetContractProposalExpirationTimePeriod(Empty input)
return new Int32Value { Value = expirationTimePeriod };
}

public override Int32Value GetCodeCheckProposalExpirationTimePeriod(Empty input)
{
var expirationTimePeriod = GetCodeCheckProposalExpirationTimePeriod();
return new Int32Value { Value = expirationTimePeriod };
}

public override Address GetSigner(Address input)
{
return State.SignerMap[input];
Expand Down Expand Up @@ -245,7 +251,7 @@ public override Hash ProposeContractCodeCheck(ContractCodeCheckInput input)
ContractMethodName = input.CodeCheckReleaseMethod,
Params = input.ContractInput,
OrganizationAddress = codeCheckController.OwnerAddress,
ExpiredTime = Context.CurrentBlockTime.AddSeconds(CodeCheckProposalExpirationTimePeriod)
ExpiredTime = Context.CurrentBlockTime.AddSeconds(GetCodeCheckProposalExpirationTimePeriod())
},
OriginProposer = proposedInfo.Proposer
};
Expand Down Expand Up @@ -392,6 +398,14 @@ public override Empty SetContractProposalExpirationTimePeriod(SetContractProposa
return new Empty();
}

public override Empty SetCodeCheckProposalExpirationTimePeriod(Int32Value input)
{
AssertSenderAddressWith(State.ContractDeploymentController.Value.OwnerAddress);
Assert(input.Value > 0, "Invalid expiration time period.");
State.CodeCheckProposalExpirationTimePeriod.Value = input.Value;
return new Empty();
}

public override DeployUserSmartContractOutput DeployUserSmartContract(UserContractDeploymentInput input)
{
AssertInlineDeployOrUpdateUserContract();
Expand Down
3 changes: 3 additions & 0 deletions contract/AElf.Contracts.Genesis/BasicContractZeroState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ public partial class BasicContractZeroState : ContractState
public SingletonState<int> ContractProposalExpirationTimePeriod { get; set; }

public MappedState<Address, Address> SignerMap { get; set; }

public SingletonState<int> CodeCheckProposalExpirationTimePeriod { get; set; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace AElf.Contracts.Genesis;
public partial class BasicContractZero
{
public const int ContractProposalExpirationTimePeriod = 259200; // 60 * 60 * 72
public const int CodeCheckProposalExpirationTimePeriod = 600; // 60 * 10
public const int DefaultCodeCheckProposalExpirationTimePeriod = 900; // 60 * 15
private const int MinimalApprovalThreshold = 6667;
private const int MaximalAbstentionThreshold = 1000;
private const int MaximalRejectionThreshold = 1000;
Expand Down
9 changes: 8 additions & 1 deletion contract/AElf.Contracts.Genesis/BasicContractZero_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ private int GetCurrentContractProposalExpirationTimePeriod()
: State.ContractProposalExpirationTimePeriod.Value;
}

private int GetCodeCheckProposalExpirationTimePeriod()
{
return State.CodeCheckProposalExpirationTimePeriod.Value == 0
? DefaultCodeCheckProposalExpirationTimePeriod
: State.CodeCheckProposalExpirationTimePeriod.Value;
}

private void AssertCurrentMiner()
{
RequireConsensusContractStateSet();
Expand All @@ -310,7 +317,7 @@ private void SendUserContractProposal(Hash proposingInputHash, string releaseMet
{
Proposer = Context.Self,
Status = ContractProposingInputStatus.CodeCheckProposed,
ExpiredTime = Context.CurrentBlockTime.AddSeconds(CodeCheckProposalExpirationTimePeriod),
ExpiredTime = Context.CurrentBlockTime.AddSeconds(GetCodeCheckProposalExpirationTimePeriod()),
Author = Context.Sender
};
State.ContractProposingInputMap[proposingInputHash] = proposedInfo;
Expand Down
3 changes: 3 additions & 0 deletions contract/AElf.Contracts.MultiToken/TokenContractConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class TokenContractConstants
public const string LockCallbackExternalInfoKey = "aelf_lock_callback";
public const string UnlockCallbackExternalInfoKey = "aelf_unlock_callback";
public const string LogEventExternalInfoKey = "aelf_log_event";
public const string TokenAliasExternalInfoKey = "aelf_token_alias";
public const int DELEGATEE_MAX_COUNT = 24;
public const char NFTSymbolSeparator = '-';
public const int NFTSymbolMaxLength = 30;
Expand All @@ -24,4 +25,6 @@ public static class TokenContractConstants
public const string SeedExpireTimeExternalInfoKey = "__seed_exp_time";
public const string NftCreateChainIdExternalInfoKey = "__nft_create_chain_id";
public const int DefaultMaxBatchApproveCount = 100;
public const char AllSymbolIdentifier = '*';

}
9 changes: 9 additions & 0 deletions contract/AElf.Contracts.MultiToken/TokenContractState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ public partial class TokenContractState : ContractState
public StringState NativeTokenSymbol { get; set; }

public StringState ChainPrimaryTokenSymbol { get; set; }

/// <summary>
/// WARNING: Use GetTokenInfo & SetTokenInfo to operate TokenInfos
/// due to token symbol alias feature.
/// </summary>
public MappedState<string, TokenInfo> TokenInfos { get; set; }
public MappedState<string, bool> InsensitiveTokenExisting { get; set; }
public MappedState<string, string> SymbolSeedMap { get; set; }
public MappedState<Address, string, long> Balances { get; set; }
public MappedState<Address, Address, string, long> Allowances { get; set; }
Expand Down Expand Up @@ -67,4 +73,7 @@ public partial class TokenContractState : ContractState
public SingletonState<bool> TokenIssuerAndOwnerModificationDisabled { get; set; }

public SingletonState<int> MaxBatchApproveCount { get; set; }

// Alias -> Actual Symbol
public MappedState<string, string> SymbolAliasMap { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ private bool CheckOrganizationExist(AuthorityInfo authorityInfo)
private void AssertValidFeeToken(string symbol, long amount)
{
AssertValidSymbolAndAmount(symbol, amount);
if (State.TokenInfos[symbol] == null)
var tokenInfo = GetTokenInfo(symbol);
if (tokenInfo == null)
{
throw new AssertionException("Token is not found");
Assert(State.TokenInfos[symbol].IsBurnable, $"Token {symbol} cannot set as method fee.");
}
Assert(tokenInfo.IsBurnable, $"Token {symbol} cannot set as method fee.");
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public override ResourceInfo GetResourceInfo(Transaction txn)
{
WritePaths =
{
GetPath(nameof(TokenContractState.Allowances), args.From.ToString(), txn.From.ToString(),
args.Symbol),
GetPath(nameof(TokenContractState.Balances), args.From.ToString(), args.Symbol),
GetPath(nameof(TokenContractState.Balances), args.To.ToString(), args.Symbol),
GetPath(nameof(TokenContractState.LockWhiteLists), args.Symbol, txn.From.ToString())
Expand All @@ -57,7 +55,7 @@ public override ResourceInfo GetResourceInfo(Transaction txn)
GetPath(nameof(TokenContractState.TransactionFeeFreeAllowancesSymbolList))
}
};

AddPathForAllowance(resourceInfo, args.From.ToString(), txn.From.ToString(), args.Symbol);
AddPathForTransactionFee(resourceInfo, txn.From.ToString(), txn.MethodName);
AddPathForDelegatees(resourceInfo, txn.From, txn.To, txn.MethodName);
AddPathForTransactionFeeFreeAllowance(resourceInfo, txn.From);
Expand All @@ -70,6 +68,18 @@ public override ResourceInfo GetResourceInfo(Transaction txn)
}
}

private void AddPathForAllowance(ResourceInfo resourceInfo, string from, string spender, string symbol)
{
resourceInfo.WritePaths.Add(GetPath(nameof(TokenContractState.Allowances), from, spender, symbol));
resourceInfo.WritePaths.Add(GetPath(nameof(TokenContractState.Allowances), from, spender,
GetAllSymbolIdentifier()));
var symbolType = GetSymbolType(symbol);
if (symbolType == SymbolType.Nft || symbolType == SymbolType.NftCollection)
{
resourceInfo.WritePaths.Add(GetPath(nameof(TokenContractState.Allowances), from, spender,
GetNftCollectionAllSymbolIdentifier(symbol)));
}
}

private void AddPathForTransactionFee(ResourceInfo resourceInfo, string from, string methodName)
{
Expand Down
Loading

0 comments on commit 3806c18

Please sign in to comment.