Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
klim0v committed Nov 10, 2020
1 parent 24aa144 commit 2c62af3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
4 changes: 2 additions & 2 deletions api/http_client/models/protobuf_any_edited.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 28 additions & 26 deletions api/http_client/models/transaction_response_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,27 +125,27 @@ type EditCandidatePublicKeyData struct {
NewPubKey string `json:"new_pub_key,omitempty"`
}

var data = map[uint64]Data{
1: &SendData{},
2: &SellCoinData{},
3: &SellAllCoinData{},
4: &BuyCoinData{},
5: &CreateCoinData{},
6: &DeclareCandidacyData{},
7: &DelegateData{},
8: &UnbondData{},
9: &RedeemCheckData{},
10: &SetCandidateOnData{},
11: &SetCandidateOffData{},
12: &CreateMultisigData{},
13: &MultiSendData{},
14: &EditCandidateData{},
15: &SetHaltBlockData{},
16: &RecreateCoinData{},
17: &EditCoinOwnerData{},
18: &EditMultisigData{},
19: &PriceVoteData{},
20: &EditCandidatePublicKeyData{},
var data = map[string]Data{
"type.googleapis.com/api_pb.SendData": &SendData{},
"type.googleapis.com/api_pb.SellCoinData": &SellCoinData{},
"type.googleapis.com/api_pb.SellAllCoinData": &SellAllCoinData{},
"type.googleapis.com/api_pb.BuyCoinData": &BuyCoinData{},
"type.googleapis.com/api_pb.CreateCoinData": &CreateCoinData{},
"type.googleapis.com/api_pb.DeclareCandidacyData": &DeclareCandidacyData{},
"type.googleapis.com/api_pb.DelegateData": &DelegateData{},
"type.googleapis.com/api_pb.UnbondData": &UnbondData{},
"type.googleapis.com/api_pb.RedeemCheckData": &RedeemCheckData{},
"type.googleapis.com/api_pb.SetCandidateOnData": &SetCandidateOnData{},
"type.googleapis.com/api_pb.SetCandidateOffData": &SetCandidateOffData{},
"type.googleapis.com/api_pb.CreateMultisigData": &CreateMultisigData{},
"type.googleapis.com/api_pb.MultiSendData": &MultiSendData{},
"type.googleapis.com/api_pb.EditCandidateData": &EditCandidateData{},
"type.googleapis.com/api_pb.SetHaltBlockData": &SetHaltBlockData{},
"type.googleapis.com/api_pb.RecreateCoinData": &RecreateCoinData{},
"type.googleapis.com/api_pb.EditCoinOwnerData": &EditCoinOwnerData{},
"type.googleapis.com/api_pb.EditMultisigData": &EditMultisigData{},
"type.googleapis.com/api_pb.PriceVoteData": &PriceVoteData{},
"type.googleapis.com/api_pb.EditCandidatePublicKeyData": &EditCandidatePublicKeyData{},
}

func (e *SendData) clone() Data {
Expand Down Expand Up @@ -229,14 +229,16 @@ func (e *EditCandidatePublicKeyData) clone() Data {
return &c
}

// ConvertToData returns Transaction Data model
func ConvertToData(t uint64, value *ProtobufAny) (Data, error) {
eventStruct, ok := data[t]
// convertToData returns Transaction Data model
func convertToData(value *ProtobufAny) (Data, error) {
var v map[string]interface{} = *value
t := v["@type"].(string)
data, ok := data[t]
if !ok {
return nil, fmt.Errorf("data type unknown: %d", t)
return nil, fmt.Errorf("data type unknown: %s", t)
}

clone := eventStruct.clone()
clone := data.clone()
err := value.UnmarshalTo(clone)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import (
"github.com/MinterTeam/minter-go-sdk/v2/api/http_client/models"
)

func ExampleConvertToData() {
func ExampleProtobufAny_UnmarshalNew() {
transactionResponse := models.TransactionResponse{
Type: 18,
Data: &models.ProtobufAny{
"@type": "type.googleapis.com/api_pb.EditMultisigData",
"threshold": "5",
"weights": []string{"1", "2", "3"},
"addresses": []string{"Mx0", "Mx1", "Mx2"},
},
}
data, _ := models.ConvertToData(transactionResponse.Type, transactionResponse.Data)
data, _ := transactionResponse.Data.UnmarshalNew()
editMultisigData := data.(*models.EditMultisigData)

fmt.Printf("%T %[1]v\n", editMultisigData.Threshold)
Expand Down

0 comments on commit 2c62af3

Please sign in to comment.