hauska

package module
v0.0.0-...-93c4166 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: MIT Imports: 9 Imported by: 0

README ΒΆ

Hauska Go SDK

A Go SDK for interacting with Hauska smart contracts, providing idiomatic Go interfaces for blockchain-based digital asset management and licensing.


βœ… What's Complete

  • Full package structure and modular organization
  • All core types, interfaces, and service definitions
  • High-level client API design
  • Error definitions and usage examples
  • Contract bindings generated using abigen
  • Automated build script with ABI extraction

πŸ”„ What's Pending

  • Full implementation of service methods using contract bindings
  • Network integration and testing
  • Documentation and unit tests

πŸ“ Project Structure

sdk/
β”œβ”€β”€ go.mod
β”œβ”€β”€ sdk.go                 # Main SDK entrypoint
β”œβ”€β”€ config.go              # Config definitions
β”œβ”€β”€ errors.go              # Error constants
β”œβ”€β”€ types/                 # Core domain types
β”œβ”€β”€ services/              # Contract logic layer
β”œβ”€β”€ client/                # High-level interface layer
β”œβ”€β”€ contracts/             # Contract bindings (generated)
β”œβ”€β”€ utils/                 # Utility helpers
└── examples/              # Sample usage patterns

Contract Bindings: The contracts/ directory contains auto-generated Go bindings for all Hauska smart contracts, created using abigen and the automated build script.


πŸ—οΈ Architecture Overview

The Hauska Go SDK follows a layered architecture that provides clean separation of concerns and intuitive APIs for blockchain interaction:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           SDK (main.go)             β”‚  ← Main entry point
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Clients (client/)           β”‚  ← High-level API layer
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚        Services (services/)         β”‚  ← Business logic layer
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚       Contracts (contracts/)        β”‚  ← Auto-generated bindings
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚        Ethereum Blockchain          β”‚  ← Smart contracts
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Component Responsibilities
  • types/: Core data structures, domain models, and shared interfaces
  • contracts/: Auto-generated contract bindings (via abigen) for direct blockchain interaction
  • services/: Business logic layer handling transaction management, validation, and error handling
  • client/: High-level, user-friendly API abstractions over service operations
  • utils/: Utility functions for address validation, amount conversions, and common operations
  • config.go: Centralized configuration with Ethereum client setup and contract addresses
Communication Flow
// User calls SDK
sdk.Factory.CreateOrganization(ctx, principal, partner)
       ↓
// Client delegates to service
factoryClient.service.CreateOrganization(ctx, principal, partner)
       ↓
// Service calls contract binding
factoryContract.CreateContract(opts, principal, partner)
       ↓
// Contract binding makes blockchain call
ethereum.Call() β†’ Smart Contract on blockchain

This design provides separation of concerns, testability, and extensibility while maintaining clean, intuitive APIs for developers.


πŸ”§ Configuration

config := &hauska.Config{
    Client:         ethClient,                     // Ethereum client
    FactoryAddress: "0xFactoryContractAddress",    // Deployed Factory contract
    USDCAddress:    "0xUSDCContractAddress",       // Deployed USDC ERC20
    PrivateKey:     "...",                         // User's private key
    ChainID:        1,                             // Ethereum mainnet
    GasLimit:       300000,
    GasPrice:       big.NewInt(20000000000),
}

πŸ› οΈ Installation

go get github.com/ardata-tech/hauska-go

πŸš€ Quick Start

package main

import (
    "context"
    "log"
    "github.com/ardata-tech/hauska-go"
    "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
    client, _ := ethclient.Dial("http://localhost:8545")
    
    config := &hauska.Config{
        Client:         client,
        FactoryAddress: "0x...",
        USDCAddress:    "0x...",
        PrivateKey:     "...",
    }

    sdk, err := hauska.New(config)
    if err != nil {
        log.Fatal(err)
    }

    // Example call
    orgs, err := sdk.Clients.Factory.GetAllOrganizations(context.Background())
    if err != nil {
        log.Printf("Expected (scaffold): %v", err)
    }
}

❗ Error Handling

Defined in errors.go, the SDK includes:

  • ErrInvalidClient, ErrMissingAuth – misconfigured SDK
  • ErrContractNotFound, ErrTransactionFailed – blockchain issues
  • ErrAssetNotFound, ErrLicenseNotFound – logical not-found errors

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var (
	// Configuration errors
	ErrInvalidClient         = errors.New("invalid ethereum client")
	ErrInvalidFactoryAddress = errors.New("invalid factory contract address")
	ErrInvalidUSDCAddress    = errors.New("invalid USDC token address")
	ErrMissingAuth           = errors.New("missing authentication (private key or auth)")
	ErrInvalidPrivateKey     = errors.New("invalid private key format")

	// Contract errors
	ErrContractNotFound      = errors.New("contract not found")
	ErrInvalidContractCall   = errors.New("invalid contract call")
	ErrTransactionFailed     = errors.New("transaction failed")
	ErrInsufficientBalance   = errors.New("insufficient balance")
	ErrInsufficientAllowance = errors.New("insufficient allowance")

	// Asset errors
	ErrAssetNotFound      = errors.New("asset not found")
	ErrAssetNotVerified   = errors.New("asset not verified")
	ErrAssetNotLicensable = errors.New("asset cannot be licensed")
	ErrAssetAlreadyExists = errors.New("asset already exists")
	ErrInvalidAssetHash   = errors.New("invalid asset hash")

	// License errors
	ErrLicenseNotFound    = errors.New("license not found")
	ErrLicenseExpired     = errors.New("license expired")
	ErrLicenseNotActive   = errors.New("license not active")
	ErrAlreadyLicensed    = errors.New("already licensed")
	ErrInvalidLicenseType = errors.New("invalid license type")

	// Group errors
	ErrGroupNotFound       = errors.New("group not found")
	ErrGroupEmpty          = errors.New("group cannot be empty")
	ErrAssetNotInGroup     = errors.New("asset not in group")
	ErrAssetAlreadyInGroup = errors.New("asset already in group")

	// Organization errors
	ErrOrgNotFound   = errors.New("organization not found")
	ErrNotAuthorized = errors.New("not authorized")
	ErrInvalidRole   = errors.New("invalid role")

	// General errors
	ErrInvalidAddress    = errors.New("invalid address")
	ErrInvalidAmount     = errors.New("invalid amount")
	ErrInvalidParameters = errors.New("invalid parameters")
	ErrTimeout           = errors.New("operation timeout")
	ErrNotImplemented    = errors.New("not implemented")
)

SDK error definitions

Functions ΒΆ

This section is empty.

Types ΒΆ

type Config ΒΆ

type Config struct {
	// Ethereum client connection
	Client *ethclient.Client

	// Contract addresses
	FactoryAddress common.Address
	USDCAddress    common.Address

	// Authentication
	PrivateKey string
	Auth       *bind.TransactOpts

	// Gas settings
	GasLimit             uint64
	GasPrice             *big.Int
	MaxFeePerGas         *big.Int
	MaxPriorityFeePerGas *big.Int

	// Network settings
	ChainID *big.Int

	// Optional: Custom module addresses (if using FactoryLite)
	ModuleAddresses *ModuleAddresses
}

Config holds the configuration for the Hauska SDK

func DefaultConfig ΒΆ

func DefaultConfig() *Config

DefaultConfig returns a default configuration for local development

func (*Config) CallOptions ΒΆ

func (c *Config) CallOptions() *bind.CallOpts

CallOptions returns call options for read operations

func (*Config) TransactionOptions ΒΆ

func (c *Config) TransactionOptions() *bind.TransactOpts

TransactionOptions returns transaction options based on config

func (*Config) Validate ΒΆ

func (c *Config) Validate() error

Validate checks if the configuration is valid

func (*Config) WaitForTransaction ΒΆ

func (c *Config) WaitForTransaction(tx *types.Transaction) (*types.Receipt, error)

WaitForTransaction waits for a transaction to be mined

type ModuleAddresses ΒΆ

type ModuleAddresses struct {
	LicenseManager     common.Address
	AssetRegistry      common.Address
	GroupManager       common.Address
	RevenueDistributor common.Address
	AssetNFT           common.Address
}

ModuleAddresses holds addresses for all Hauska modules

type SDK ΒΆ

type SDK struct {

	// High-level clients
	Factory      client.FactoryClient
	Organization client.OrganizationClient
	License      client.LicenseClient
	Asset        client.AssetClient
	Group        client.GroupClient
	Revenue      client.RevenueClient
	USDC         client.USDCClient

	// Low-level services (for advanced usage)
	Services *Services
	// contains filtered or unexported fields
}

SDK is the main entry point for the Hauska Go SDK

func NewSDK ΒΆ

func NewSDK(config *Config) (*SDK, error)

NewSDK creates a new instance of the Hauska SDK

func (*SDK) Close ΒΆ

func (sdk *SDK) Close() error

Close cleans up SDK resources

func (*SDK) GetConfig ΒΆ

func (sdk *SDK) GetConfig() *Config

GetConfig returns the SDK configuration

func (*SDK) Health ΒΆ

func (sdk *SDK) Health(ctx context.Context) error

Health checks the health of all SDK components

func (*SDK) NewOrganizationClient ΒΆ

func (sdk *SDK) NewOrganizationClient(orgAddress string) (client.OrganizationClient, error)

NewOrganizationClient creates a new organization client for a specific organization

type Services ΒΆ

Services holds all low-level service implementations

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

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