Skip to content

Commit

Permalink
Merge 2dc7c68 into 125ebaa
Browse files Browse the repository at this point in the history
  • Loading branch information
erickyan86 committed Apr 30, 2019
2 parents 125ebaa + 2dc7c68 commit e375cf8
Show file tree
Hide file tree
Showing 31 changed files with 169 additions and 119 deletions.
8 changes: 4 additions & 4 deletions accountmanager/accountmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ func (am *AccountManager) process(accountManagerContext *types.AccountManagerCon
if err := am.TransferAsset(common.Name(accountManagerContext.ChainConfig.AccountName), acct.AccountName, action.AssetID(), action.Value()); err != nil {
return nil, err
}
actionX := types.NewAction(types.Transfer, common.Name(accountManagerContext.ChainConfig.AccountName), acct.AccountName, 0, action.AssetID(), 0, action.Value(), nil)
actionX := types.NewAction(types.Transfer, common.Name(accountManagerContext.ChainConfig.AccountName), acct.AccountName, 0, action.AssetID(), 0, action.Value(), nil, nil)
internalAction := &types.InternalAction{Action: actionX.NewRPCAction(0), ActionType: "", GasUsed: 0, GasLimit: 0, Depth: 0, Error: ""}
internalActions = append(internalActions, internalAction)
}
Expand Down Expand Up @@ -1293,7 +1293,7 @@ func (am *AccountManager) process(accountManagerContext *types.AccountManagerCon
if err := am.IssueAnyAsset(action.Sender(), &asset); err != nil {
return nil, err
}
actionX := types.NewAction(types.Transfer, common.Name(accountManagerContext.ChainConfig.ChainName), asset.GetAssetOwner(), 0, asset.GetAssetId(), 0, asset.GetAssetAmount(), nil)
actionX := types.NewAction(types.Transfer, common.Name(accountManagerContext.ChainConfig.ChainName), asset.GetAssetOwner(), 0, asset.GetAssetId(), 0, asset.GetAssetAmount(), nil, nil)
internalAction := &types.InternalAction{Action: actionX.NewRPCAction(0), ActionType: "", GasUsed: 0, GasLimit: 0, Depth: 0, Error: ""}
internalActions = append(internalActions, internalAction)
break
Expand All @@ -1306,7 +1306,7 @@ func (am *AccountManager) process(accountManagerContext *types.AccountManagerCon
if err = am.IncAsset2Acct(action.Sender(), inc.To, inc.AssetId, inc.Amount); err != nil {
return nil, err
}
actionX := types.NewAction(types.Transfer, common.Name(accountManagerContext.ChainConfig.ChainName), inc.To, 0, inc.AssetId, 0, inc.Amount, nil)
actionX := types.NewAction(types.Transfer, common.Name(accountManagerContext.ChainConfig.ChainName), inc.To, 0, inc.AssetId, 0, inc.Amount, nil, nil)
internalAction := &types.InternalAction{Action: actionX.NewRPCAction(0), ActionType: "", GasUsed: 0, GasLimit: 0, Depth: 0, Error: ""}
internalActions = append(internalActions, internalAction)
break
Expand All @@ -1324,7 +1324,7 @@ func (am *AccountManager) process(accountManagerContext *types.AccountManagerCon
if err := am.ast.DestroyAsset(common.Name(accountManagerContext.ChainConfig.AssetName), action.AssetID(), action.Value()); err != nil {
return nil, err
}
actionX := types.NewAction(types.Transfer, common.Name(accountManagerContext.ChainConfig.AccountName), common.Name(accountManagerContext.ChainConfig.ChainName), 0, action.AssetID(), 0, action.Value(), nil)
actionX := types.NewAction(types.Transfer, common.Name(accountManagerContext.ChainConfig.AccountName), common.Name(accountManagerContext.ChainConfig.ChainName), 0, action.AssetID(), 0, action.Value(), nil, nil)
internalAction := &types.InternalAction{Action: actionX.NewRPCAction(0), ActionType: "", GasUsed: 0, GasLimit: 0, Depth: 0, Error: ""}
internalActions = append(internalActions, internalAction)
break
Expand Down
33 changes: 16 additions & 17 deletions accountmanager/accountmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
)

var sdb = getStateDB()

var acctm = getAccountManager()
var ast = getAsset()
var sysName = "fractal.account"
Expand Down Expand Up @@ -1550,12 +1549,12 @@ func TestAccountManager_Process(t *testing.T) {
panic("rlp payload err")
}

action := types.NewAction(types.IssueAsset, common.Name("a123456789aeee"), common.Name(sysName), 1, 1, 0, big.NewInt(0), payload)
action1 := types.NewAction(types.IncreaseAsset, common.Name("a123456789aeee"), common.Name(sysName), 1, 1, 2, big.NewInt(0), payload2)
action2 := types.NewAction(types.UpdateAsset, common.Name("a123456789aeee"), common.Name(sysName), 1, 1, 2, big.NewInt(0), payload1)
action3 := types.NewAction(types.CreateAccount, common.Name("a123456789aeee"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload3)
action4 := types.NewAction(types.UpdateAccount, common.Name("a123456789addd"), common.Name(sysName), 1, 1, 2, big.NewInt(0), payload4)
action5 := types.NewAction(types.UpdateAccountAuthor, common.Name("a123456789addd"), common.Name(sysName), 1, 1, 2, big.NewInt(0), payload5)
action := types.NewAction(types.IssueAsset, common.Name("a123456789aeee"), common.Name(sysName), 1, 1, 0, big.NewInt(0), payload, nil)
action1 := types.NewAction(types.IncreaseAsset, common.Name("a123456789aeee"), common.Name(sysName), 1, 1, 2, big.NewInt(0), payload2, nil)
action2 := types.NewAction(types.UpdateAsset, common.Name("a123456789aeee"), common.Name(sysName), 1, 1, 2, big.NewInt(0), payload1, nil)
action3 := types.NewAction(types.CreateAccount, common.Name("a123456789aeee"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload3, nil)
action4 := types.NewAction(types.UpdateAccount, common.Name("a123456789addd"), common.Name(sysName), 1, 1, 2, big.NewInt(0), payload4, nil)
action5 := types.NewAction(types.UpdateAccountAuthor, common.Name("a123456789addd"), common.Name(sysName), 1, 1, 2, big.NewInt(0), payload5, nil)

//action5 := types.NewAction(types.DeleteAccount, common.Name("123asdf2"), common.Name("123asdf2"), 1, 1, 2, big.NewInt(0), pubkey1[:])
//action6 := types.NewAction(types.Transfer, common.Name("a123456789aeee"), common.Name("a123456789aeee"), 1, 1, 2, big.NewInt(1), pubkey1[:])
Expand Down Expand Up @@ -1637,7 +1636,7 @@ func TestAccountManager_Process(t *testing.T) {
if err != nil {
panic("rlp payload err")
}
action6 := types.NewAction(types.UpdateAccountAuthor, common.Name("a123456789addd"), common.Name(sysName), 1, 1, 2, big.NewInt(0), payload6)
action6 := types.NewAction(types.UpdateAccountAuthor, common.Name("a123456789addd"), common.Name(sysName), 1, 1, 2, big.NewInt(0), payload6, nil)

tests = []struct {
name string
Expand Down Expand Up @@ -1834,15 +1833,15 @@ func TestAccountManager_SubAccount(t *testing.T) {
panic("rlp payload err")
}

action := types.NewAction(types.CreateAccount, common.Name("a123456789aeee"), common.Name(sysName), 1, 1, 2, big.NewInt(40), payload)
action1 := types.NewAction(types.CreateAccount, common.Name("bbbbbbbb"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload1)
action2 := types.NewAction(types.CreateAccount, common.Name("bbbbbbbb"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload2)
action3 := types.NewAction(types.CreateAccount, common.Name("bbbbbbbb"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload3)
action4 := types.NewAction(types.CreateAccount, common.Name("bbbbbbbb"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload4)
action5 := types.NewAction(types.CreateAccount, common.Name("bbbbbbbb.cc"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload5)
action6 := types.NewAction(types.CreateAccount, common.Name("bbbbbbbb.ccc"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload6)
action7 := types.NewAction(types.CreateAccount, common.Name("a123456789aeee"), common.Name(sysName), 1, 1, 2, big.NewInt(30), payload7)
action8 := types.NewAction(types.CreateAccount, common.Name("cccccccc"), common.Name(sysName), 1, 1, 2, big.NewInt(30), payload8)
action := types.NewAction(types.CreateAccount, common.Name("a123456789aeee"), common.Name(sysName), 1, 1, 2, big.NewInt(40), payload, nil)
action1 := types.NewAction(types.CreateAccount, common.Name("bbbbbbbb"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload1, nil)
action2 := types.NewAction(types.CreateAccount, common.Name("bbbbbbbb"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload2, nil)
action3 := types.NewAction(types.CreateAccount, common.Name("bbbbbbbb"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload3, nil)
action4 := types.NewAction(types.CreateAccount, common.Name("bbbbbbbb"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload4, nil)
action5 := types.NewAction(types.CreateAccount, common.Name("bbbbbbbb.cc"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload5, nil)
action6 := types.NewAction(types.CreateAccount, common.Name("bbbbbbbb.ccc"), common.Name(sysName), 1, 1, 2, big.NewInt(10), payload6, nil)
action7 := types.NewAction(types.CreateAccount, common.Name("a123456789aeee"), common.Name(sysName), 1, 1, 2, big.NewInt(30), payload7, nil)
action8 := types.NewAction(types.CreateAccount, common.Name("cccccccc"), common.Name(sysName), 1, 1, 2, big.NewInt(30), payload8, nil)

tests := []struct {
name string
Expand Down
5 changes: 5 additions & 0 deletions blockchain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func (g *Genesis) ToBlock(db fdb.Database) (*types.Block, []*types.Receipt) {
0,
big.NewInt(0),
payload,
nil,
))

for _, account := range g.AllocAccounts {
Expand All @@ -247,6 +248,7 @@ func (g *Genesis) ToBlock(db fdb.Database) (*types.Block, []*types.Receipt) {
0,
big.NewInt(0),
payload,
nil,
))
}

Expand Down Expand Up @@ -292,6 +294,7 @@ func (g *Genesis) ToBlock(db fdb.Database) (*types.Block, []*types.Receipt) {
0,
big.NewInt(0),
payload,
nil,
))
}

Expand Down Expand Up @@ -384,6 +387,7 @@ func (g *Genesis) ToBlock(db fdb.Database) (*types.Block, []*types.Receipt) {
action.Gas(),
action.Value(),
action.Data(),
action.Remark(),
)
}
actions = append(actions, action)
Expand All @@ -399,6 +403,7 @@ func (g *Genesis) ToBlock(db fdb.Database) (*types.Block, []*types.Receipt) {
action.Gas(),
action.Value(),
action.Data(),
action.Remark(),
)
}
actions = append(actions, action)
Expand Down
6 changes: 3 additions & 3 deletions blockchain/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
memdb "github.com/fractalplatform/fractal/utils/fdb/memdb"
)

var defaultgenesisBlockHash = common.HexToHash("0x6a0ea8cecb572c40e8561eae6788d7b9a8fac93fc3e9c5bae91f047373ae9c2d")
var defaultgenesisBlockHash = common.HexToHash("0x689f0108f6b410790cef82548546ae699f8aa58268e5d210c18680d2b122ba3b")

func TestDefaultGenesisBlock(t *testing.T) {
block, _ := DefaultGenesis().ToBlock(nil)
Expand All @@ -43,15 +43,15 @@ func TestDefaultGenesisBlock(t *testing.T) {

func TestSetupGenesis(t *testing.T) {
var (
customghash = common.HexToHash("0x1824830151211dd8d1facd147ebfa2dc74136c265f254a2bdaf7dc150f00f40d")
customghash = common.HexToHash("61e8144f0467c1ec2a7419b69552c848e77eb56d7c7732529725152178b9a726")
customg = Genesis{
Config: params.DefaultChainconfig.Copy(),
AllocAccounts: DefaultGenesisAccounts(),
AllocAssets: DefaultGenesisAssets(),
AllocCandidates: DefaultGenesisCandidates(),
}
oldcustomg = customg
oldcustomghash = common.HexToHash("b8591bbdd232c4af673761ffc055488354c69b7c02e269ad1066f001c3174b4c")
oldcustomghash = common.HexToHash("21a416dd25124856ebda5c2b95ccdc7abb38c03e1337b9d4cedbd6448a60854b")
)
customg.Config.ChainID = big.NewInt(5)
oldcustomg.Config = customg.Config.Copy()
Expand Down
4 changes: 2 additions & 2 deletions blockchain/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func makeCandidatesTx(t *testing.T, from string, fromprikey *ecdsa.PrivateKey, s
var actions []*types.Action
for i := 0; i < len(getCandidates()); i++ {
amount := new(big.Int).Mul(delegateValue, big.NewInt(2))
action := types.NewAction(types.Transfer, common.StrToName(from), common.StrToName(getCandidates()[syscandidatePrefix+strconv.Itoa(i)].name), nonce, uint64(1), uint64(210000), amount, nil)
action := types.NewAction(types.Transfer, common.StrToName(from), common.StrToName(getCandidates()[syscandidatePrefix+strconv.Itoa(i)].name), nonce, uint64(1), uint64(210000), amount, nil, nil)
actions = append(actions, action)
nonce++
}
Expand All @@ -288,7 +288,7 @@ func makeCandidatesTx(t *testing.T, from string, fromprikey *ecdsa.PrivateKey, s
URL: url,
}
payload, _ := rlp.EncodeToBytes(arg)
action := types.NewAction(types.RegCandidate, common.StrToName(to.name), common.StrToName(params.DefaultChainconfig.DposName), 0, uint64(1), uint64(210000), delegateValue, payload)
action := types.NewAction(types.RegCandidate, common.StrToName(to.name), common.StrToName(params.DefaultChainconfig.DposName), 0, uint64(1), uint64(210000), delegateValue, payload, nil)
actions1 = append(actions1, action)
}

Expand Down
4 changes: 2 additions & 2 deletions consensus/dpos/dpos.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ func (s *stateDB) Delete(key string) error {
return nil
}
func (s *stateDB) Undelegate(to string, amount *big.Int) (*types.Action, error) {
action := types.NewAction(types.Transfer, common.StrToName(s.name), common.StrToName(to), 0, s.assetid, 0, amount, nil)
action := types.NewAction(types.Transfer, common.StrToName(s.name), common.StrToName(to), 0, s.assetid, 0, amount, nil, nil)
accountDB, err := accountmanager.NewAccountManager(s.state)
if err != nil {
return action, err
}
return action, accountDB.TransferAsset(common.StrToName(s.name), common.StrToName(to), s.assetid, amount)
}
func (s *stateDB) IncAsset2Acct(from string, to string, amount *big.Int) (*types.Action, error) {
action := types.NewAction(types.IncreaseAsset, common.StrToName(s.name), common.StrToName(to), 0, s.assetid, 0, amount, nil)
action := types.NewAction(types.IncreaseAsset, common.StrToName(s.name), common.StrToName(to), 0, s.assetid, 0, amount, nil, nil)
accountDB, err := accountmanager.NewAccountManager(s.state)
if err != nil {
return action, err
Expand Down
9 changes: 8 additions & 1 deletion processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package processor

import (
"fmt"

"github.com/ethereum/go-ethereum/log"
"github.com/fractalplatform/fractal/accountmanager"
"github.com/fractalplatform/fractal/common"
Expand Down Expand Up @@ -91,7 +93,12 @@ func (p *StateProcessor) ApplyTransaction(author *common.Name, gp *common.GasPoo
return nil, 0, err
}

assetID := tx.GasAssetID()
// todo for the moment,only system asset
// assetID := tx.GasAssetID()
assetID := p.bc.Config().SysTokenID
if assetID != tx.GasAssetID() {
return nil, 0, fmt.Errorf("only support system asset %d as tx fee", p.bc.Config().SysTokenID)
}
gasPrice := tx.GasPrice()

var totalGas uint64
Expand Down
16 changes: 8 additions & 8 deletions processor/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ func opCall(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Sta
gas += params.CallStipend
}

action := types.NewAction(types.CallContract, contract.Name(), toName, 0, evm.AssetID, gas, value, args)
action := types.NewAction(types.CallContract, contract.Name(), toName, 0, evm.AssetID, gas, value, args, nil)

ret, returnGas, err := evm.Call(contract, action, gas)
if err != nil {
Expand Down Expand Up @@ -931,7 +931,7 @@ func opCallCode(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack
gas += params.CallStipend
}
// todo
action := types.NewAction(types.CallContract, contract.Name(), toName, 0, evm.AssetID, gas, value, args)
action := types.NewAction(types.CallContract, contract.Name(), toName, 0, evm.AssetID, gas, value, args, nil)

ret, returnGas, err := evm.CallCode(contract, action, gas)
if err != nil {
Expand Down Expand Up @@ -1027,7 +1027,7 @@ func execAddAsset(evm *EVM, contract *Contract, assetID uint64, toName common.Na
return err
}

action := types.NewAction(types.IncreaseAsset, contract.Name(), common.Name(evm.chainConfig.AssetName), 0, evm.chainConfig.SysTokenID, 0, big.NewInt(0), b)
action := types.NewAction(types.IncreaseAsset, contract.Name(), common.Name(evm.chainConfig.AssetName), 0, evm.chainConfig.SysTokenID, 0, big.NewInt(0), b, nil)

internalActions, err := evm.AccountDB.Process(&types.AccountManagerContext{
Action: action,
Expand Down Expand Up @@ -1055,7 +1055,7 @@ func opDestroyAsset(pc *uint64, evm *EVM, contract *Contract, memory *Memory, st
value, assetID := stack.pop(), stack.pop()
astID := assetID.Uint64()

action := types.NewAction(types.DestroyAsset, contract.Name(), common.Name(evm.chainConfig.AssetName), 0, astID, 0, value, nil)
action := types.NewAction(types.DestroyAsset, contract.Name(), common.Name(evm.chainConfig.AssetName), 0, astID, 0, value, nil, nil)

internalActions, err := evm.AccountDB.Process(&types.AccountManagerContext{
Action: action,
Expand Down Expand Up @@ -1237,7 +1237,7 @@ func executeIssuseAsset(evm *EVM, contract *Contract, desc string) (uint64, erro
if err != nil {
return 0, err
}
action := types.NewAction(types.IssueAsset, contract.Name(), common.Name(evm.chainConfig.AssetName), 0, evm.chainConfig.SysTokenID, 0, big.NewInt(0), b)
action := types.NewAction(types.IssueAsset, contract.Name(), common.Name(evm.chainConfig.AssetName), 0, evm.chainConfig.SysTokenID, 0, big.NewInt(0), b, nil)

internalActions, err := evm.AccountDB.Process(&types.AccountManagerContext{
Action: action,
Expand Down Expand Up @@ -1299,7 +1299,7 @@ func execSetAssetOwner(evm *EVM, contract *Contract, assetID uint64, owner commo
return err
}

action := types.NewAction(types.SetAssetOwner, contract.Name(), common.Name(evm.chainConfig.AssetName), 0, evm.chainConfig.SysTokenID, 0, big.NewInt(0), b)
action := types.NewAction(types.SetAssetOwner, contract.Name(), common.Name(evm.chainConfig.AssetName), 0, evm.chainConfig.SysTokenID, 0, big.NewInt(0), b, nil)
internalActions, err := evm.AccountDB.Process(&types.AccountManagerContext{
Action: action,
Number: evm.Context.BlockNumber.Uint64(),
Expand Down Expand Up @@ -1375,7 +1375,7 @@ func execWithdrawFee(evm *EVM, contract *Contract, withdrawTo common.Name, objec
return errEnc
}

action := types.NewAction(types.WithdrawFee, common.Name(evm.chainConfig.FeeName), withdrawInfo.Founder, 0, 0, 0, big.NewInt(0), paload)
action := types.NewAction(types.WithdrawFee, common.Name(evm.chainConfig.FeeName), withdrawInfo.Founder, 0, 0, 0, big.NewInt(0), paload, nil)
internalAction := &types.InternalAction{Action: action.NewRPCAction(0), ActionType: "withdrawfee", GasUsed: 0, GasLimit: contract.Gas, Depth: uint64(evm.depth), Error: errmsg}
evm.InternalTxs = append(evm.InternalTxs, internalAction)
}
Expand All @@ -1398,7 +1398,7 @@ func opCallEx(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *S
assetID := assetId.Uint64()
value = math.U256(value)

action := types.NewAction(types.CallContract, contract.Name(), toName, 0, assetID, 0, value, nil)
action := types.NewAction(types.CallContract, contract.Name(), toName, 0, assetID, 0, value, nil, nil)

err = evm.AccountDB.TransferAsset(action.Sender(), action.Recipient(), action.AssetID(), action.Value())

Expand Down
2 changes: 1 addition & 1 deletion processor/vm/runtime/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestRunCode(t *testing.T) {
return
}

action = types.NewAction(types.Transfer, runtimeConfig.Origin, receiverName, 0, runtimeConfig.AssetID, runtimeConfig.GasLimit, runtimeConfig.Value, myInput)
action = types.NewAction(types.Transfer, runtimeConfig.Origin, receiverName, 0, runtimeConfig.AssetID, runtimeConfig.GasLimit, runtimeConfig.Value, myInput, nil)

ret, _, err := Call(action, &runtimeConfig)
if err != nil {
Expand Down

0 comments on commit e375cf8

Please sign in to comment.