github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/radar/mainchain/across_tx.go (about) 1 package mainchain 2 3 import ( 4 "math/big" 5 6 "github.com/sixexorg/magnetic-ring/common" 7 maintypes "github.com/sixexorg/magnetic-ring/core/mainchain/types" 8 orgtypes "github.com/sixexorg/magnetic-ring/core/orgchain/types" 9 "github.com/sixexorg/magnetic-ring/errors" 10 ) 11 12 type LeagueEntiy struct { 13 Name string 14 Rate uint32 15 MinBox uint64 16 Creator common.Address 17 MetaBox *big.Int 18 } 19 20 func checkOrgTx(mainTx *maintypes.Transaction, orgTx *orgtypes.Transaction) error { 21 if orgTx.TxType == orgtypes.Join && 22 mainTx.TxType == maintypes.JoinLeague && 23 mainTx.TxData.Account == orgTx.TxData.From { 24 return nil 25 26 } else if orgTx.TxType == orgtypes.EnergyFromMain && 27 mainTx.TxType == maintypes.EnergyToLeague && 28 mainTx.TxData.From == orgTx.TxData.From && 29 mainTx.TxData.Energy.Cmp(orgTx.TxData.Energy) == 0 { 30 return nil 31 } 32 return errors.ERR_EXTERNAL_TX_REFERENCE_WRONG 33 } 34 35 //todo Currently, the nonce value of the cross-chain is set to 0, and the value is automatically assigned when the main chain txpool is verified. 36 // The logic is not implemented at present, and the later implementation is implemented. 37 func orgTxBirthMainTx(tx *orgtypes.Transaction, height uint64, leagueId common.Address, f func(leagueId common.Address) (rate uint32)) *maintypes.Transaction { 38 var mainTx *maintypes.Transaction 39 switch tx.TxType { 40 case orgtypes.EnergyToMain: 41 mainTx = &maintypes.Transaction{ 42 Version: maintypes.TxVersion, 43 TxType: maintypes.EnergyToMain, 44 TxData: &maintypes.TxData{ 45 From: tx.TxData.From, 46 LeagueId: leagueId, 47 Energy: tx.TxData.Energy, 48 }, 49 } 50 case orgtypes.VoteIncreaseUT: 51 mainTx = &maintypes.Transaction{ 52 Version: maintypes.TxVersion, 53 TxType: maintypes.RaiseUT, 54 TxData: &maintypes.TxData{ 55 From: tx.TxData.From, 56 LeagueId: leagueId, 57 MetaBox: tx.TxData.MetaBox, 58 }, 59 } 60 case orgtypes.VoteApply: 61 mainTx = &maintypes.Transaction{ 62 Version: maintypes.TxVersion, 63 TxType: maintypes.ApplyPass, 64 TxData: &maintypes.TxData{ 65 From: tx.TxData.From, 66 LeagueId: leagueId, 67 TxHash: tx.Hash(), 68 }, 69 } 70 71 } 72 return mainTx 73 }