Skip to content

Commit

Permalink
parent sign
Browse files Browse the repository at this point in the history
  • Loading branch information
Musiczombie committed Dec 9, 2019
1 parent 46f0fe4 commit b23a119
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 34 deletions.
2 changes: 2 additions & 0 deletions mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ CREATE TABLE IF NOT EXISTS actions_hash (
gas_used BIGINT NOT NULL,
payer VARCHAR(100),
payer_gas_price VARCHAR(1000),
parent_signer VARCHAR(100),
payer_parent_signer VARCHAR(100),
state ENUM('0', '1') NOT NULL,
error_msg longtext,
remark BLOB,
Expand Down
65 changes: 45 additions & 20 deletions task/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,52 @@ func (a *ActionTask) analysisAction(data *types.BlockAndResult, dbTx *sql.Tx) er
internalCount = len(internalTxs[i].InternalActions[j].InternalLogs)
}
}
getSigner := func(account, substr string, index uint64) string {
var singer string
if index <= 0 {
return singer
}
cnt := strings.IndexAny(account, substr)
if index > uint64(cnt) {
return singer
}
for i := uint64(0); i < index; i++ {
lastIndex := strings.LastIndex(account, ".")
account = string([]byte(account)[:lastIndex])
}
singer = account
return singer
}
var parentSinger, payerParentSigner string
if action.ParentIndex > 0 {
parentSinger = getSigner(action.From.String(), ".", action.ParentIndex)
}
if action.Payer != "" && action.PayerParentIndex > 0 {
payerParentSigner = getSigner(action.Payer.String(), ".", action.PayerParentIndex)
}
mAction := &db.MysqlAction{
TxHash: tx.Hash.String(),
ActionHash: action.ActionHash.String(),
ActionIndex: j,
Nonce: action.Nonce,
Height: block.Number.Uint64(),
Created: block.Time,
GasAssetId: tx.GasAssetID,
TransferAssetId: action.AssetID,
ActionType: uint64(action.Type),
From: action.From.String(),
To: action.To.String(),
Amount: action.Amount,
GasLimit: action.GasLimit,
GasUsed: actionResult.GasUsed,
State: actionResult.Status,
ErrorMsg: actionResult.Error,
Remark: []byte(fmt.Sprintf("%s", []byte(action.Remark))),
InternalCount: internalCount,
Payer: action.Payer.String(),
PayerGasPrice: action.PayerGasPrice,
TxHash: tx.Hash.String(),
ActionHash: action.ActionHash.String(),
ActionIndex: j,
Nonce: action.Nonce,
Height: block.Number.Uint64(),
Created: block.Time,
GasAssetId: tx.GasAssetID,
TransferAssetId: action.AssetID,
ActionType: uint64(action.Type),
From: action.From.String(),
To: action.To.String(),
Amount: action.Amount,
GasLimit: action.GasLimit,
GasUsed: actionResult.GasUsed,
State: actionResult.Status,
ErrorMsg: actionResult.Error,
Remark: []byte(fmt.Sprintf("%s", []byte(action.Remark))),
InternalCount: internalCount,
Payer: action.Payer.String(),
PayerGasPrice: action.PayerGasPrice,
ParentSigner: parentSinger,
PayerParentSigner: payerParentSigner,
}
parsedPayload, err := parsePayload(action)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion task/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ func (f *FeeTask) analysisFeeAction(data *types.BlockAndResult, dbTx *sql.Tx) er
gasPrice := big.NewInt(0).Set(tx.GasPrice)
for j, aRs := range receipt.ActionResults {
at := tx.RPCActions[j]
feeFrom := at.From.String()
for k, aR := range aRs.GasAllot {
if tx.GasPrice.Cmp(bigZero) == 0 {
if at.PayerGasPrice != nil {
gasPrice.Set(at.PayerGasPrice)
feeFrom = at.Payer.String()
}
}
fee := big.NewInt(0).Mul(big.NewInt(int64(aR.Gas)), gasPrice)
Expand All @@ -56,7 +58,7 @@ func (f *FeeTask) analysisFeeAction(data *types.BlockAndResult, dbTx *sql.Tx) er
Height: data.Block.Number.Uint64(),
Created: data.Block.Time,
AssetId: tx.GasAssetID,
From: at.From.String(),
From: feeFrom,
To: aR.Account.String(),
Amount: fee,
Reason: aR.Reason,
Expand Down
28 changes: 15 additions & 13 deletions types/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,19 @@ var ActionTypeToString map[ActionType]string = map[ActionType]string{
}

type RPCAction struct {
Type ActionType `json:"type"`
Nonce uint64 `json:"nonce"`
From Name `json:"from"`
To Name `json:"to"`
AssetID uint64 `json:"assetID"`
GasLimit uint64 `json:"gas"`
Amount *big.Int `json:"value"`
Remark hexutil.Bytes `json:"remark"`
Payload hexutil.Bytes `json:"payload"`
ActionHash Hash `json:"actionHash"`
ActionIndex uint64 `json:"actionIndex"`
Payer Name `json:"payer"`
PayerGasPrice *big.Int `json:"payerGasPrice"`
Type ActionType `json:"type"`
Nonce uint64 `json:"nonce"`
From Name `json:"from"`
To Name `json:"to"`
AssetID uint64 `json:"assetID"`
GasLimit uint64 `json:"gas"`
Amount *big.Int `json:"value"`
Remark hexutil.Bytes `json:"remark"`
Payload hexutil.Bytes `json:"payload"`
ActionHash Hash `json:"actionHash"`
ActionIndex uint64 `json:"actionIndex"`
Payer Name `json:"payer"`
PayerGasPrice *big.Int `json:"payerGasPrice"`
ParentIndex uint64 `json:"parentIndex"`
PayerParentIndex uint64 `json:"payerParentIndex"`
}

0 comments on commit b23a119

Please sign in to comment.