forked from libsv/go-bc
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmapi_callback.go
More file actions
35 lines (31 loc) · 1.2 KB
/
mapi_callback.go
File metadata and controls
35 lines (31 loc) · 1.2 KB
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
package bc
import (
"encoding/json"
)
// MapiCallback is the body contents posted to the provided callback url from Merchant API.
type MapiCallback struct {
CallbackPayload string `json:"callbackPayload"`
APIVersion string `json:"apiVersion"`
Timestamp string `json:"timestamp"`
MinerID string `json:"minerId"`
BlockHash string `json:"blockHash"`
BlockHeight uint64 `json:"blockHeight"`
CallbackTxID string `json:"callbackTxId"`
CallbackReason string `json:"callbackReason"`
}
// NewMapiCallbackFromBytes is a glorified JSON unmarshaller, but might be more sophisticated in the future.
func NewMapiCallbackFromBytes(b []byte) (*MapiCallback, error) {
var mapiCallback MapiCallback
err := json.Unmarshal(b, &mapiCallback)
if err != nil {
return nil, err
}
return &mapiCallback, nil
}
// Bytes convert the MapiCallback struct into a binary format.
// We are not going to parse anything out but rather take the whole JSON object as a binary blob.
// The reason behind this approach is that the mapi server signs the whole callback,
// so if a single byte is out of place, the signature will be invalid.
func (mcb *MapiCallback) Bytes() ([]byte, error) {
return json.Marshal(mcb)
}