This is a project I created to simulate the operation of a Blockchain.
Download this repo, then, run cargo run
;
I've built an experimental Contract that uses Kibi Blockchain to store / read data. To use it, follow these steps:
-
1 - Clone this repo and run
cargo run
; -
2 - Go to Kib GreetingContract repo and clone it;
-
3 - Inside the
kibi-greeting-contract
repo/folder, run one of the commands below:
Persisting a greeting
:
# dev-1234 = the contract id
# set_greeting = is a contract's method
# "Hello from Wendz!" = is the string value to be stored on chain under the contract
cargo run -- call dev-1234 set_greeting "Hello from Wendz!"
Viewing the current greeting
:
# dev-1234 = the contract id
# greeting = is a contract's field
cargo run -- view dev-1234 greeting
-
1 - Run
cargo run
. -
2 - Execute the command bellow to create an account (change the account value as you wish):
curl --location 'http://localhost:8000/create_account' \
--header 'Content-Type: application/json' \
--data '{
"account": "wendersonpires"
}'
- 2 - Execute the command bellow to get the current chain data:
curl --location 'http://localhost:8000/chain'
You can navigate over the REST Api to get to know more.
REST Api
URI: http://localhost:8000
METHOD: GET
URI: http://localhost:8000/new_transaction
METHOD: POST
BODY:
{
"from": "public key? user name?",
"to": "<optional for now>",
"content": "json content"
}
O body
que é o dado
de cada transação é salvo na chain em forma de String (stringified JSON).
URI: http://localhost:8000/create_account
METHOD: POST
BODY:
AUTO-MINE: true
{
"account": "wendersonpires.kib"
}
Esta rota faz executa o mine
automaticamente pois deve-se assegurar que uma conta igual não seja registrada novamente.
URI: http://localhost:8000/mine
METHOD: GET
URI: http://localhost:8000/chain
METHOD: GET
Durante o processo de buscar os blocos, todos os dados (transactions
/ dado
) é convertido para JSON novamente para ser exibido ao cliente final.
URI: http://localhost:8000/contract_transaction
METHOD: POST
BODY:
{
"tx_type": "CONTRACT",
"contract_id": "dev-1234",
"data": "stringified json content"
}
Rota usada para guardar novos dados em um contrato específico.
URI: http://localhost:8000/contract_payload/<contract_id>
METHOD: GET
Rota usada para buscar os dados mais atuais de um contrato.
URI: http://localhost:8000/contract_payload_json/<contract_id>
METHOD: GET
Rota usada para buscar os dados mais atuais de um contrato e retorna-los no formato JSON.