Skip to content

Commit

Permalink
Fill in methodName and mapResponse in QueryBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
mehcode committed Jan 12, 2020
1 parent 4b3f546 commit bd81824
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
72 changes: 72 additions & 0 deletions query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,25 +161,97 @@ func (builder *QueryBuilder) isPaymentRequired() bool {

func methodName(pb *proto.Query) string {
switch pb.Query.(type) {
// Crypto

case *proto.Query_TransactionGetReceipt:
return "/proto.CryptoService/getTransactionReceipts"

case *proto.Query_CryptogetAccountBalance:
return "/proto.CryptoService/cryptoGetBalance"

case *proto.Query_CryptoGetAccountRecords:
return "/proto.CryptoService/getAccountRecords"

case *proto.Query_CryptoGetInfo:
return "/proto.CryptoService/getAccountInfo"

case *proto.Query_TransactionGetRecord:
return "/proto.CryptoService/getTxRecordByTxID"

case *proto.Query_CryptoGetProxyStakers:
return "/proto.CryptoService/getStakersByAccountID"

// Smart Contracts

case *proto.Query_ContractCallLocal:
return "/proto.SmartContractService/contractCallLocalMethod"

case *proto.Query_ContractGetBytecode:
return "/proto.SmartContractService/ContractGetBytecode"

case *proto.Query_ContractGetInfo:
return "/proto.SmartContractService/getContractInfo"

case *proto.Query_ContractGetRecords:
return "/proto.SmartContractService/getTxRecordByContractID"

// File

case *proto.Query_FileGetContents:
return "/proto.FileService/getFileContent"

case *proto.Query_FileGetInfo:
return "/proto.FileService/getFileInfo"

default:
panic(fmt.Sprintf("[methodName] not implemented: %T", pb.Query))
}
}

func mapResponseHeader(resp *proto.Response) *proto.ResponseHeader {
switch resp.Response.(type) {
// Crypto

case *proto.Response_TransactionGetReceipt:
return resp.GetTransactionGetReceipt().Header

case *proto.Response_CryptogetAccountBalance:
return resp.GetCryptogetAccountBalance().Header

case *proto.Response_CryptoGetAccountRecords:
return resp.GetCryptoGetAccountRecords().Header

case *proto.Response_CryptoGetInfo:
return resp.GetCryptoGetInfo().Header

case *proto.Response_TransactionGetRecord:
return resp.GetTransactionGetRecord().Header

case *proto.Response_CryptoGetProxyStakers:
return resp.GetCryptoGetProxyStakers().Header

// Smart Contracts

case *proto.Response_ContractCallLocal:
return resp.GetContractCallLocal().Header

case *proto.Response_ContractGetBytecodeResponse:
return resp.GetContractGetBytecodeResponse().Header

case *proto.Response_ContractGetInfo:
return resp.GetContractGetInfo().Header

case *proto.Response_ContractGetRecordsResponse:
return resp.GetContractGetRecordsResponse().Header

// File

case *proto.Response_FileGetContents:
return resp.GetFileGetContents().Header

case *proto.Response_FileGetInfo:
return resp.GetFileGetInfo().Header

default:
panic(fmt.Sprintf("[mapResponseHeader] not implemented: %T", resp.Response))
}
Expand Down
1 change: 0 additions & 1 deletion transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func (transaction Transaction) Execute(client *Client) (TransactionID, error) {

var methodName string

// TODO: Add the rest of the types here
switch transactionBody.Data.(type) {
case *proto.TransactionBody_CryptoCreateAccount:
methodName = "/proto.CryptoService/createAccount"
Expand Down

0 comments on commit bd81824

Please sign in to comment.