Skip to content

Commit

Permalink
feat!: rename TokenId type from tokenId to vitetoken
Browse files Browse the repository at this point in the history
  • Loading branch information
vuilder0 committed Feb 7, 2022
1 parent 875b776 commit a866dc5
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion liblangutil/Token.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ namespace solidity::langutil
T(BytesM, "bytesM", 0) \
T(FixedMxN, "fixedMxN", 0) \
T(UFixedMxN, "ufixedMxN", 0) \
K(TokenId, "tokenId", 0) /* Solidity++: Vite token id */ \
K(TokenId, "vitetoken", 0) /* Solidity++: Vite token id */ \
T(TypesEnd, nullptr, 0) /* used as type enum end marker */ \
\
/* Literals */ \
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/analysis/GlobalContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariable

// Solidity++: solidity++ magic variables
magicVarDecl("blake2b", TypeProvider::function(strings{"bytes memory"}, strings{"bytes32"}, FunctionType::Kind::BLAKE2B, false, StateMutability::Pure)),
magicVarDecl("balance", TypeProvider::function(strings{"tokenId"}, strings{"uint"}, FunctionType::Kind::Balance, false, StateMutability::View)),
magicVarDecl("balance", TypeProvider::function(strings{"vitetoken"}, strings{"uint"}, FunctionType::Kind::Balance, false, StateMutability::View)),
magicVarDecl("height", TypeProvider::function(strings(), strings{"uint256"}, FunctionType::Kind::Height, false, StateMutability::View)),
magicVarDecl("accountheight", TypeProvider::function(strings(), strings{"uint64"}, FunctionType::Kind::AccountHeight, false, StateMutability::View)),
magicVarDecl("prevhash", TypeProvider::function(strings(), strings{"bytes32"}, FunctionType::Kind::PrevHash, false, StateMutability::View)),
Expand Down
9 changes: 4 additions & 5 deletions libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ MemberList::MemberMap AddressType::nativeMembers(ASTNode const*) const
members.emplace_back(MemberList::Member{"send", TypeProvider::function(strings{"uint"}, strings{"bool"}, FunctionType::Kind::Send, false, StateMutability::NonPayable)});
// members.emplace_back(MemberList::Member{"send", TypeProvider::function(strings{"message"}, strings{}, FunctionType::Kind::Send, false, StateMutability::Payable)});
// Solidity++: redefine address.transfer()
members.emplace_back(MemberList::Member{"transfer", TypeProvider::function(strings{"tokenId", "uint"}, strings(), FunctionType::Kind::Transfer, false, StateMutability::NonPayable)});
members.emplace_back(MemberList::Member{"transfer", TypeProvider::function(strings{"vitetoken", "uint"}, strings(), FunctionType::Kind::Transfer, false, StateMutability::NonPayable)});
}
return members;
}
Expand Down Expand Up @@ -2907,7 +2907,7 @@ string FunctionType::richIdentifier() const
if (m_valueSet)
id += "value";
if (m_tokenSet) // Solidity++
id += "tti";
id += "token";
if (m_saltSet)
id += "salt";
if (bound())
Expand Down Expand Up @@ -3111,7 +3111,7 @@ vector<tuple<string, TypePointer>> FunctionType::makeStackItems() const
if (m_valueSet)
slots.emplace_back("value", TypeProvider::uint256());
if (m_tokenSet)
slots.emplace_back("tti", TypeProvider::viteTokenId()); // Solidity++
slots.emplace_back("token", TypeProvider::viteTokenId()); // Solidity++
if (m_saltSet)
slots.emplace_back("salt", TypeProvider::fixedBytes(32));
if (bound())
Expand Down Expand Up @@ -3898,8 +3898,7 @@ MemberList::MemberMap MagicType::nativeMembers(ASTNode const*) const
{"data", TypeProvider::array(DataLocation::CallData)},
{"sig", TypeProvider::fixedBytes(4)},
{"sender", TypeProvider::address()},
{"tokenid", TypeProvider::viteTokenId()}, // Solidity++: get tx's transfer token id
{"amount", TypeProvider::uint256()} // Solidity++: get tx's transfer amount
{"token", TypeProvider::viteTokenId()}, // Solidity++: get tx's transfer token id
});
case Kind::Transaction:
return MemberList::MemberMap({
Expand Down
6 changes: 3 additions & 3 deletions libsolidity/codegen/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1800,9 +1800,9 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
}

// Solidity++:
else if (member == "tokenid")
else if (member == "token")
m_context << Instruction::TOKENID;
else if (member == "amount")
else if (member == "value")
m_context << Instruction::CALLVALUE;

else
Expand Down Expand Up @@ -2644,7 +2644,7 @@ void ExpressionCompiler::appendExternalFunctionCall(
{
m_context.appendDebugInfo("value to send");
m_context << dupInstruction(m_context.baseToCurrentStackOffset(valueStackPos));
m_context.appendDebugInfo("tokenId");
m_context.appendDebugInfo("vite token");
m_context << dupInstruction(m_context.baseToCurrentStackOffset(tokenStackPos)); // Solidity++: push tokenId
}
else if (_functionType.valueSet() && !_functionType.tokenSet())
Expand Down
2 changes: 1 addition & 1 deletion test/soliditypp/ParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace solidity::frontend::test::soliditypp
{
char const* text = R"(
contract Test {
tokenId token = "tti_5649544520544f4b454e6e40";
vitetoken token = "tti_5649544520544f4b454e6e40";
}
)";
BOOST_CHECK(successParse(text));
Expand Down
6 changes: 3 additions & 3 deletions test/soliditypp/SolidityppExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ BOOST_AUTO_TEST_CASE(blake2b)
char const* sourceCode = R"(
contract test {
function f() external {
tokenId t = msg.tokenid;
vitetoken t = msg.token;
}
}
)";
Expand All @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(msg_amount)
char const* sourceCode = R"(
contract test {
function f() external {
uint a = msg.amount;
uint a = msg.value;
}
}
)";
Expand All @@ -366,7 +366,7 @@ BOOST_AUTO_TEST_CASE(msg_amount)
{
char const* sourceCode = R"(
contract test {
function f(tokenId token) public {
function f(vitetoken token) public {
balance(token);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ contract C {
this.balance; // to avoid pureness warning
return 1;
}
function transfer(tokenId _token, uint amount) public {
function transfer(vitetoken _token, uint amount) public {
payable(this).transfer(_token, amount); // to avoid pureness warning
}
receive() payable external {
Expand Down
4 changes: 2 additions & 2 deletions test/syntax/soliditypp/magic/amount.solpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma soliditypp >=0.8.0;
contract Test {
uint amount;
function test() external {
amount = msg.amount;
function test() external payable {
amount = msg.value;
}
}
2 changes: 1 addition & 1 deletion test/syntax/soliditypp/magic/balance.solpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma soliditypp >=0.8.0;
contract Test {
uint b;
function test(tokenId token) external {
function test(vitetoken token) external {
b = balance(token);
}
}
4 changes: 2 additions & 2 deletions test/syntax/soliditypp/magic/token_id.solpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma soliditypp >=0.8.0;
contract Test {
tokenId token;
vitetoken token;
function test() external {
token = msg.tokenid;
token = msg.token;
}
}
6 changes: 3 additions & 3 deletions test/syntax/soliditypp/tokenid/good_tokenid.solpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma soliditypp >=0.8.0;

contract GoodTokenId {
tokenId t1 = "tti_5649544520544f4b454e6e40";
tokenId t2 = tokenId("tti_5649544520544f4b454e6e40");
tokenId t3 = t1;
vitetoken t1 = "tti_5649544520544f4b454e6e40";
vitetoken t2 = vitetoken("tti_5649544520544f4b454e6e40");
vitetoken t3 = t1;
}
// ----
4 changes: 2 additions & 2 deletions test/syntax/soliditypp/tokenid/tokenid_in_event.solpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ pragma soliditypp >=0.8.0;

contract TokenIdInEvent {

event E(tokenId token);
event E(vitetoken token);

function f() external {
tokenId t = "tti_5649544520544f4b454e6e40";
vitetoken t = "tti_5649544520544f4b454e6e40";
emit E(t);
}
}
2 changes: 1 addition & 1 deletion test/syntax/soliditypp/tokenid/tokenid_in_function.solpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma soliditypp >=0.8.0;

contract TokenIdInFunction {
function f(tokenId t) internal pure returns (tokenId) {
function f(vitetoken t) internal pure returns (vitetoken) {
return t;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/syntax/soliditypp/tokenid/tokenid_too_long.solpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma soliditypp >=0.8.0;

contract BadTokenIdChecksum {
tokenId t = "tti_5649544520544f4b454e000000";
vitetoken t = "tti_5649544520544f4b454e000000";
}
// ----
// SyntaxError 9429: (110-142): This looks like a Vite Token Id but is not exactly 24 hex digits. It is 26 hex digits.
// SyntaxError 9429: (112-144): This looks like a Vite Token Id but is not exactly 24 hex digits. It is 26 hex digits.
4 changes: 2 additions & 2 deletions test/syntax/soliditypp/tokenid/tokenid_too_short.solpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma soliditypp >=0.8.0;

contract BadTokenIdChecksum {
tokenId t = "tti_5649544520544f4b454e00";
vitetoken t = "tti_5649544520544f4b454e00";
}
// ----
// SyntaxError 9429: (110-138): This looks like a Vite Token Id but is not exactly 24 hex digits. It is 22 hex digits.
// SyntaxError 9429: (112-140): This looks like a Vite Token Id but is not exactly 24 hex digits. It is 22 hex digits.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma soliditypp >=0.8.0;

contract BadTokenIdChecksum {
tokenId t = "tti_5649544520544f4b454e0000";
vitetoken t = "tti_5649544520544f4b454e0000";
}
// ----
// SyntaxError 9429: (110-140): This looks like a Vite Token Id but has an invalid checksum.
// SyntaxError 9429: (112-142): This looks like a Vite Token Id but has an invalid checksum.

0 comments on commit a866dc5

Please sign in to comment.