Skip to content

Commit

Permalink
Merge pull request #14 from coinbase/main-1712610488
Browse files Browse the repository at this point in the history
v0.4.0 Release
  • Loading branch information
drohit-cb authored Apr 8, 2024
2 parents 8ffd128 + 2e95f62 commit 19ae468
Show file tree
Hide file tree
Showing 16 changed files with 454 additions and 306 deletions.
4 changes: 0 additions & 4 deletions client/orchestration/v1/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ func WorkflowFinished(workflow *stakingpb.Workflow) bool {
workflow.State == stakingpb.Workflow_STATE_FAILED
}

func WorkflowWaitingForSigning(workflow *stakingpb.Workflow) bool {
return workflow.State == stakingpb.Workflow_STATE_WAITING_FOR_SIGNING
}

func WorkflowWaitingForExternalBroadcast(workflow *stakingpb.Workflow) bool {
return workflow.State == stakingpb.Workflow_STATE_WAITING_FOR_EXT_BROADCAST
}
18 changes: 6 additions & 12 deletions docs/openapi/orchestration.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1283,18 +1283,17 @@
"STATE_UNSPECIFIED",
"STATE_NOT_CONSTRUCTED",
"STATE_CONSTRUCTED",
"STATE_PENDING_SIGNING",
"STATE_PENDING_EXT_BROADCAST",
"STATE_SIGNED",
"STATE_BROADCASTING",
"STATE_CONFIRMING",
"STATE_CONFIRMED",
"STATE_FINALIZED",
"STATE_FAILED",
"STATE_SUCCESS",
"STATE_PENDING_EXT_BROADCAST"
"STATE_SUCCESS"
],
"default": "STATE_UNSPECIFIED",
"description": "State defines an enumeration of states for a staking transaction.\n\n - STATE_UNSPECIFIED: Unspecified transaction state, this is for backwards compatibility.\n - STATE_NOT_CONSTRUCTED: Tx has not yet been constructed in the backend.\n - STATE_CONSTRUCTED: Tx construction is over in the backend.\n - STATE_PENDING_SIGNING: Tx is waiting to be signed.\n - STATE_SIGNED: Tx has been signed and returned to the backend.\n - STATE_BROADCASTING: Tx is being broadcasted to the network.\n - STATE_CONFIRMING: Tx is waiting for confirmation.\n - STATE_CONFIRMED: Tx has been confirmed to be included in a block.\n - STATE_FINALIZED: Tx has been finalized.\n - STATE_FAILED: Tx construction or broadcasting failed.\n - STATE_SUCCESS: Tx has been successfully executed.\n - STATE_PENDING_EXT_BROADCAST: Tx is waiting to be externally broadcasted by the customer."
"description": "State defines an enumeration of states for a staking transaction.\n\n - STATE_UNSPECIFIED: Unspecified transaction state, this is for backwards compatibility.\n - STATE_NOT_CONSTRUCTED: Tx has not yet been constructed in the backend.\n - STATE_CONSTRUCTED: Tx construction is over in the backend.\n - STATE_PENDING_EXT_BROADCAST: Tx is waiting to be externally broadcasted by the customer.\n - STATE_SIGNED: Tx has been signed and returned to the backend.\n - STATE_BROADCASTING: Tx is being broadcasted to the network.\n - STATE_CONFIRMING: Tx is waiting for confirmation.\n - STATE_CONFIRMED: Tx has been confirmed to be included in a block.\n - STATE_FINALIZED: Tx has been finalized.\n - STATE_FAILED: Tx construction or broadcasting failed.\n - STATE_SUCCESS: Tx has been successfully executed."
},
"v1Validator": {
"type": "object",
Expand Down Expand Up @@ -1435,10 +1434,6 @@
"description": "The timestamp the workflow was last updated.",
"readOnly": true
},
"skipBroadcast": {
"type": "boolean",
"description": "Flag to skip tx broadcast to network on behalf of the user. Use this flag if you instead prefer to broadcast signed txs on your own."
},
"completeTime": {
"type": "string",
"format": "date-time",
Expand All @@ -1458,13 +1453,12 @@
"enum": [
"STATE_UNSPECIFIED",
"STATE_IN_PROGRESS",
"STATE_WAITING_FOR_SIGNING",
"STATE_WAITING_FOR_EXT_BROADCAST",
"STATE_COMPLETED",
"STATE_FAILED",
"STATE_WAITING_FOR_EXT_BROADCAST"
"STATE_FAILED"
],
"default": "STATE_UNSPECIFIED",
"description": "Example flow: A workflow with skip_broadcast = true leading to a successful completion.\n IN_PROGRESS -\u003e WAITING_FOR_EXT_BROADCAST -\u003e IN_PROGRESS -\u003e COMPLETED\n Example flow: A workflow with skip_broadcast = false leading to a successful completion.\n IN_PROGRESS -\u003e WAITING_FOR_SIGNING -\u003e IN_PROGRESS -\u003e COMPLETED\n Example flow: A workflow with skip_broadcast = false leading to a failure.\n IN_PROGRESS -\u003e WAITING_FOR_SIGNING -\u003e IN_PROGRESS -\u003e FAILED\n\n - STATE_UNSPECIFIED: Unspecified workflow state, this is for backwards compatibility.\n - STATE_IN_PROGRESS: In Progress represents a workflow that is currently in progress.\n - STATE_WAITING_FOR_SIGNING: Waiting for signing represents the workflow is waiting on the consumer to sign and return the corresponding signed tx.\n - STATE_COMPLETED: Completed represents the workflow has completed.\n - STATE_FAILED: Failed represents the workflow has failed.\n - STATE_WAITING_FOR_EXT_BROADCAST: Waiting for external broadcast represents the workflow is waiting for the customer to broadcast a tx and return its corresponding tx hash.",
"description": "Example flows:\n A workflow leading to a successful completion.\n IN_PROGRESS -\u003e WAITING_FOR_EXT_BROADCAST -\u003e IN_PROGRESS -\u003e COMPLETED\n A workflow leading to a failure.\n IN_PROGRESS -\u003e WAITING_FOR_EXT_BROADCAST -\u003e IN_PROGRESS -\u003e FAILED\n\n - STATE_UNSPECIFIED: Unspecified workflow state, this is for backwards compatibility.\n - STATE_IN_PROGRESS: In Progress represents a workflow that is currently in progress.\n - STATE_WAITING_FOR_EXT_BROADCAST: Waiting for external broadcast represents the workflow is waiting for the customer to broadcast a tx and return its corresponding tx hash.\n - STATE_COMPLETED: Completed represents the workflow has completed.\n - STATE_FAILED: Failed represents the workflow has failed.",
"title": "The state of a workflow"
},
"v1WorkflowStep": {
Expand Down
1 change: 1 addition & 0 deletions docs/openapi/rewards.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@
},
"exp": {
"type": "string",
"format": "int64",
"description": "The number of decimals needed to convert from the raw numeric value to the most\ncommon denomination.",
"readOnly": true
},
Expand Down
27 changes: 7 additions & 20 deletions examples/ethereum/create-and-process-workflow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func main() {
},
},
},
SkipBroadcast: true,
},
}

Expand All @@ -94,39 +93,27 @@ func main() {

printWorkflowProgressDetails(workflow)

// If workflow is in WAITING_FOR_SIGNING state, sign the transaction and update the workflow
if v1.WorkflowWaitingForSigning(workflow) {
// If workflow is in WAITING_FOR_EXT_BROADCAST state, sign, broadcast the transaction and update the workflow.
if v1.WorkflowWaitingForExternalBroadcast(workflow) {
unsignedTx := workflow.Steps[workflow.GetCurrentStepId()].GetTxStepOutput().GetUnsignedTx()

// Logic to sign the transaction. This can be substituted with any other signing mechanism.
log.Printf("Signing unsigned tx %s ...\n", unsignedTx)

signedTx, err := signer.New("ethereum_kiln").SignTransaction(privateKey, &signer.UnsignedTx{Data: []byte(unsignedTx)})
signedTx, err := signer.New("ethereum_kiln").SignTransaction([]string{privateKey}, &signer.UnsignedTx{Data: []byte(unsignedTx)})
if err != nil {
log.Fatalf(fmt.Errorf("error signing transaction: %w", err).Error())
}

log.Printf("Returning back signed tx %s ...\n", string(signedTx.Data))

workflow, err = stakingClient.Orchestration.PerformWorkflowStep(ctx, &stakingpb.PerformWorkflowStepRequest{
Name: workflow.Name,
Step: workflow.GetCurrentStepId(),
Data: string(signedTx.Data),
})
if err != nil {
log.Fatalf(fmt.Errorf("error updating workflow with signed tx: %w", err).Error())
}
} else if v1.WorkflowWaitingForExternalBroadcast(workflow) {
unsignedTx := workflow.Steps[workflow.GetCurrentStepId()].GetTxStepOutput().GetUnsignedTx()

fmt.Printf("Please sign and broadcast this unsigned tx %s externally and return back the tx hash via the PerformWorkflowStep API ...\n", unsignedTx)
// Add logic to broadcast the tx here.
fmt.Printf("Please broadcast this signed tx %s externally and return back the tx hash via the PerformWorkflowStep API ...\n", signedTx)
break
} else if v1.WorkflowFinished(workflow) {
break
}

// Sleep for 5 seconds before polling for workflow status again
time.Sleep(5 * time.Second)
// Sleep for 1 second before polling for workflow status again
time.Sleep(1 * time.Second)
}
}

Expand Down
1 change: 0 additions & 1 deletion examples/ethereum/create-workflow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func main() {
},
},
},
SkipBroadcast: true,
},
}

Expand Down
33 changes: 19 additions & 14 deletions examples/solana/create-workflow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main
import (
"context"
"fmt"
"github.com/coinbase/staking-client-library-go/internal/signer"
"log"
"os"
"time"
Expand All @@ -20,8 +21,9 @@ import (
)

const (
// TODO: Replace with your project ID.
projectID = ""
// TODO: Replace with your project ID and private key.
projectID = ""
privateKey = ""

// TODO: Replace with your wallet addresses and amount.
walletAddress = ""
Expand All @@ -47,8 +49,8 @@ func main() {
log.Fatalf("error instantiating staking client: %s", err.Error())
}

if projectID == "" || walletAddress == "" {
log.Fatalf("projectID and walletAddress must be set")
if projectID == "" || privateKey == "" || walletAddress == "" {
log.Fatalf("projectID, privateKey, and walletAddress must be set")
}

req := &stakingpb.CreateWorkflowRequest{
Expand All @@ -69,7 +71,6 @@ func main() {
},
},
},
SkipBroadcast: true,
},
}

Expand All @@ -92,23 +93,27 @@ func main() {

printWorkflowProgressDetails(workflow)

// If workflow is in WAITING_FOR_SIGNING state, sign the transaction and update the workflow
if v1.WorkflowWaitingForSigning(workflow) {
// If workflow is in WAITING_FOR_EXT_BROADCAST state, sign, broadcast the transaction and update the workflow.
if v1.WorkflowWaitingForExternalBroadcast(workflow) {
unsignedTx := workflow.Steps[workflow.GetCurrentStepId()].GetTxStepOutput().GetUnsignedTx()

fmt.Printf("Please sign this unsigned tx and return back the signed tx via the PerformWorkflowStep API : %s\n", unsignedTx)
break
} else if v1.WorkflowWaitingForExternalBroadcast(workflow) {
unsignedTx := workflow.Steps[workflow.GetCurrentStepId()].GetTxStepOutput().GetUnsignedTx()
// Logic to sign the transaction. This can be substituted with any other signing mechanism.
log.Printf("Signing unsigned tx %s ...\n", unsignedTx)

signedTx, err := signer.New("solana").SignTransaction([]string{privateKey}, &signer.UnsignedTx{Data: []byte(unsignedTx)})
if err != nil {
log.Fatalf(fmt.Errorf("error signing transaction: %w", err).Error())
}

fmt.Printf("Please sign and broadcast this unsigned tx externally and return back the tx hash via the PerformWorkflowStep API : %s\n", unsignedTx)
// Add logic to broadcast the tx here.
fmt.Printf("Please broadcast this signed tx %s externally and return back the tx hash via the PerformWorkflowStep API ...\n", signedTx)
break
} else if v1.WorkflowFinished(workflow) {
break
}

// Sleep for 5 seconds before polling for workflow status again
time.Sleep(5 * time.Second)
// Sleep for 1 second before polling for workflow status again
time.Sleep(1 * time.Second)
}
}

Expand Down
Loading

0 comments on commit 19ae468

Please sign in to comment.