Skip to content

Commit

Permalink
Merge pull request #475 from LF-Decentralized-Trust-labs/paladin-sdk
Browse files Browse the repository at this point in the history
Misc SDK and operator fixes
  • Loading branch information
awrichar authored Dec 11, 2024
2 parents 8c37ea8 + 6f5f41e commit f4a838b
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void testBond() throws Exception {
assertEquals("type=TransactionData(bytes32 salt,bytes data),labels=[]", schema.signature());
}
}
assertNotNull(notoSchema);

String bondTrackerPublicBytecode = ResourceLoader.jsonResourceEntryText(
this.getClass().getClassLoader(),
Expand Down Expand Up @@ -287,7 +288,7 @@ void testBond() throws Exception {
"");
var deployEvent = events.stream().filter(ev -> ev.get("soliditySignature").toString().startsWith("event AtomDeployed")).findFirst();
assertFalse(deployEvent.isEmpty());
var deployEventData = (HashMap<String, Object>) deployEvent.get().get("data");
var deployEventData = mapper.convertValue(deployEvent.get().get("data"), HashMap.class);
var atomAddress = JsonHex.addressFrom(deployEventData.get("addr").toString());

// Alice approves payment transfer
Expand Down
2 changes: 1 addition & 1 deletion example/bond/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/zeto/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion operator/api/v1alpha1/paladin_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,29 @@ const (
// AuthTypeSecret is used to authenticate with a secret
// The secret must contain keys "username" and "password"
AuthTypeSecret AuthType = "secret"
AuthTypeInline AuthType = "inline"
)

type Auth struct {
// auth method to use for the connection
// +kubebuilder:validation:Enum=secret
// +kubebuilder:validation:Enum=secret;inline
Type AuthType `json:"type"`

// Secret is used to provide the name of the secret to use for authentication
Secret *AuthSecret `json:"secretRef,omitempty"`

// Auth details are provided inline (not recommended)
Inline *AuthInline `json:"inline,omitempty"`
}

type AuthSecret struct {
// The name of the secret to use for authentication
Name string `json:"name"`
}
type AuthInline struct {
Username string `json:"username"`
Password string `json:"password"`
}

// StatusReason is an enumeration of possible failure causes. Each StatusReason
// must map to a single HTTP status code, but multiple reasons may map
Expand Down
20 changes: 20 additions & 0 deletions operator/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions operator/config/crd/bases/core.paladin.io_paladins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ spec:
Deprecated: Use 'baseLedgerEndpoint' instead. Example:
{ "baseLedgerEndpoint": {"type": "network", "network": {"auth": {}}} }
properties:
inline:
description: Auth details are provided inline (not recommended)
properties:
password:
type: string
username:
type: string
required:
- password
- username
type: object
secretRef:
description: Secret is used to provide the name of the secret
to use for authentication
Expand All @@ -64,6 +75,7 @@ spec:
description: auth method to use for the connection
enum:
- secret
- inline
type: string
required:
- type
Expand All @@ -78,6 +90,17 @@ spec:
properties:
auth:
properties:
inline:
description: Auth details are provided inline (not recommended)
properties:
password:
type: string
username:
type: string
required:
- password
- username
type: object
secretRef:
description: Secret is used to provide the name of the
secret to use for authentication
Expand All @@ -92,6 +115,7 @@ spec:
description: auth method to use for the connection
enum:
- secret
- inline
type: string
required:
- type
Expand Down
9 changes: 9 additions & 0 deletions operator/internal/controller/paladin_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,15 @@ func (r *PaladinReconciler) generatePaladinAuthConfig(ctx context.Context, node
if err := mapToStruct(sec.Data, &pldConf.Blockchain.WS.Auth); err != nil {
return err
}

case corev1alpha1.AuthTypeInline:
if authConfig.Inline == nil {
return fmt.Errorf("AuthInline must be provided when using AuthTypeInline")
}
pldConf.Blockchain.HTTP.Auth.Username = authConfig.Inline.Username
pldConf.Blockchain.HTTP.Auth.Password = authConfig.Inline.Password
pldConf.Blockchain.WS.Auth.Username = authConfig.Inline.Username
pldConf.Blockchain.WS.Auth.Password = authConfig.Inline.Password
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lfdecentralizedtrust-labs/paladin-sdk",
"version": "0.0.4-alpha.1",
"version": "0.0.6-alpha.1",
"description": "",
"main": "build/index.js",
"scripts": {
Expand Down
29 changes: 24 additions & 5 deletions sdk/typescript/src/interfaces/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,26 @@ export interface ITransactionReceipt {
transactionHash: string;
source: string;
contractAddress?: string;
domainReceipt?: {
receipt: {
contractAddress?: string;
};
};
states?: ITransactionStates;
domainReceipt?: IPenteDomainReceipt;
failureMessage?: string;
}

export interface IPenteDomainReceipt {
receipt: {
from?: string;
to?: string;
contractAddress?: string;
logs?: IPenteLog[];
};
}

export interface IPenteLog {
address: string;
topics: string[];
data: string;
}

export interface ITransactionStates {
none?: boolean;
spent?: IStateBase[];
Expand Down Expand Up @@ -125,3 +137,10 @@ export enum TransactionType {
Private = "private",
Public = "public",
}

export interface IDecodedEvent {
signature: string;
definition: ethers.JsonFragment;
data: any;
summary: string; // errors only
}
22 changes: 22 additions & 0 deletions sdk/typescript/src/paladin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import {
IPreparedTransaction,
ITransactionReceipt,
ITransactionStates,
IDecodedEvent,
} from "./interfaces/transaction";
import { Algorithms, Verifiers } from "./interfaces";
import { ethers } from "ethers";

const POLL_INTERVAL_MS = 100;

Expand Down Expand Up @@ -189,4 +191,24 @@ export default class PaladinClient {
]);
return res.data.result;
}

async storeABI(abi: ethers.InterfaceAbi) {
await this.post("ptx_storeABI", [abi]);
}

async decodeEvent(topics: string[], data: string) {
try {
const res = await this.post<JsonRpcResult<IDecodedEvent>>(
"ptx_decodeEvent",
[topics, data, ""]
);
return res.data.result;
} catch (err) {
const parsed = this.parseAxiosErrorMessage(err);
if (typeof parsed === "string" && parsed.indexOf("PD012229") >= 0) {
return undefined;
}
throw err;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ public JsonABI.Entry getABIEntry(String entryType, String entryName) {
}
}
}
if (entryType.equals("constructor")) {
return JsonABI.newConstructor(null);
}
throw new IllegalArgumentException("%s %s not found in ABI".formatted(entryType, entryName));
}

Expand Down

0 comments on commit f4a838b

Please sign in to comment.