api

package
v0.0.0-...-8f01991 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 7 Imported by: 0

README

Confirmix HTTP API

Endpoints

Blockchain Bilgisi
GET /info

Blockchain hakkında genel bilgi alır.

curl http://localhost:8080/info
GET /blocks

Tüm blokları listeler.

curl http://localhost:8080/blocks
GET /blocks/:hash

Hash değeri ile belirli bir bloğu getirir.

curl http://localhost:8080/blocks/[BLOCK_HASH]
Validator İşlemleri
GET /validators

Tüm validatorları listeler.

curl http://localhost:8080/validators
GET /validators/current

Şu anki aktif validator'ı gösterir.

curl http://localhost:8080/validators/current
POST /validators

Yeni bir validator ekler.

curl -X POST http://localhost:8080/validators
DELETE /validators/:address

Belirtilen validator'ı siler.

curl -X DELETE http://localhost:8080/validators/[VALIDATOR_ADDRESS]
İşlem Gönderme
POST /transactions

Yeni bir işlem gönderir.

curl -X POST http://localhost:8080/transactions \
  -H "Content-Type: application/json" \
  -d '{
    "data": "Alice'den Bob'a 50 coin transfer",
    "validator": "[VALIDATOR_ADDRESS]"
  }'

Smart Contract Endpoints

Deploy Contract
POST /contracts

Deploy a new smart contract.

Request Body:

{
    "code": "608060405234801561001057600080fd5b50...",  // Contract bytecode (hex)
    "owner": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
    "name": "MyToken",
    "version": "1.0.0"
}

Response:

{
    "address": "0x1234...",
    "owner": "0x742d...",
    "name": "MyToken",
    "version": "1.0.0",
    "timestamp": 1647123456,
    "is_enabled": true
}
List Contracts
GET /contracts

Returns a list of all deployed contracts.

Response:

[
    {
        "address": "0x1234...",
        "owner": "0x742d...",
        "name": "MyToken",
        "version": "1.0.0",
        "timestamp": 1647123456,
        "is_enabled": true
    }
]
Get Contract
GET /contracts/:address

Returns details of a specific contract.

Response:

{
    "address": "0x1234...",
    "owner": "0x742d...",
    "name": "MyToken",
    "version": "1.0.0",
    "timestamp": 1647123456,
    "is_enabled": true
}
Execute Contract
POST /contracts/:address/execute

Execute a smart contract method.

Request Body:

{
    "input": "a9059cbb000000000000000000000000..."  // Method call data (hex)
}

Response:

{
    "result": "0000000000000000000000000000000000000000000000000000000000000001"
}
Disable Contract
POST /contracts/:address/disable

Disable a smart contract (only contract owner).

Request Body:

{
    "owner": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
}
Enable Contract
POST /contracts/:address/enable

Enable a disabled smart contract (only contract owner).

Request Body:

{
    "owner": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
}

Örnek Kullanım

  1. Blockchain bilgisini al:
curl http://localhost:8080/info
  1. Mevcut validator'ı kontrol et:
curl http://localhost:8080/validators/current
  1. Yeni bir işlem gönder:
curl -X POST http://localhost:8080/transactions \
  -H "Content-Type: application/json" \
  -d '{
    "data": "Alice'den Bob'a 50 coin transfer",
    "validator": "[VALIDATOR_ADDRESS]"
  }'
  1. Tüm blokları listele:
curl http://localhost:8080/blocks

Notlar

  • Tüm POST istekleri için Content-Type: application/json header'ı gereklidir
  • Validator adresleri, validator oluşturulduğunda console'da görüntülenir
  • Round-Robin konsensüs nedeniyle, işlemler sadece sırası gelen validator tarafından eklenebilir
  • Bloklar arası minimum 5 saniyelik bekleme süresi vardır
  • All POST requests must include the Content-Type: application/json header
  • Contract code and input data must be hex-encoded
  • Contract addresses are automatically generated based on the code, owner, and timestamp
  • Only the contract owner can disable or enable a contract
  • Contract execution follows the EVM specification

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents the HTTP API server

func NewServer

func NewServer(bc *blockchain.Blockchain) *Server

NewServer creates a new HTTP API server

func (*Server) Run

func (s *Server) Run(addr string) error

Run starts the HTTP server

type TransactionRequest

type TransactionRequest struct {
	Data      string `json:"data" binding:"required"`
	Validator string `json:"validator" binding:"required"`
}

TransactionRequest represents a new transaction request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL