-
Notifications
You must be signed in to change notification settings - Fork 0
/
rosetta_construction_hash_request.go
50 lines (44 loc) · 1.75 KB
/
rosetta_construction_hash_request.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
package models
import (
"encoding/json"
)
// RosettaConstructionHashRequest represents a RosettaConstructionHashRequest struct.
// TransactionHash returns the network-specific transaction hash for a signed transaction.
type RosettaConstructionHashRequest struct {
// The network_identifier specifies which network a particular object is associated with.
NetworkIdentifier NetworkIdentifier `json:"network_identifier"`
// Signed transaction
SignedTransaction string `json:"signed_transaction"`
}
// MarshalJSON implements the json.Marshaler interface for RosettaConstructionHashRequest.
// It customizes the JSON marshaling process for RosettaConstructionHashRequest objects.
func (r *RosettaConstructionHashRequest) MarshalJSON() (
[]byte,
error) {
return json.Marshal(r.toMap())
}
// toMap converts the RosettaConstructionHashRequest object to a map representation for JSON marshaling.
func (r *RosettaConstructionHashRequest) toMap() map[string]any {
structMap := make(map[string]any)
structMap["network_identifier"] = r.NetworkIdentifier
structMap["signed_transaction"] = r.SignedTransaction
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for RosettaConstructionHashRequest.
// It customizes the JSON unmarshaling process for RosettaConstructionHashRequest objects.
func (r *RosettaConstructionHashRequest) UnmarshalJSON(input []byte) error {
if input[0] == '"' {
return unmarshalResponseString(input)
}
temp := &struct {
NetworkIdentifier NetworkIdentifier `json:"network_identifier"`
SignedTransaction string `json:"signed_transaction"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
r.NetworkIdentifier = temp.NetworkIdentifier
r.SignedTransaction = temp.SignedTransaction
return nil
}