Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client interface updates #31

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions examples/ethereum/create-and-process-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Workflow } from '../../src/gen/coinbase/staking/orchestration/v1/workfl
import { calculateTimeDifference } from '../../src/utils/date';

const walletPrivateKey: string = 'your-wallet-private-key'; // replace with your wallet's private key
const stakerAddress: string = '0xdb816889F2a7362EF242E5a717dfD5B38Ae849FE'; // replace with your staker address
const stakerAddress: string = 'your-wallet-address'; // replace with your staker address
const amount: string = '123'; // replace with your amount
const network: string = 'holesky'; // replace with your network

Expand All @@ -32,17 +32,11 @@ async function stakePartialEth(): Promise<void> {
let unsignedTx = '';
let workflow: Workflow = {} as Workflow;
let currentStepId: number | undefined;
let workflowId: string;

try {
// Create a new eth kiln stake workflow
workflow = await client.Ethereum.stake(network, stakerAddress, amount);

workflowId = workflow.name?.split('/').pop() || '';
if (workflowId == null || workflowId === '') {
throw new Error('Unexpected workflow state. workflowId is null');
}

currentStepId = workflow.currentStepId;
if (currentStepId == null) {
throw new Error('Unexpected workflow state. currentStepId is null');
Expand All @@ -64,7 +58,7 @@ async function stakePartialEth(): Promise<void> {
// If the workflow is waiting for external broadcast, sign and broadcast the unsigned tx externally and return back the tx hash via the PerformWorkflowStep API.
// Note: In this example, we just log this message as the wallet provider needs to implement this logic.
try {
workflow = await client.getWorkflow(workflowId);
workflow = await client.getWorkflow(workflow.name!);
} catch (error) {
// TODO: add retry logic for network errors
if (error instanceof Error) {
Expand Down
12 changes: 3 additions & 9 deletions examples/solana/create-and-process-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { Workflow } from '../../src/gen/coinbase/staking/orchestration/v1/workfl
import { calculateTimeDifference } from '../../src/utils/date';

const walletPrivateKey: string = 'your-wallet-private-key'; // replace with your wallet's private key
const walletAddress: string = ''; // replace with your wallet address
const walletAddress: string = 'your-wallet-address'; // replace with your wallet address
const amount: string = '100000000'; // replace with your amount. For solana it should be >= 0.1 SOL
const network: string = 'mainnet'; // replace with your network
const network: string = 'devnet'; // replace with your network

// Set your api key name and private key here. Get your keys from here: https://portal.cdp.coinbase.com/access/api
const apiKeyName: string = 'your-api-key-name';
Expand All @@ -32,17 +32,11 @@ async function stakeSolana(): Promise<void> {
let unsignedTx = '';
let workflow: Workflow = {} as Workflow;
let currentStepId: number | undefined;
let workflowId: string;

try {
// Create a new solana stake workflow
workflow = await client.Solana.stake(network, walletAddress, amount);

workflowId = workflow.name?.split('/').pop() || '';
if (workflowId == null || workflowId === '') {
throw new Error('Unexpected workflow state. workflowId is null');
}

currentStepId = workflow.currentStepId;
if (currentStepId == null) {
throw new Error('Unexpected workflow state. currentStepId is null');
Expand All @@ -67,7 +61,7 @@ async function stakeSolana(): Promise<void> {
// If the workflow is waiting for external broadcast, sign and broadcast the unsigned tx externally and return back the tx hash via the PerformWorkflowStep API.
// Note: In this example, we just log this message as the wallet provider needs to implement this logic.
try {
workflow = await client.getWorkflow(workflowId);
workflow = await client.getWorkflow(workflow.name!);
} catch (error) {
// TODO: add retry logic for network errors
if (error instanceof Error) {
Expand Down
11 changes: 5 additions & 6 deletions src/client/staking-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ export class StakingClient {
}

// Get a workflow given workflow id.
async getWorkflow(workflowId: string): Promise<Workflow> {
const name: string = `workflows/${workflowId}`;
const path: string = `/v1/${name}`;
async getWorkflow(workflowName: string): Promise<Workflow> {
const path: string = `/v1/${workflowName}`;
const method: string = 'GET';
const url: string = this.baseURL + '/orchestration';

Expand All @@ -203,19 +202,19 @@ export class StakingClient {
);

const req: GetWorkflowRequest = {
name: name,
name: workflowName,
};

return StakingService.GetWorkflow(req, initReq);
}

// Return back a signed tx or a broadcasted tx hash for a given workflow and step number.
async performWorkflowStep(
workflowId: string,
workflowName: string,
stepIndex: number,
data: string,
): Promise<Workflow> {
const name: string = `${parent}/workflows/${workflowId}`;
const name: string = `${parent}/${workflowName}`;
const path: string = `/v1/${name}/step`;
const method: string = 'POST';
const url: string = this.baseURL + '/orchestration';
Expand Down
Loading