Skip to content

Commit

Permalink
chore: Add .prettierignore and .prettierrc.json files
Browse files Browse the repository at this point in the history
  • Loading branch information
Laisky committed Jul 22, 2024
1 parent 52d2236 commit 2bdcce0
Show file tree
Hide file tree
Showing 81 changed files with 34,916 additions and 1 deletion.
864 changes: 864 additions & 0 deletions blockchain/ethereum/contracts/ao-bridge.sol

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions blockchain/ton/contracts/counter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
node_modules
temp
build
dist
.DS_Store

# VS Code
.vscode/*
.history/
*.vsix

# IDEA files
.idea

# VIM
Session.vim
1 change: 1 addition & 0 deletions blockchain/ton/contracts/counter/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
7 changes: 7 additions & 0 deletions blockchain/ton/contracts/counter/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 120,
"tabWidth": 4,
"singleQuote": true,
"bracketSpacing": true,
"semi": true
}
26 changes: 26 additions & 0 deletions blockchain/ton/contracts/counter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# helloworld

## Project structure

- `contracts` - source code of all the smart contracts of the project and their dependencies.
- `wrappers` - wrapper classes (implementing `Contract` from ton-core) for the contracts, including any [de]serialization primitives and compilation functions.
- `tests` - tests for the contracts.
- `scripts` - scripts used by the project, mainly the deployment scripts.

## How to use

### Build

`npx blueprint build` or `yarn blueprint build`

### Test

`npx blueprint test` or `yarn blueprint test`

### Deploy or run another script

`npx blueprint run` or `yarn blueprint run`

### Add a new contract

`npx blueprint create ContractName` or `yarn blueprint create ContractName`
84 changes: 84 additions & 0 deletions blockchain/ton/contracts/counter/contracts/hello_world.fc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include "imports/stdlib.fc";

const op::increase = "op::increase"c; ;; create an opcode from string using the "c" prefix, this results in 0x7e8764ef opcode in this case
const op::withdraw = "op::withdraw"c;

;; storage variables

;; id is required to be able to create different instances of counters
;; since addresses in TON depend on the initial state of the contract
global int ctx_id;
global int ctx_counter;

;; load_data populates storage variables using stored data
() load_data() impure {
var ds = get_data().begin_parse();

ctx_id = ds~load_uint(32);
ctx_counter = ds~load_uint(32);

ds.end_parse();
}

;; save_data stores storage variables as a cell into persistent storage
() save_data() impure inline {
set_data(
begin_cell()
.store_uint(ctx_id, 32)
.store_uint(ctx_counter, 32)
.end_cell()
);
}

;; recv_internal is the main function of the contract and is called when it receives a message from other contracts
() recv_internal(int my_balance, int msg_value, cell in_msg_full, slice in_msg_body) impure {
if (in_msg_body.slice_empty?()) { ;; ignore all empty messages
return ();
}

slice cs = in_msg_full.begin_parse();
int flags = cs~load_uint(4);
if (flags & 1) { ;; ignore all bounced messages
return ();
}

load_data(); ;; here we populate the storage variables

int op = in_msg_body~load_uint(32); ;; by convention, the first 32 bits of incoming message is the op
int query_id = in_msg_body~load_uint(64); ;; also by convention, the next 64 bits contain the "query id", although this is not always the case

if (op == op::increase) {
int increase_by = in_msg_body~load_uint(32);
ctx_counter += increase_by;
save_data();
return ();
}
elseif (op == op::withdraw) {
slice recipient_slice = in_msg_body~load_msg_addr();
int amount = in_msg_body~load_grams();

if (my_balance < amount) {
;; Not enough balance to withdraw
throw(1001);
}

send_grams(recipient_slice, amount);
}
else {
throw(0xffff);
}
}

;; get methods are a means to conveniently read contract data using, for example, HTTP APIs
;; they are marked with method_id
;; note that unlike in many other smart contract VMs, get methods cannot be called by other contracts

int get_counter() method_id {
load_data();
return ctx_counter;
}

int get_id() method_id {
load_data();
return ctx_id;
}
Loading

0 comments on commit 2bdcce0

Please sign in to comment.