Skip to content

Commit

Permalink
Merge pull request #204 from identity-com/feature/IDCOM-2129-extend-t…
Browse files Browse the repository at this point in the history
…ransactions
  • Loading branch information
rado0x54 authored Jan 5, 2023
2 parents d4a5147 + 231142a commit b46f945
Show file tree
Hide file tree
Showing 44 changed files with 1,762 additions and 642 deletions.
270 changes: 199 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"packages/tests"
],
"devDependencies": {
"@project-serum/anchor-cli": "^0.25.0",
"@project-serum/anchor-cli": "^0.26.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-prettier": "^4.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"dependencies": {
"@identity.com/cryptid": "0.3.0-alpha.11",
"@identity.com/sol-did-client": "^3.1.3",
"@identity.com/sol-did-client": "^3.3.0",
"@oclif/core": "^1.13.10",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^2.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/client/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"types": "dist/index.d.ts",
"dependencies": {
"@identity.com/cryptid-idl": "0.3.0-alpha.11",
"@identity.com/sol-did-client": "^3.1.3",
"@project-serum/anchor": "^0.25.0",
"@identity.com/sol-did-client": "^3.3.0",
"@project-serum/anchor": "^0.26.0",
"@solana/web3.js": "^1.62.0",
"ramda": "^0.28.0"
},
Expand Down
34 changes: 29 additions & 5 deletions packages/client/core/src/api/abstractCryptidClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import { DidSolIdentifier, DidSolService } from "@identity.com/sol-did-client";
import { didService } from "../lib/did";
import { CryptidService } from "../service/cryptid";
import { CryptidAccountDetails } from "../lib/CryptidAccountDetails";
import { TransactionAccount } from "../types";
import { TransactionAccount, TransactionState } from "../types";
import { ProposalResult, ExecuteArrayResult } from "../types/cryptid";
import { translateError } from "@project-serum/anchor";
import { CryptidTransaction } from "../lib/CryptidTransaction";

export abstract class AbstractCryptidClient implements CryptidClient {
readonly details: CryptidAccountDetails;
Expand Down Expand Up @@ -108,18 +109,41 @@ export abstract class AbstractCryptidClient implements CryptidClient {
};
}

async propose(transaction: Transaction): Promise<ProposalResult> {
async propose(
transaction: Transaction,
state?: TransactionState
): Promise<ProposalResult> {
return this.service().then((service) =>
service.propose(this.details, transaction)
service.propose(this.details, transaction, state)
);
}

async extend(
transactionAccountAddress: PublicKey,
transaction: Transaction,
state?: TransactionState
): Promise<Transaction> {
return this.service().then((service) =>
service.extend(
this.details,
transactionAccountAddress,
transaction,
state
)
);
}

async execute(
transactionAccountAddress: PublicKey
transactionAccountAddress: PublicKey,
cryptidTransactionRepresentation?: CryptidTransaction
): Promise<ExecuteArrayResult> {
return this.service()
.then((service) =>
service.execute(this.details, transactionAccountAddress)
service.execute(
this.details,
transactionAccountAddress,
cryptidTransactionRepresentation
)
)
.then((result) => ({
executeTransactions: [result.executeTransaction],
Expand Down
51 changes: 44 additions & 7 deletions packages/client/core/src/api/cryptidClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {
} from "@solana/web3.js";
import { DIDDocument } from "did-resolver";
import { Wallet } from "../types/crypto";
import { ProposalResult, TransactionAccount } from "../types";
import { ProposalResult, TransactionAccount, TransactionState } from "../types";
import { CryptidAccountDetails } from "../lib/CryptidAccountDetails";
import { Middleware } from "../lib/Middleware";
import { ExecuteArrayResult } from "../types/cryptid";
import { CryptidTransaction } from "../lib/CryptidTransaction";

export type PayerOption = "DID_PAYS" | "SIGNER_PAYS";
export type CryptidOptions = {
Expand All @@ -23,10 +24,10 @@ export type CryptidOptions = {
waitForConfirmation?: boolean;
rentPayer?: PayerOption;
};
// The chain of controllers, from the top (inclusive), to the one that owns the cryptid account (exclusive)
// For example, if did:sol:alice controls did:sol:bob which controls did:sol:carol,
// If alice is creating a cryptid account for carol, the controller chain is [did:sol:alice, did:sol:bob]
export type CreateOptions = CryptidOptions & {
// The chain of controllers, from the top (inclusive), to the one that owns the cryptid account (exclusive)
// For example, if did:sol:alice controls did:sol:bob which controls did:sol:carol,
// If alice is creating a cryptid account for carol, the controller chain is [did:sol:alice, did:sol:bob]
controllerChain?: string[];
};
export type FindAllOptions = {
Expand All @@ -47,7 +48,7 @@ export const DEFAULT_CRYPTID_OPTIONS: Partial<CryptidOptions> = {
* Clients have the following options when signing a transaction:
*
* 1. directExecute: Single instruction, no middleware.
* 2. propose / execute: Two separate calls, middleware is executed as part of the execute call.
* 2. propose / execute: Two separate calls, middleware is typically executed as part of the execute call.
* 3. proposeAndExecute: Single call, returns an array of transactions to be passed to the chain.
* If forceSingleTx is set to true, this forces all instructions into a single transaction.
* Note: At present, there are no checks to see if it fits.
Expand Down Expand Up @@ -100,8 +101,44 @@ export interface CryptidClient {
forceSingleTx?: boolean
): Promise<ExecuteArrayResult>;

propose(transaction: Transaction): Promise<ProposalResult>;
execute(transactionAccountAddress: PublicKey): Promise<ExecuteArrayResult>;
/**
* Propose a transaction for execution by cryptid.
* @param transaction The transaction to propose
* @param state [TransactionState.Ready] The state to propose the transaction in. If NotReady, the transaction can be extended.
*/
propose(
transaction: Transaction,
state?: TransactionState
): Promise<ProposalResult>;

/**
* Extend an existing cryptid transaction proposal by adding a transaction to it.
*
* The transaction must have previously been proposed in "NotReady" state.
*
* Any authority on the cryptid account can extend the transaction.
*
* @param transactionAccountAddress The account representing the cryptid transaction proposal to extend
* @param transaction The transaction to add
* @param state [TransactionState.Ready] The new state of the transaction. If NotReady, the transaction can be extended further.
*/
extend(
transactionAccountAddress: PublicKey,
transaction: Transaction,
state?: TransactionState
): Promise<Transaction>;

/**
* Execute a proposed transaction.
*
* The transaction must be in "Ready" state.
* @param transactionAccountAddress
* @param cryptidTransactionRepresentation
*/
execute(
transactionAccountAddress: PublicKey,
cryptidTransactionRepresentation?: CryptidTransaction
): Promise<ExecuteArrayResult>;

// TODO Reinstate
// cancelLarge(transactionAccount: PublicKey): Promise<TransactionSignature>;
Expand Down
Loading

0 comments on commit b46f945

Please sign in to comment.