blockchain

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 22 Imported by: 4

Documentation

Index

Constants

View Source
const (
	BLOCKCHAIN_PORT_RANGE_START       = 5000
	BLOCKCHAIN_PORT_RANGE_END         = 5003
	NEIGHBOR_IP_RANGE_START           = 0
	NEIGHBOR_IP_RANGE_END             = 0
	BLOCKCHAIN_NEIGHBOR_SYNC_TIME_SEC = 5
)
View Source
const (
	MINING_DIFFICULTY  = 2
	MINING_SENDER      = "METCHAIN_Blockchain"
	MINING_REWARD      = 0.3
	MINING_REWARD_MEGA = 3
	MINING_REWARD_MET  = 15
	MINING_TIMER_SEC   = 10
	STAKING_SENDER     = "Coinbase"
)

Variables

View Source
var MBlockkey = database.MakeBucket([]byte("block"))
View Source
var Utxokey = database.MakeBucket([]byte("utxo_tx"))

Functions

func AddBig

func AddBig(x float32, y float64) *big.Float

func CheckNFT

func CheckNFT(nv []int, nft string) bool

func CreateMiniBlock

func CreateMiniBlock(b *pb.RpcBlock, db database.Database, bc *Blockchain) ([32]byte, error, float64)

func GetBlockDB

func GetBlockDB(height int) ([]byte, []byte)

func Hash

func Hash(previousHash []byte, timestamp int64, nonce uint64) [32]byte

func LastWallet

func LastWallet(db database.Database) ([]byte, []byte)

func MatchBlockHeight

func MatchBlockHeight(i uint64, j uint64) error

func MatchDomainToP2PBytes

func MatchDomainToP2PBytes(ov []byte, nv []byte) error

func StakedInfo

func StakedInfo(txhash [32]byte, b *MiniBlock, z *NFTStaking) *pb.StakeNFT

func StringTo32Byte

func StringTo32Byte(e string) [32]byte

func SubBig

func SubBig(x float32, y float64) *big.Float

func VerifyAddressPrefix

func VerifyAddressPrefix(str string) string

Types

type AmountRespose

type AmountRespose struct {
	Amount float32 `json:"amount"`
}

func (*AmountRespose) MarshalJSON

func (ar *AmountRespose) MarshalJSON() ([]byte, error)

type Blockchain

type Blockchain struct {
	Txpool []*Transaction

	Unstake []*int64
	//Add on 10/4/2023 Update for recording the wallets created. Not to be changed
	Wallets        []*WalletCreated
	MiniBlock      []string
	MetBlock       []string
	MegaBlock      []string
	MiniBlockCount int
	MetBlockCount  int
	MegaBlockCount int

	NFTPool  []*NFTStaking
	NFTStake []*pb.StakeNFT
	//added for localnodes
	Port uint16
	//added for mining
	Mux sync.Mutex

	MuxNeighbors sync.Mutex

	LastRPCBlock *LastRPCBlock
	*domain.Metchain
}

func Start

func Start(db database.Database) *Blockchain

func (*Blockchain) AddWallet

func (bc *Blockchain) AddWallet(wallet string) bool

func (*Blockchain) CheckNFTRewards

func (bc *Blockchain) CheckNFTRewards() []*Transaction

func (*Blockchain) ClearStake

func (bc *Blockchain) ClearStake(ls []*int64)

func (*Blockchain) ClearTransactionPool

func (bc *Blockchain) ClearTransactionPool()

func (*Blockchain) ConverOldNFTToNew

func (bc *Blockchain) ConverOldNFTToNew(m []byte, nft *pb.StakeNFT) (*pb.StakeNFT, error)

func (*Blockchain) ConvertBlockToDomainBlock

func (mbc *Blockchain) ConvertBlockToDomainBlock() *pb.BlockInfo

func (*Blockchain) ConvertBlockToDomainGroupBlock

func (bc *Blockchain) ConvertBlockToDomainGroupBlock(b *pb.BlockInfo) []*pb.BlockInfo

func (*Blockchain) ConvertGroupToSecureDomainInfo

func (bc *Blockchain) ConvertGroupToSecureDomainInfo(bks []*pb.BlockInfo) *pb.P2PBlockWithTrustedDataResponseMessage

func (*Blockchain) GetNFT

func (bc *Blockchain) GetNFT() *Nft

func (*Blockchain) GetStakedNFT

func (bc *Blockchain) GetStakedNFT() []*pb.StakeNFT

func (*Blockchain) LastMiniBlockRPC

func (bc *Blockchain) LastMiniBlockRPC() error

func (*Blockchain) MatchDomainBlockToP2PBlock

func (bc *Blockchain) MatchDomainBlockToP2PBlock(bk *pb.P2PBlockWithTrustedDataRequestMessage, domainIP net.Addr) error

func (*Blockchain) P2PBlockUngroup

func (*Blockchain) ProofOfWork

func (bc *Blockchain) ProofOfWork() uint64

func (*Blockchain) StakeNFTMet

func (bc *Blockchain) StakeNFTMet(sender string, seed string, value string, nft string, stakeunlock string) bool

func (*Blockchain) StakedNFT

func (bc *Blockchain) StakedNFT(b *MiniBlock, pool []*NFTStaking) []*Transaction

func (*Blockchain) TransactionPool

func (bc *Blockchain) TransactionPool() []*Transaction

func (*Blockchain) ValidChain

func (bc *Blockchain) ValidChain(chain []*MiniBlock) bool

func (*Blockchain) ValidProof

func (bc *Blockchain) ValidProof(nonce uint64, previousHash [32]byte, transactions []*Transaction, difficulty int, megablock [32]byte, metblock [32]byte) bool

func (*Blockchain) VerifyNFT

func (bc *Blockchain) VerifyNFT(wx string) []byte

func (*Blockchain) VerifyTransactionSignature

func (bc *Blockchain) VerifyTransactionSignature(senderPublickey *ecdsa.PublicKey, s *utils.Signature, tx *Transaction) error

for verification if the transaction is legit

func (*Blockchain) WalletToDB

func (bc *Blockchain) WalletToDB(db database.Database, nb *MiniBlock) error

type DomainBlock

type DomainBlock struct {
	Height         uint64
	Timestamp      int64
	Nonce          uint64
	PreviousHash   [32]byte //As per the Hash size
	Megablock      [32]byte
	Metblock       [32]byte
	Transactions   []*Transaction
	CurrentHash    [32]byte
	UtxoCommitment string
	Bits           uint64
}

type GenesisConsensus

type GenesisConsensus struct {
	Timestamp    int64
	Nonce        int
	PreviousHash [32]byte //As per the Hash size
	Merkleroot   []byte
	Height       int64
	Transaction  *mconfig.Txtransaction
}

func GenesisGenrate

func GenesisGenrate() *GenesisConsensus

func (*GenesisConsensus) GensisCompile

func (gc *GenesisConsensus) GensisCompile() []byte

func (*GenesisConsensus) MarshalJSON

func (gc *GenesisConsensus) MarshalJSON() ([]byte, error)

func (*GenesisConsensus) VerifyGenesis

func (gc *GenesisConsensus) VerifyGenesis() (string, bool)

func (*GenesisConsensus) VerifyMerkleRoot

func (gc *GenesisConsensus) VerifyMerkleRoot()

func (*GenesisConsensus) VerifyMessage

func (gc *GenesisConsensus) VerifyMessage()

func (*GenesisConsensus) VerifyNonce

func (gc *GenesisConsensus) VerifyNonce()

func (*GenesisConsensus) VerifyPreviousHash

func (gc *GenesisConsensus) VerifyPreviousHash()

func (*GenesisConsensus) VerifyTimestamp

func (gc *GenesisConsensus) VerifyTimestamp()

func (*GenesisConsensus) VerifyTransaction

func (gc *GenesisConsensus) VerifyTransaction()

type JsonMiniBlock

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

type LastRPCBlock

type LastRPCBlock struct {
	Height       uint64
	Timestamp    int64
	Nonce        uint64
	PreviousHash [32]byte //As per the Hash size
	Megablock    [32]byte
	Metblock     [32]byte
	Transactions []*Transaction
	CurrentHash  [32]byte
	Bits         uint64
}

func (*LastRPCBlock) BlockToRPCLastBlock

func (lb *LastRPCBlock) BlockToRPCLastBlock(nb *MiniBlock) *LastRPCBlock

type MBlock

type MBlock struct {
	Height       uint64
	Timestamp    int64
	Nonce        uint64
	PreviousHash [32]byte //As per the Hash size
	Megablock    [32]byte
	Metblock     [32]byte
	Transactions []*Transaction
	CurrentHash  [32]byte
	Bits         uint64
}

func (*MBlock) DomainblockToRPCBlock

func (B *MBlock) DomainblockToRPCBlock(val []byte) error

func (*MBlock) UnmarshalJSON

func (b *MBlock) UnmarshalJSON(data []byte) error

type MiniBlock

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

func (*MiniBlock) BlockToDB

func (b *MiniBlock) BlockToDB(db database.Database) error

func (*MiniBlock) Hash

func (b *MiniBlock) Hash() [32]byte

func (*MiniBlock) MarshalJSON

func (b *MiniBlock) MarshalJSON() ([]byte, error)

func (*MiniBlock) Nonce

func (b *MiniBlock) Nonce() uint64

func (*MiniBlock) PreviousHash

func (b *MiniBlock) PreviousHash() [32]byte

func (*MiniBlock) Transactions

func (b *MiniBlock) Transactions() []*Transaction

func (*MiniBlock) UnmarshalJSON

func (b *MiniBlock) UnmarshalJSON(data []byte) error

type NFTStaking

type NFTStaking struct {
	NFT           int
	MetCoin       float64
	WalletAddress string
	LockTime      int64
	UnLockTime    int64
	Status        bool
	LockingTXHash []byte
}

type Nft

type Nft struct {
	Superrare  []int
	Rare       []int
	LessCommon []int
	Common     []int
}

type TransactionRequest

type TransactionRequest struct {
	SenderBlockchainAddress    *string  `json:"senderBlockchainAddress"`
	RecipientBlockchainAddress *string  `json:"recipientBlockchainAddress"`
	SenderPublicKey            *string  `json:"senderPublicKey"`
	Value                      *float32 `json:"value"`
	Signature                  *string  `json:"signature"`
}

type TxVerify

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

func (*TxVerify) VerifySignature

func (Tx *TxVerify) VerifySignature() error

type Txtransaction

type Txtransaction struct {
	Txhex      []byte
	Txcoinbase []byte
}

func (*Txtransaction) MarshalJSON

func (tx *Txtransaction) MarshalJSON() ([]byte, error)

type WalletCreated

type WalletCreated struct {
	WalletAddress string
	BlockHash     string
	LockHash      string
}

func (*WalletCreated) MarshalJSON

func (wc *WalletCreated) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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