From cc829042201614f1e5b8688ad9db5b1ae38b3df7 Mon Sep 17 00:00:00 2001 From: Steve Goodman Date: Thu, 29 Feb 2024 12:53:02 +0200 Subject: [PATCH] Testing Solidity formatting. --- .../Accounts/deploying_new_accounts.adoc | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/components/Starknet/modules/architecture_and_concepts/pages/Accounts/deploying_new_accounts.adoc b/components/Starknet/modules/architecture_and_concepts/pages/Accounts/deploying_new_accounts.adoc index 44bef91a6a..93c5f59e8a 100644 --- a/components/Starknet/modules/architecture_and_concepts/pages/Accounts/deploying_new_accounts.adoc +++ b/components/Starknet/modules/architecture_and_concepts/pages/Accounts/deploying_new_accounts.adoc @@ -43,4 +43,57 @@ A `DEPLOY_ACCOUNT` transaction automatically tells the sequencer to call the `+_ [NOTE] ==== When creating a new account without the `DEPLOY_ACCOUNT` transaction, such as by invoking the Universal Deployer Contract (UDC) with an `INVOKE` transaction, the sequencer calls the `+__validate__+` function, which validates the `INVOKE` transaction. -==== \ No newline at end of file +==== + +''' + +.Solidity Example +[source,solidity] +---- +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.5.0 <0.9.0; + +library Balances { + function move(mapping(address => uint256) storage balances, address from, address to, uint amount) internal { + require(balances[from] >= amount); + require(balances[to] + amount >= balances[to]); + balances[from] -= amount; + balances[to] += amount; + } +} + +contract Token { + mapping(address => uint256) balances; + using Balances for *; + mapping(address => mapping(address => uint256)) allowed; + + event Transfer(address from, address to, uint amount); + event Approval(address owner, address spender, uint amount); + + function transfer(address to, uint amount) external returns (bool success) { + balances.move(msg.sender, to, amount); + emit Transfer(msg.sender, to, amount); + return true; + + } + + function transferFrom(address from, address to, uint amount) external returns (bool success) { + require(allowed[from][msg.sender] >= amount); + allowed[from][msg.sender] -= amount; + balances.move(from, to, amount); + emit Transfer(from, to, amount); + return true; + } + + function approve(address spender, uint tokens) external returns (bool success) { + require(allowed[msg.sender][spender] == 0, ""); + allowed[msg.sender][spender] = tokens; + emit Approval(msg.sender, spender, tokens); + return true; + } + + function balanceOf(address tokenOwner) external view returns (uint balance) { + return balances[tokenOwner]; + } +} +---- \ No newline at end of file