-
Notifications
You must be signed in to change notification settings - Fork 1
/
onchain_feeds.go
62 lines (55 loc) · 1.72 KB
/
onchain_feeds.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
package jobs
import (
"github.com/Crossbell-Box/OperatorSync/app/worker/global"
"github.com/Crossbell-Box/OperatorSync/app/worker/utils"
commonTypes "github.com/Crossbell-Box/OperatorSync/common/types"
)
func OnChainNotes(workDispatched *commonTypes.OnChainRequest, response *commonTypes.OnChainResponse) {
global.Logger.Debug("New OnChain request received: ", workDispatched)
// Process request
ipfsUri, tx, characterId, noteId, err := utils.FeedOnChain(workDispatched)
if err != nil {
global.Logger.Error("Unable to finish OnChain request: ", workDispatched)
OnChainHandleFailed(workDispatched.Platform, workDispatched.FeedID, err.Error(), response)
} else {
OnChainHandleSucceed(workDispatched.Platform, workDispatched.FeedID, ipfsUri, tx, characterId, noteId, response)
}
}
func OnChainHandleSucceed(platform string, feedID uint, ipfsUri string, transaction string, characterId int64, noteId int64, response *commonTypes.OnChainResponse) {
OnChainHandleResponse(
true,
platform,
feedID,
ipfsUri,
transaction,
characterId,
noteId,
"",
response,
)
}
func OnChainHandleFailed(platform string, feedID uint, errMsg string, response *commonTypes.OnChainResponse) {
OnChainHandleResponse(
false,
platform,
feedID,
"",
"",
0,
0,
errMsg,
response,
)
}
func OnChainHandleResponse(isSucceeded bool, platform string, feedID uint, ipfsUri string, transaction string, characterId int64, noteId int64, errMsg string, response *commonTypes.OnChainResponse) {
*response = commonTypes.OnChainResponse{
IsSucceeded: isSucceeded,
Platform: platform,
FeedID: feedID,
IPFSUri: ipfsUri,
Transaction: transaction,
CharacterID: characterId,
NoteID: noteId,
Message: errMsg,
}
}