Skip to content

Commit

Permalink
Merge pull request #8 from moonstream-to/fix-updated-db-call-requests
Browse files Browse the repository at this point in the history
Call request id to work with updated backend and show expired flag
  • Loading branch information
zomglings authored Aug 10, 2023
2 parents 5e26230 + 0074c2c commit fcfca9b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
10 changes: 6 additions & 4 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ func CreateMoonstreamCommand() *cobra.Command {

var blockchain, address, contractType, contractId, contractAddress, infile string
var limit, offset, batchSize int
var showExpired bool

contractsSubcommand := &cobra.Command{
Use: "contracts",
Expand Down Expand Up @@ -427,7 +428,7 @@ func CreateMoonstreamCommand() *cobra.Command {
return clientErr
}

callRequests, err := client.ListCallRequests(contractId, contractAddress, address, limit, offset)
callRequests, err := client.ListCallRequests(contractId, contractAddress, address, limit, offset, showExpired)
if err != nil {
return err
}
Expand All @@ -441,6 +442,7 @@ func CreateMoonstreamCommand() *cobra.Command {
callRequestsSubcommand.Flags().StringVar(&address, "caller", "", "Address of caller")
callRequestsSubcommand.Flags().IntVar(&limit, "limit", 100, "Limit")
callRequestsSubcommand.Flags().IntVar(&offset, "offset", 0, "Offset")
callRequestsSubcommand.Flags().BoolVar(&showExpired, "show-expired", false, "Specify this flag to show expired call requests")

createCallRequestsSubcommand := &cobra.Command{
Use: "drop",
Expand Down Expand Up @@ -475,11 +477,11 @@ func CreateMoonstreamCommand() *cobra.Command {
callRequests := make([]CallRequestSpecification, len(messages))
for i, message := range messages {
callRequests[i] = CallRequestSpecification{
Caller: message.Claimant,
Method: "claim",
Caller: message.Claimant,
Method: "claim",
RequestId: message.RequestID,
Parameters: DropperCallRequestParameters{
DropId: message.DropId,
RequestID: message.RequestID,
BlockDeadline: message.BlockDeadline,
Amount: message.Amount,
Signer: message.Signer,
Expand Down
48 changes: 25 additions & 23 deletions moonstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,36 @@ import (
)

type RegisteredContract struct {
Id string `json:"id"`
Blockchain string `json:"blockchain"`
Address string `json:"address"`
ContractType string `json:"contract_type"`
MoonstreamUserId string `json:"moonstream_user_id"`
Title string `json:"title"`
Description string `json:"description"`
ImageURI string `json:"image_uri"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Id string `json:"id"`
Blockchain string `json:"blockchain"`
Address string `json:"address"`
MetatxRequesterId string `json:"metatx_requester_id"`
Title string `json:"title"`
Description string `json:"description"`
ImageURI string `json:"image_uri"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

type CallRequest struct {
Id string `json:"id"`
ContractId string `json:"contract_id"`
ContractAddress string `json:"contract_address"`
MoonstreamUserId string `json:"moonstream_user_id"`
Caller string `json:"caller"`
Method string `json:"method"`
Parameters interface{} `json:"parameters"`
ExpiresAt time.Time `json:"expires_at"`
CreatedAt time.Time `json:"created_at"`
UpdateAt time.Time `json:"updated_at"`
Id string `json:"id"`
ContractId string `json:"contract_id"`
ContractAddress string `json:"contract_address"`
MetatxRequesterId string `json:"metatx_requester_id"`
CallRequestType string `json:"call_request_type"`
Caller string `json:"caller"`
Method string `json:"method"`
RequestId string `json:"request_id"`
Parameters interface{} `json:"parameters"`
ExpiresAt time.Time `json:"expires_at"`
CreatedAt time.Time `json:"created_at"`
UpdateAt time.Time `json:"updated_at"`
}

type CallRequestSpecification struct {
Caller string `json:"caller"`
Method string `json:"method"`
RequestId string `json:"request_id"`
Parameters interface{} `json:"parameters"`
}

Expand All @@ -51,7 +53,6 @@ type CreateCallRequestsRequest struct {

type DropperCallRequestParameters struct {
DropId string `json:"dropId"`
RequestID string `json:"requestID"`
BlockDeadline string `json:"blockDeadline"`
Amount string `json:"amount"`
Signer string `json:"signer"`
Expand Down Expand Up @@ -142,11 +143,11 @@ func (client *MoonstreamEngineAPIClient) ListRegisteredContracts(blockchain, add
return contracts, nil
}

func (client *MoonstreamEngineAPIClient) ListCallRequests(contractId, contractAddress, caller string, limit, offset int) ([]CallRequest, error) {
func (client *MoonstreamEngineAPIClient) ListCallRequests(contractId, contractAddress, caller string, limit, offset int, showExpired bool) ([]CallRequest, error) {
var callRequests []CallRequest

if caller == "" {
return callRequests, fmt.Errorf("You must specify caller when listing call requests")
return callRequests, fmt.Errorf("you must specify caller when listing call requests")
}

request, requestCreationErr := http.NewRequest("GET", fmt.Sprintf("%s/metatx/requests", client.BaseURL), nil)
Expand All @@ -167,6 +168,7 @@ func (client *MoonstreamEngineAPIClient) ListCallRequests(contractId, contractAd
queryParameters.Add("caller", caller)
queryParameters.Add("limit", strconv.Itoa(limit))
queryParameters.Add("offset", strconv.Itoa(offset))
queryParameters.Add("show_expired", strconv.FormatBool(showExpired))

request.URL.RawQuery = queryParameters.Encode()

Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

var WAGGLE_VERSION string = "0.0.7"
var WAGGLE_VERSION string = "0.0.8"

0 comments on commit fcfca9b

Please sign in to comment.