/
blocklog_processor_iotrx_changes.go
130 lines (123 loc) · 4.83 KB
/
blocklog_processor_iotrx_changes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package plugins
import (
"encoding/json"
"errors"
"github.com/coschain/contentos-go/app/blocklog"
"github.com/coschain/contentos-go/common"
"github.com/coschain/contentos-go/iservices"
"github.com/coschain/contentos-go/prototype"
)
func ProcessContractTransferToUserChangeProcessor(opType string, operation prototype.BaseOperation, change *blocklog.StateChange, baseRecord interface{}) ([]interface{}, error) {
if opType != "contract_apply" || change.What != "Account.Balance" {
return nil, nil
}
op, ok := operation.(*prototype.ContractApplyOperation)
if !ok {
return nil, errors.New("failed conversion to ContractApplyOperation")
}
if change.Cause == "contract_apply.vm_native.transfer_to_user"{
before := common.JsonNumberUint64(change.Change.Before.(json.Number))
after := common.JsonNumberUint64(change.Change.After.(json.Number))
owner := op.GetOwner().GetValue()
contract := op.GetContract()
contractName := owner + "@" + contract
userName := change.Change.Id.(string)
ioTrx := baseRecord.(iservices.IOTrxRecord)
ioTrx.From = contractName
ioTrx.To = userName
ioTrx.Action = "contract_transfer_to_user"
ioTrx.Amount = after - before
return []interface{}{ioTrx}, nil
}
return nil, nil
}
func ProcessContractTransferToUserVestChangeProcessor(opType string, operation prototype.BaseOperation, change *blocklog.StateChange, baseRecord interface{}) ([]interface{}, error) {
if opType != "contract_apply" || change.What != "Account.Vest" {
return nil, nil
}
op, ok := operation.(*prototype.ContractApplyOperation)
if !ok {
return nil, errors.New("failed conversion to ContractApplyOperation")
}
if change.Cause == "contract_apply.vm_native.transfer_to_user_vest"{
before := common.JsonNumberUint64(change.Change.Before.(json.Number))
after := common.JsonNumberUint64(change.Change.After.(json.Number))
owner := op.GetOwner().GetValue()
contract := op.GetContract()
contractName := owner + "@" + contract
userName := change.Change.Id.(string)
ioTrx := baseRecord.(iservices.IOTrxRecord)
ioTrx.From = contractName
ioTrx.To = userName
ioTrx.Action = "contract_transfer_vest_to_user"
ioTrx.Amount = after - before
return []interface{}{ioTrx}, nil
}
return nil, nil
}
func ProcessUserToContractChangeProcessor(opType string, operation prototype.BaseOperation, change *blocklog.StateChange, baseRecord interface{}) ([]interface{}, error) {
if opType != "contract_apply" || change.What != "Account.Balance" {
return nil, nil
}
op, ok := operation.(*prototype.ContractApplyOperation)
if !ok {
return nil, errors.New("failed conversion to ContractApplyOperation")
}
if change.Cause == "contract_apply.u2c"{
owner := op.GetOwner().GetValue()
contract := op.GetContract()
contractName := owner + "@" + contract
userName := change.Change.Id.(string)
ioTrx := baseRecord.(iservices.IOTrxRecord)
ioTrx.From = userName
ioTrx.To = contractName
ioTrx.Action = "user_transfer_to_contract"
ioTrx.Amount = op.GetAmount().GetValue()
return []interface{}{ioTrx}, nil
}
return nil, nil
}
func ProcessContractTransferToContractChangeProcessor(opType string, operation prototype.BaseOperation, change *blocklog.StateChange, baseRecord interface{}) ([]interface{}, error) {
if opType != "contract_apply" || change.What != "Contract.Balance" {
return nil, nil
}
op, ok := operation.(*prototype.ContractApplyOperation)
if !ok {
return nil, errors.New("failed conversion to ContractApplyOperation")
}
if change.Cause == "contract_apply.vm_native.transfer_to_contract"{
owner := op.GetOwner().GetValue()
contract := op.GetContract()
fromContractName := owner + "@" + contract
toContractName := change.Change.Id.(string)
ioTrx := baseRecord.(iservices.IOTrxRecord)
if fromContractName != toContractName {
before := common.JsonNumberUint64(change.Change.Before.(json.Number))
after := common.JsonNumberUint64(change.Change.After.(json.Number))
ioTrx.From = fromContractName
ioTrx.To = toContractName
ioTrx.Action = "contract_transfer_to_contract"
ioTrx.Amount = after - before
return []interface{}{ioTrx}, nil
}
return nil, nil
}
return nil, nil
}
func ProcessUnDelegateVestChangeProcessor(opType string, operation prototype.BaseOperation, change *blocklog.StateChange, baseRecord interface{}) ([]interface{}, error) {
if opType != "un_delegate_vest" || change.What != "Account.BorrowedVest" {
return nil, nil
}
op, ok := operation.(*prototype.UnDelegateVestOperation)
if !ok {
return nil, errors.New("failed conversion to UnDelegateVestOperation")
}
borrower := change.Change.Id.(string)
before := common.JsonNumberUint64(change.Change.Before.(json.Number))
after := common.JsonNumberUint64(change.Change.After.(json.Number))
ioTrx := baseRecord.(iservices.IOTrxRecord)
ioTrx.From = op.GetAccount().GetValue()
ioTrx.To = borrower
ioTrx.Amount = before - after
return []interface{}{ioTrx}, nil
}