This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
286 additions
and
169 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
api/src/data/data-sources/akash-api/akash-api-deployment-data-source.ts
This file was deleted.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
api/src/data/data-sources/akash/akash-deployment-data-source.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { type IDeploymentDataSource } from "@src/data/interfaces/data-sources/deployment-data-source"; | ||
import { | ||
QueryClientImpl, | ||
QueryDeploymentsRequest, | ||
QueryDeploymentResponse | ||
} from "@akashnetwork/akashjs/build/protobuf/akash/deployment/v1beta3/query"; | ||
import { | ||
MsgCreateDeployment, | ||
MsgCreateDeploymentResponse | ||
} from "@akashnetwork/akashjs/build/protobuf/akash/deployment/v1beta3/deploymentmsg"; | ||
import { getRpc } from "@akashnetwork/akashjs/build/rpc"; | ||
import { DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing"; | ||
import { | ||
getAkashTypeRegistry, | ||
getTypeUrl | ||
} from "@akashnetwork/akashjs/build/stargate/index"; | ||
import { SigningStargateClient } from "@cosmjs/stargate"; | ||
import axios from "axios"; | ||
|
||
export class AkashApiDeploymentDataSource implements IDeploymentDataSource { | ||
private readonly rpcEndpoint: string; | ||
private readonly mnemonic: string; | ||
constructor(rpcEndpoint: string | undefined, mnemonic: string | undefined) { | ||
this.rpcEndpoint = rpcEndpoint || ""; | ||
this.mnemonic = mnemonic || ""; | ||
} | ||
|
||
async create(): Promise<MsgCreateDeploymentResponse> { | ||
const response = await axios.get(`${this.rpcEndpoint}/blocks/latest`); | ||
const data = response.data; | ||
|
||
const dseq = parseInt(data.block.header.height); | ||
|
||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(this.mnemonic, { | ||
prefix: "akash" | ||
}); | ||
|
||
// get first account | ||
const [account] = await wallet.getAccounts(); | ||
|
||
// Use the encode method for the message to wrap the data | ||
const message = MsgCreateDeployment.fromPartial({ | ||
id: { | ||
dseq: dseq, | ||
owner: account.address | ||
} | ||
}); | ||
|
||
const msgAny = { | ||
typeUrl: getTypeUrl(MsgCreateDeployment), | ||
value: message | ||
}; | ||
|
||
const myRegistry = new Registry(getAkashTypeRegistry()); | ||
|
||
const client = await SigningStargateClient.connectWithSigner( | ||
this.rpcEndpoint, | ||
wallet, | ||
{ | ||
registry: myRegistry | ||
} | ||
); | ||
|
||
const fee = { | ||
amount: [ | ||
{ | ||
denom: "uakt", | ||
amount: "5000" | ||
} | ||
], | ||
gas: "800000" | ||
}; | ||
|
||
const signedMessage = await client.signAndBroadcast( | ||
account.address, | ||
[msgAny], | ||
fee, | ||
"create deployment" | ||
); | ||
|
||
console.log(signedMessage); | ||
|
||
return Promise.reject(new Error(`Not implemented yet`)); | ||
} | ||
|
||
async list(): Promise<QueryDeploymentResponse[]> { | ||
const rpc = await getRpc(this.rpcEndpoint); | ||
const request = QueryDeploymentsRequest.fromJSON({}); | ||
const client = new QueryClientImpl(rpc); | ||
const response = await client.Deployments(request); | ||
if (response?.deployments?.length > 0) { | ||
return response.deployments; | ||
} | ||
return Promise.reject(new Error("No deployments found")); | ||
} | ||
|
||
async listByOwner(ownerAddress: string): Promise<QueryDeploymentResponse[]> { | ||
const rpc = await getRpc(this.rpcEndpoint); | ||
const request = QueryDeploymentsRequest.fromJSON({ | ||
filters: { | ||
owner: ownerAddress | ||
} | ||
}); | ||
const client = new QueryClientImpl(rpc); | ||
const response = await client.Deployments(request); | ||
if (response?.deployments?.length > 0) { | ||
return response.deployments; | ||
} | ||
return Promise.reject( | ||
new Error(`No deployments found for owner ${ownerAddress}`) | ||
); | ||
} | ||
} |
12 changes: 6 additions & 6 deletions
12
api/src/data/interfaces/data-sources/deployment-data-source.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import AkashQuery from "@akashnetwork/akashjs/build/protobuf/akash/deployment/v1beta3/query"; | ||
import { QueryDeploymentResponse } from "@akashnetwork/akashjs/build/protobuf/akash/deployment/v1beta3/query"; | ||
import { MsgCreateDeploymentResponse } from "@akashnetwork/akashjs/build/protobuf/akash/deployment/v1beta3/deploymentmsg"; | ||
|
||
export interface DeploymentDataSource { | ||
getAll: () => Promise<AkashQuery.QueryDeploymentResponse[]>; | ||
getByOwner: ( | ||
ownerAddress: string | ||
) => Promise<AkashQuery.QueryDeploymentResponse[]>; | ||
export interface IDeploymentDataSource { | ||
create: () => Promise<MsgCreateDeploymentResponse>; | ||
list: () => Promise<QueryDeploymentResponse[]>; | ||
listByOwner: (ownerAddress: string) => Promise<QueryDeploymentResponse[]>; | ||
} |
7 changes: 4 additions & 3 deletions
7
api/src/domain/interfaces/repositories/deployment-repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { type Deployment } from "@src/domain/entities/deployment"; | ||
|
||
export interface DeploymentRepository { | ||
getDeployments: () => Promise<Deployment[]>; | ||
getDeploymentsByOwner: (ownerAddress: string) => Promise<Deployment[]>; | ||
export interface IDeploymentRepository { | ||
create: (deployment: Deployment) => Promise<Deployment>; | ||
list: () => Promise<Deployment[]>; | ||
listByOwner: (ownerAddress: string) => Promise<Deployment[]>; | ||
} |
2 changes: 1 addition & 1 deletion
2
...es/deployment/get-deployments-by-owner.ts → ...ces/use-cases/deployment/list-by-owner.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { type Deployment } from "../../../entities/deployment"; | ||
|
||
export interface GetDeploymentsByOwnerUseCase { | ||
export interface IListByOwnerUseCase { | ||
execute: (ownerAddress: string) => Promise<Deployment[]>; | ||
} |
Oops, something went wrong.