-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseSingleDCTTransfer.go
40 lines (31 loc) · 1.36 KB
/
parseSingleDCTTransfer.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
package datafield
import (
"github.com/kalyan3104/k-core/core"
vmcommon "github.com/kalyan3104/k-vm-common-go"
)
func (odp *operationDataFieldParser) parseSingleDCTTransfer(args [][]byte, function string, sender, receiver []byte) *ResponseParseData {
responseParse, parsedDCTTransfers, ok := odp.extractDCTData(args, function, sender, receiver)
if !ok {
return responseParse
}
if core.IsSmartContractAddress(receiver) && isASCIIString(parsedDCTTransfers.CallFunction) {
responseParse.Function = parsedDCTTransfers.CallFunction
}
if len(parsedDCTTransfers.DCTTransfers) == 0 || !isASCIIString(string(parsedDCTTransfers.DCTTransfers[0].DCTTokenName)) {
return responseParse
}
firstTransfer := parsedDCTTransfers.DCTTransfers[0]
responseParse.Tokens = append(responseParse.Tokens, string(firstTransfer.DCTTokenName))
responseParse.DCTValues = append(responseParse.DCTValues, firstTransfer.DCTValue.String())
return responseParse
}
func (odp *operationDataFieldParser) extractDCTData(args [][]byte, function string, sender, receiver []byte) (*ResponseParseData, *vmcommon.ParsedDCTTransfers, bool) {
responseParse := &ResponseParseData{
Operation: function,
}
parsedDCTTransfers, err := odp.dctTransferParser.ParseDCTTransfers(sender, receiver, function, args)
if err != nil {
return responseParse, nil, false
}
return responseParse, parsedDCTTransfers, true
}