Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 12 additions & 8 deletions contract/AElf.Contracts.MultiToken/TokenContract_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,28 @@ private void AssertApproveToken(string symbol)
{
Assert(!string.IsNullOrEmpty(symbol), "Symbol can not be null.");
var words = symbol.Split(TokenContractConstants.NFTSymbolSeparator);
var symbolPrefix = words[0];
var allSymbolIdentifier = GetAllSymbolIdentifier();
Assert(symbolPrefix.Length > 0 && (IsValidCreateSymbol(symbolPrefix) || symbolPrefix.Equals(allSymbolIdentifier)), "Invalid symbol.");

if (words.Length == 1)
{
if (!symbolPrefix.Equals(allSymbolIdentifier))
{
ValidTokenExists(symbolPrefix);
}
ValidTokenExists(words[0]);
return;
}

// The length of words should be either 1 or 2.
Assert(words.Length == 2, "Invalid symbol length.");

var symbolPrefix = words[0];
var itemId = words[1];

var allSymbolIdentifier = GetAllSymbolIdentifier();
Assert(symbolPrefix.Length > 0 && IsValidCreateSymbol(symbolPrefix), "Invalid symbol.");

// Symbol's format can either be ABC-123 or ABC-*.
Assert(itemId.Length > 0 && (IsValidItemId(itemId) || itemId.Equals(allSymbolIdentifier)), "Invalid NFT Symbol.");
var nftSymbol = itemId.Equals(allSymbolIdentifier) ? GetCollectionSymbol(symbolPrefix) : symbol;
ValidTokenExists(nftSymbol);
}

private string GetCollectionSymbol(string symbolPrefix)
{
return $"{symbolPrefix}-{TokenContractConstants.CollectionSymbolSuffix}";
Expand Down
20 changes: 2 additions & 18 deletions contract/AElf.Contracts.MultiToken/TokenContract_NFT_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,10 @@ private long GetAllowance(Address from, Address spender, string sourceSymbol, lo
var allowance = State.Allowances[from][spender][sourceSymbol];
if (allowance >= amount) return allowance;
var tokenType = GetSymbolType(sourceSymbol);
if (tokenType == SymbolType.Token)
{
allowance = GetAllSymbolAllowance(from, spender, out allowanceSymbol);
}
else
{
allowance = GetNftCollectionAllSymbolAllowance(from, spender, sourceSymbol, out allowanceSymbol);
if (allowance >= amount) return allowance;
allowance = GetAllSymbolAllowance(from, spender, out allowanceSymbol);
}

if (tokenType == SymbolType.Token) return allowance;
allowance = GetNftCollectionAllSymbolAllowance(from, spender, sourceSymbol, out allowanceSymbol);
return allowance;
}


private long GetAllSymbolAllowance(Address from, Address spender, out string allowanceSymbol)
{
allowanceSymbol = GetAllSymbolIdentifier();
return State.Allowances[from][spender][allowanceSymbol];
}

private long GetNftCollectionAllSymbolAllowance(Address from, Address spender, string sourceSymbol,
out string allowanceSymbol)
Expand Down
8 changes: 5 additions & 3 deletions contract/AElf.Contracts.MultiToken/TokenContract_Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ public override GetAllowanceOutput GetAvailableAllowance(GetAllowanceInput input
result.Allowance = allowance;
return result;
}

var symbolType = GetSymbolType(symbol);
allowance = Math.Max(allowance, GetAllSymbolAllowance(input.Owner,input.Spender,out _));
if (symbolType == SymbolType.Nft || symbolType == SymbolType.NftCollection)
{
allowance = Math.Max(allowance, GetNftCollectionAllSymbolAllowance(input.Owner, input.Spender, symbol, out _));
allowance = Math.Max(allowance,
GetNftCollectionAllSymbolAllowance(input.Owner, input.Spender, symbol, out _));
}

result.Allowance = allowance;
return result;
}
Expand All @@ -90,7 +92,7 @@ private bool CheckSymbolIdentifier(string symbol)
{
var words = symbol.Split(TokenContractConstants.NFTSymbolSeparator);
var allSymbolIdentifier = GetAllSymbolIdentifier();
return words[0].Equals(allSymbolIdentifier) || (words.Length > 1 && words[1].Equals(allSymbolIdentifier));
return words.Length > 1 && words[1].Equals(allSymbolIdentifier);
}

public override BoolValue IsInWhiteList(IsInWhiteListInput input)
Expand Down
Loading