https://github.com/Tynik/python-fift
The python module to implement TON smart contracts
https://github.com/Tynik/python-fift
blockchain contest fift prototype python smart-contract telegram ton
Last synced: over 1 year ago
JSON representation
The python module to implement TON smart contracts
- Host: GitHub
- URL: https://github.com/Tynik/python-fift
- Owner: Tynik
- License: gpl-3.0
- Archived: true
- Created: 2019-10-25T18:13:47.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-18T06:04:30.000Z (over 6 years ago)
- Last Synced: 2024-10-23T20:13:08.603Z (over 1 year ago)
- Topics: blockchain, contest, fift, prototype, python, smart-contract, telegram, ton
- Language: Python
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Python to Fift language transformer [PROTOTYPE]
It's the prototype version and only has a little bit a part of Fift language
possibility.
Fift language book [link](https://test.ton.org/fiftbase.pdf).
### Examples
Create an empty Fift script:
```python
from fift.fift import *
@script(out_filename='script.fif')
def main():
# python code which will be transformed to Fift language
pass
fift_code = main()
```
So, you can do something with the generated Fift code in `fift_code` variable or
set an optional keyword argument `out_filename` and the code will be automatically
saved into the passed filename.
To run the code transformation you need to call a function `main` wrapped `@script`
decorator. As a result you will get the generated Fift code.
#### Include another Fift script
```python
from fift.fift import *
@script()
def main():
# will be transformed as `"Asm.fif" include`
include('Asm.fif')
include('TonUtil.fif')
main()
```
#### Work with strings
```python
from fift.fift import *
@script()
def main():
# Transforms in: `"abc"`
string('abc')
# Concatenation of many string values. Transforms in: `"a" "b" $+ 1 (.) $+`
string('a', 'b', 1)
# Transforms in: `."abc"`
string('abc').print()
# Transforms in: `."abc" cr`
string('abc').print(cr=True)
# Convert a constant with number value to string value
# Transforms in: `1 constant a`
a = const('a', 1)
# Transforms in: `@' a (.) =: a`
assign(a, string(a))
main()
```
#### Create the new word and its usage
```python
from fift.fift import *
@script()
def main():
# Transforms in: `{ dup * } : square`
square = word('square', dup(), '*')
# `2 square`
square(2)
# `{ dup square square * } : **5`
power5 = word('**5', square(square(dup())), '*')
power5(3)
main()
```
#### Create the different constants
```python
from fift.fift import *
@script()
def main():
# create a constant with name `a` and value `1`
a = const('a', 1)
# will be transformed as `dictnew constant d`
d = const('d', {})
# if a constant created with `{}` value the result variable will have `Dict` interface
# and you can add a new value to the created dict with using the next ways
# where:
# 1 : it's the key
# (4, 'u') : the key size and type (u - unsigned, i - signed)
# builder() : the value. Transformed as ``. Also, you can pass another entity as value.
d.add(1, (4, 'u'), builder())
d[2] = ((4, 'u'), builder())
# create the string constant
const('c', String('abc'))
main()
```
#### Construct the builder
```python
from fift.fift import *
@script()
def main():
# create an empty builder and will be transformed as ``
builder()
# ``
builder().u(0, 32)
# ``
builder().i(2, 4)
# ``
builder().b(swap())
# ``
builder().r(swap())
# ``
builder().s('b{1001}')
# ``
builder().u(3, 16).inspect()
# ``
builder().u(0, 32).i(2, 4)
main()
```
#### Work with files (read, write and data deserialization)
```python
from fift.fift import *
@script()
def main():
# read a file. Transforms in `"test.bin" file>B`
file('test.bin').read()
# write to file. Transforms in `"test.bin" B>file`
file('test.bin').write()
# deserialize data from a file
# transforms in `"test.bin" file>B B>boc B B>boc