txs

package
v0.0.0-...-ab07e92 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClientRegistrationType   = 1
	ServiceRequestType       = 2
	ClientRatingMsgType      = 3
	MinerRegistrationType    = 4
	MinerServiceDoneType     = 5
	MinerStatusUpdateType    = 6
	MinerRewardClaimType     = 7
	MinerServiceStartingType = 8
)
View Source
const PersonalMessagePrefix = "\x19Ethereum Signed Message:\n"

PersonalMessagePrefix is the prefix used by the eth_sign method in MetaMask.

Variables

This section is empty.

Functions

func AddressFromPublicKey

func AddressFromPublicKey(pubKey *ecdsa.PublicKey) string

AddressFromPublicKey derives the Ethereum address from a public key.

func DecodeMessageAndSignature

func DecodeMessageAndSignature(data string) (string, string, error)

func EncodeMessageAndSignature

func EncodeMessageAndSignature(message string, signature string) (string, error)

func HashPersonalMessage

func HashPersonalMessage(message []byte) []byte

HashPersonalMessage hashes a message according to the personal_sign spec.

func HexToBytes

func HexToBytes(hexStr string) ([]byte, error)

HexToBytes converts a hex string to a byte array.

func RecoverPubKey

func RecoverPubKey(hash, signature []byte) (*ecdsa.PublicKey, error)

RecoverPubKey recovers the public key from a hash and a signature.

func SelectPseudorandomMiner

func SelectPseudorandomMiner(miners []string, blockHeight int64, appHash []byte, serviceID string) string

SelectPseudorandomMiner selects a miner pseudorandomly based on the block height, app hash, and service ID.

Types

type ClientRatingMsg

type ClientRatingMsg struct {
	ReviewedMinerAddr string `json:"miner_addr"`
	Rating            int    `json:"rating"`
}

func (ClientRatingMsg) ToBytes

func (m ClientRatingMsg) ToBytes() ([]byte, error)

type ClientRegistrationMsg

type ClientRegistrationMsg struct {
	ClientName string `json:"client_name"`
}

func (ClientRegistrationMsg) ToBytes

func (m ClientRegistrationMsg) ToBytes() ([]byte, error)

Implement ToBytes for each struct

type Message

type Message struct {
	Type    uint8  `json:"type"`
	Content []byte `json:"content"`
}

func (*Message) DecodeContent

func (m *Message) DecodeContent() (MessageContent, error)

func (Message) MarshalJSON

func (m Message) MarshalJSON() ([]byte, error)

MarshalJSON customizes the JSON encoding of the Message struct

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(data []byte) error

UnmarshalJSON customizes the JSON decoding of the Message struct

type MessageContent

type MessageContent interface {
	ToBytes() ([]byte, error)
}

type MinerRegistrationMsg

type MinerRegistrationMsg struct {
	MinerName    string   `json:"miner_name"`    // The name of the miner
	ServiceTypes []uint64 `json:"service_types"` // An array of service type identifiers
	IP           string   `json:"ip"`            // The IP address of the miner for network connections
	Status       uint8    `json:"status"`
}

func (MinerRegistrationMsg) ToBytes

func (m MinerRegistrationMsg) ToBytes() ([]byte, error)

type MinerRewardClaimMsg

type MinerRewardClaimMsg struct{}

func (MinerRewardClaimMsg) ToBytes

func (m MinerRewardClaimMsg) ToBytes() ([]byte, error)

type MinerServiceDoneMsg

type MinerServiceDoneMsg struct {
	ServiceID   string `json:"service_id"`   // Unique identifier for the service
	ServiceType uint64 `json:"service_type"` // Numeric identifier of the type of service completed
}

func (MinerServiceDoneMsg) ToBytes

func (m MinerServiceDoneMsg) ToBytes() ([]byte, error)

type MinerStatusUpdateMsg

type MinerStatusUpdateMsg struct {
	AddServiceTypes    []uint64 `json:"service_types"`
	RemoveServiceTypes []uint64 `json:"service_types"`
	Status             uint8    `json:"status"`
}

func (MinerStatusUpdateMsg) ToBytes

func (m MinerStatusUpdateMsg) ToBytes() ([]byte, error)

type ServiceRequestMsg

type ServiceRequestMsg struct {
	ServiceID uint64 `json:"service_id"`
	Meta      []byte `json:"meta"`
}

func (ServiceRequestMsg) ToBytes

func (m ServiceRequestMsg) ToBytes() ([]byte, error)

type ServiceStartingMsg

type ServiceStartingMsg struct {
	ServiceID       string `json:"service_id"`        // Unique identifier for the service
	MaxTimeoutBlock int64  `json:"max_timeout_block"` // Maximum number of blocks the service should run before automatic termination
}

ServiceStartingMsg defines the data structure for initiating a service process.

func (ServiceStartingMsg) ToBytes

func (m ServiceStartingMsg) ToBytes() ([]byte, error)

ToBytes converts the ServiceStartingMsg to a byte slice for easy transmission and storage.

type Transaction

type Transaction struct {
	Msg       Message `json:"msg"`
	Signature string  `json:"signature"`
}

func (*Transaction) FromString

func (t *Transaction) FromString(encodedString string) error

func (Transaction) ToString

func (t Transaction) ToString() (string, error)

Jump to

Keyboard shortcuts

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