github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/store/orgchain/validation/tx_handler.go (about)

     1  package validation
     2  
     3  import (
     4  	"math/big"
     5  
     6  	"github.com/sixexorg/magnetic-ring/common"
     7  	"github.com/sixexorg/magnetic-ring/core/orgchain/types"
     8  )
     9  
    10  type opCode byte
    11  
    12  const (
    13  	Account_ut_add       opCode = 0x01
    14  	Account_energy_add     opCode = 0x02
    15  	Account_ut_sub       opCode = 0x03
    16  	Account_energy_sub     opCode = 0x04
    17  	Account_energy_consume opCode = 0x05
    18  	Account_bonus_left   opCode = 0x06
    19  	Account_nonce_add    opCode = 0x07
    20  	AccountMaxLine       opCode = 0x19
    21  
    22  	Vote_against      opCode = 0x20
    23  	Vote_agree        opCode = 0x21
    24  	Vote_abstention   opCode = 0x22
    25  	VoteMaxLine       opCode = 0x23
    26  	Account_bonus_fee opCode = 0xa0
    27  	League_Raise_ut   opCode = 0xb0
    28  )
    29  
    30  type OpLogs []*OpLog
    31  
    32  type OpLog struct {
    33  	method opCode
    34  	data   interface{}
    35  }
    36  type OPAddressAdress struct {
    37  	First  common.Address
    38  	Second common.Address
    39  }
    40  type OPAddressUint64 struct {
    41  	Address common.Address
    42  	Num     uint64
    43  }
    44  type OPAddressBigInt struct {
    45  	Address common.Address
    46  	Num     *big.Int
    47  }
    48  type OPAddressUin32 struct {
    49  	Address common.Address
    50  	Num     *big.Int
    51  }
    52  type OPHashAddress struct {
    53  	Hash    common.Hash
    54  	Address common.Address
    55  }
    56  
    57  type OPCreateLeague struct {
    58  	Creator   common.Address
    59  	League    common.Address
    60  	NodeId    common.Address
    61  	FrozenBox *big.Int
    62  	Rate      uint32
    63  	Minbox    uint64
    64  	Private   bool
    65  }
    66  
    67  func CheckTxFee(tx *types.Transaction) bool {
    68  	switch tx.TxType {
    69  	case types.TransferUT:
    70  	case types.MSG:
    71  		//TODO other txType
    72  	}
    73  	return false
    74  }
    75  
    76  func HandleTransaction(tx *types.Transaction) []*OpLog {
    77  	oplogs := []*OpLog{}
    78  	re := false
    79  	oplogs, re = commonTxRoute(tx)
    80  	if re {
    81  		return oplogs
    82  	}
    83  	oplogs, re = voteTxRoute(tx)
    84  	if re {
    85  		return oplogs
    86  	}
    87  	oplogs, re = systemTxRoute(tx)
    88  	if re {
    89  		return oplogs
    90  	}
    91  	oplogs, re = bonusTxRoute(tx)
    92  	if re {
    93  		return oplogs
    94  	}
    95  	return oplogs
    96  }
    97  
    98  func oplogPraseAddresAddress(first, second common.Address, method opCode) *OpLog {
    99  	op := &OpLog{
   100  		method: method,
   101  		data: &OPAddressAdress{
   102  			First:  first,
   103  			Second: second,
   104  		},
   105  	}
   106  	return op
   107  
   108  }
   109  func oplogPraseAddresUint64(address common.Address, nonce uint64, method opCode) *OpLog {
   110  	op := &OpLog{
   111  		method: method,
   112  		data: &OPAddressUint64{
   113  			Address: address,
   114  			Num:     nonce,
   115  		},
   116  	}
   117  	return op
   118  }
   119  
   120  func oplogPraseAddressBigInt(address common.Address, num *big.Int, method opCode) *OpLog {
   121  	data := &OPAddressBigInt{
   122  		Address: address,
   123  		Num:     num,
   124  	}
   125  	return &OpLog{method, data}
   126  }
   127  
   128  func oplogPraseHashAddress(hash common.Hash, address common.Address, method opCode) *OpLog {
   129  	data := &OPHashAddress{
   130  		Hash:    hash,
   131  		Address: address,
   132  	}
   133  	return &OpLog{method, data}
   134  }