stafi-node documentation

If you want to run the node locally, you need to setup the node as follow steps. Or you can connect to our node wss://stafi-node.wetez.io/‌

Run node

1, Docker

docker run --name stafi -p 9944:9944 -it stafiprotocol/stafi:v0.1

2, Build from source

(1) Initial Setup

curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env
rustup update stable
rustup update nightly
rustup default nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
cargo install --git https://github.com/alexcrichton/wasm-gc

You will also need to install the following packages:‌

Linux:

sudo apt install cmake pkg-config libssl-dev git clang libclang-dev

‌Mac:

brew install cmake pkg-config openssl git llvm

(2) Source code

git clone https://github.com/stafiprotocol/stafi-node

(3) Building

cargo build --release

​‌

(4) Running

./target/release/stafi --dev

​‌

Module test

‌Open the ui tool: https://polkadot.js.org/apps/#/settings​‌

Click the General tab and set the remote node to Local Node.

Or set the remote node to our node wss://stafi-node.wetez.io/‌

Click the Developer tab and config the json file.

{ "StakeTokenType": { "_enum": [ "FIS", "XTZ", "ATOM" ] }, "XtzStakeData": { "id": "Hash", "initiator": "AccountId", "stage": "XtzStakeStage", "multi_sig_address": "Vec", "stake_amount": "u128", "tx_hash": "Vec", "block_hash": "Vec", "stake_account": "Vec", "sig": "Vec" }, "XtzStakeStage": { "_enum": [ "Init", "Completed" ] }, "AtomStakeStage": { "_enum": [ "Init", "TransferSuccess", "Staking", "Completed" ] }, "AtomStakeData": { "id": "Hash", "initiator": "AccountId", "stage": "AtomStakeStage", "multi_sig_address": "Vec", "stake_amount": "u128", "tx_hash": "Vec", "block_hash": "Vec", "stake_account": "Vec", "sig": "Vec" }, "TransactionType": { "_enum": [ "TransferStafi" ] }, "Transaction": { "tx_type": "TransactionType", "data": "Vec" }, "Transfer": { "to": "AccountId", "value": "Balance" }, "PendingState": { "yet_needed": "u32", "owners_done": "u32", "index": "u32" }, "Symbol": { "_enum": [ "XTZ", "ATOM", "FIS" ] }, "BondTokenLockType": { "_enum": [ "Redemption" ] }, "BondTokenLockStatus": { "_enum": [ "Locked", "Completed" ] }, "Precision": "u16", "Token": { "symbol": "Symbol", "token_desc": "TokenDesc", "precision": "Precision" }, "TokenDesc": "Vec", "BondToken": { "id": "Hash", "account_id": "AccountId", "symbol": "Symbol", "balance": "Balance", "capital_amount": "Balance", "rewards_amount": "Balance", "last_reward_block_num": "BlockNumber", "issue_block": "BlockNumber", "stake_id": "Hash", "stake_address": "Vec", "lock_ids": "Vec" }, "LockBondData": { "id": "Hash", "bond_id": "Hash", "lock_type": "BondTokenLockType", "lock_amount": "BlockNumber", "lock_block": "Moment", "status": "BondTokenLockStatus" }, "BondReward": { "block_num": "BlockNumber", "total_reward": "Balance", "total_balance": "Balance" }, "CustomRedeemData": { "initiator": "AccountId", "lock_id": "Hash", "original_account_id": "Vec" }, "TxHashType": "Vec", "BabeIdType": "Vec", "VerifiedData": { "tx_hash": "TxHashType", "timestamp": "u64", "status": "i8", "babe_key": "BabeIdType", "babe_num": "u8" }, "AuthIndex": "u32", "OcVerifiedData": { "tx_hash": "TxHashType", "timestamp": "u64", "status": "i8", "babe_id": "AccountId", "babe_num": "u8", "authority_index": "AuthIndex" }, "HostData": { "host": "Vec", "weight": "u8" }, "ChainType": { "_enum": [ "TEZOS", "COSMOS", "STAFI" ] }, "MultisigAddr": { "chain_type": "ChainType", "multisig_addr": "Vec" } }

​‌

1, Basic multi-signature module

To generate a multi-signature address with some balances and make transaction from multi-signature address to a normal address.

You can check the codes of module stafi-multifsig.

(1) Generate a multi-signature address.

Follow the step 1, 2, 3, 4, 5 as shown below.

Generate multi-signature address by ALICE/BOB/CHARLIE.

The required_num is 2 which means it needs 2 signatures from ALICE/BOB/CHARLIE to make transaction from multi-signature address.

The value is preset balance of the multi-signature address.

Sign and Submit

(2) Check the multi-signature address

5ChiZF8pRmPzujGmRu9fQVaMTRYxzb9wP9mSVbTJYXXhXe7e

(3) Test transfer from multi-signature address to a normal address.

Follow the step 1, 2, 3, 4, 5 as shown below.

Transfer 2 DEV from the multi-signature address to ALICE_SESSION.

After submitting transaction, ALICE has signed the transaction message by default.

(4) Get the multi_sig_id from the step 3.

Follow the step 1, 2, 3, 4 as shown below.

the multi_sig_id is 0xe322efd303e5a5cb50e4f831875daaa2df4d15948093d5e766ae6c35068e7e07

(5) Confirm the transfer transaction from BOB.

Follow the step 1, 2, 3, 4, 5 as shown below.

Submit the transaction.

(6) Check the balance of ALICE_SESSION

The balance is 2 DEV. It's successful.

2, Tokenbalances module

You can check the codes of module tokenbalances.

(1) Register custom token

Follow the step 1, 2, 3, 4, 5 as shown below.

Submit the transaction.

(2) Check the custom token

Follow the step 1, 2, 3, 4 as shown below.

(3) Set free token balance for a account

Follow the step 1, 2, 3, 4, 5 as shown below.

Submit the transaction.

(4) Check the free token balance of a account

Follow the step 1, 2, 3, 4 as shown below.

3, Stake custom token(xtz)

The user can stake custom token(such as xtz) by submitting transaction hash,block hash etc. And the system will check legitimacy and correctness of the transaction by making HTTP requests using off-chain worker mechanism.

Now we will use some test datas generated on tezos zeronet to show you the process.

And please note these test datas will be expired on tezos zeronet. So if you want to test it yourself, you need to generate these test datas or contact us and we will provide them to you.

You can check the codes of module stafi-staking/xtzstaking.

(1) Stake

Follow the step 1, 2, 3, 4 as shown below. (You can omit the parameter sig first)

Submit the transaction.

(2) Check the custom stake

Please Attention. The stage is 0 when the XtzStakeData is generated. And the stage will be changed to 1 when the system check that these datas are valid and correct.

You can check the codes of module stafi-offchain-worker.

4, Tezos key pair algorithms

We implemented some methods to generate key pair and public address for tezos. Such as generate_keypair_with_password/generate_keypair_from_mnemonic/generate_keypair_from_seed in stafi-crypto/tez/generator.rs.

And we also implemented the signature algorithm which using tezos private key to sign a message and the methods to verify the signature data using public key. Such as sign/sign_with_sk/verify_with_ed in stafi-crypto/tez/sign.rs.

The algorithms will be used in xtzstaking module in the near future.

You can check the codes of module stafi-crypto(the tez directory) and run cargo test to test the algorithms.

Rpc

We implemented some rpc methods. You can check them by requesting http://rpc.stafi.io

We planned to implement more rpc methods. But then we realized maybe it's better to use polkadot-js library which is very powerful. So we just implemented three methods for now and we will implement more if necessary.

(1) multisig_getaddr

url: http://rpc.stafi.io

body:

{"id":1, "jsonrpc":"2.0", "method": "multisig_getaddr", "params":["TEZOS"]}

(2) stake_xtz_gethash

When you use 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY to run customStake of xtzStaking module and it's successful, the rpc method will return the result or the result will be empty.

url: http://rpc.stafi.io

body:

{"id":1, "jsonrpc":"2.0", "method": "stake_xtz_gethash", "params":["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"]}

(3) stake_xtz_getdata

Using the hash returned by stake_xtz_gethash and you can check more detail information.

url: http://rpc.stafi.io

body:

{"id":1, "jsonrpc":"2.0", "method": "stake_xtz_getdata", "params":["0x2eaa7446e1a3f0cc66c3adae0f20ce875313cbcb3e6969458e6487b2266fd7ae"]}

Last updated