Skip to content
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
1 change: 0 additions & 1 deletion Cargo.lock

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

66 changes: 42 additions & 24 deletions packages/js-evo-sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export class EvoSDK {
}

get wasm(): wasm.WasmSdk {
if (!this.wasmSdk) throw new Error('SDK is not connected. Call EvoSDK#connect() first.');
if (!this.wasmSdk) {
throw new Error('SDK is not connected. Call EvoSDK#connect() first.');
}
return this.wasmSdk;
}

Expand All @@ -83,47 +85,63 @@ export class EvoSDK {
}

async connect(): Promise<void> {
if (this.wasmSdk) return; // idempotent
if (this.wasmSdk) {
return; // idempotent
}
await initWasm();

const { network, trusted, version, proofs, settings, logs, addresses } = this.options;

let builder: wasm.WasmSdkBuilder;

// If specific addresses are provided, use them instead of network presets
if (addresses && addresses.length > 0) {
// Prefetch trusted quorums for the network before creating builder with addresses
// Prefetch trusted context only when trusted mode is requested
let context: wasm.WasmTrustedContext | undefined;
if (trusted) {
if (network === 'mainnet') {
await wasm.WasmSdk.prefetchTrustedQuorumsMainnet();
context = await wasm.WasmTrustedContext.prefetchMainnet();
} else if (network === 'testnet') {
await wasm.WasmSdk.prefetchTrustedQuorumsTestnet();
context = await wasm.WasmTrustedContext.prefetchTestnet();
} else if (network === 'local') {
await wasm.WasmSdk.prefetchTrustedQuorumsLocal();
context = await wasm.WasmTrustedContext.prefetchLocal();
} else {
throw new Error(`Unknown network: ${network}`);
}
}

let builder: wasm.WasmSdkBuilder;

if (addresses && addresses.length > 0) {
builder = wasm.WasmSdkBuilder.withAddresses(addresses, network);
} else if (network === 'mainnet') {
await wasm.WasmSdk.prefetchTrustedQuorumsMainnet();

builder = trusted ? wasm.WasmSdkBuilder.mainnetTrusted() : wasm.WasmSdkBuilder.mainnet();
builder = wasm.WasmSdkBuilder.mainnet();
} else if (network === 'testnet') {
await wasm.WasmSdk.prefetchTrustedQuorumsTestnet();

builder = trusted ? wasm.WasmSdkBuilder.testnetTrusted() : wasm.WasmSdkBuilder.testnet();
builder = wasm.WasmSdkBuilder.testnet();
} else if (network === 'local') {
// Default local dashmate gateway and quorum list sidecar
await wasm.WasmSdk.prefetchTrustedQuorumsLocal();

builder = trusted ? wasm.WasmSdkBuilder.localTrusted() : wasm.WasmSdkBuilder.local();
builder = wasm.WasmSdkBuilder.local();
} else {
throw new Error(`Unknown network: ${network}`);
}

if (version) builder = builder.withVersion(version);
if (typeof proofs === 'boolean') builder = builder.withProofs(proofs);
if (logs) builder = builder.withLogs(logs);
// Attach trusted context for proof verification and discovered addresses
if (context) {
builder = builder.withTrustedContext(context);
}

if (version) {
builder = builder.withVersion(version);
}
if (typeof proofs === 'boolean') {
builder = builder.withProofs(proofs);
}
if (logs) {
builder = builder.withLogs(logs);
}
if (settings) {
const { connectTimeoutMs, timeoutMs, retries, banFailedAddress } = settings;
builder = builder.withSettings(connectTimeoutMs ?? null, timeoutMs ?? null, retries ?? null, banFailedAddress ?? null);
builder = builder.withSettings(
connectTimeoutMs ?? null,
timeoutMs ?? null,
retries ?? null,
banFailedAddress ?? null,
);
}

this.wasmSdk = builder.build();
Expand Down
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/tests/unit/facades/addresses.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('AddressesFacade', () => {

beforeEach(async function setup() {
await init();
const builder = wasmSDKPackage.WasmSdkBuilder.testnetTrusted();
const builder = wasmSDKPackage.WasmSdkBuilder.testnet();
wasmSdk = await builder.build();
client = EvoSDK.fromWasm(wasmSdk);

Expand Down
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/tests/unit/facades/contracts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('ContractsFacade', () => {

beforeEach(async function setup() {
await init();
const builder = wasmSDKPackage.WasmSdkBuilder.testnetTrusted();
const builder = wasmSDKPackage.WasmSdkBuilder.testnet();
wasmSdk = await builder.build();
client = EvoSDK.fromWasm(wasmSdk);

Expand Down
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/tests/unit/facades/documents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('DocumentsFacade', () => {

beforeEach(async function setup() {
await init();
const builder = wasmSDKPackage.WasmSdkBuilder.testnetTrusted();
const builder = wasmSDKPackage.WasmSdkBuilder.testnet();
wasmSdk = await builder.build();
client = EvoSDK.fromWasm(wasmSdk);

Expand Down
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/tests/unit/facades/dpns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('DPNSFacade', () => {

beforeEach(async function setup() {
await init();
const builder = wasmSDKPackage.WasmSdkBuilder.testnetTrusted();
const builder = wasmSDKPackage.WasmSdkBuilder.testnet();
wasmSdk = await builder.build();
client = EvoSDK.fromWasm(wasmSdk);

Expand Down
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/tests/unit/facades/epoch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('EpochFacade', () => {

beforeEach(async function setup() {
await init();
const builder = wasmSDKPackage.WasmSdkBuilder.testnetTrusted();
const builder = wasmSDKPackage.WasmSdkBuilder.testnet();
wasmSdk = await builder.build();
client = EvoSDK.fromWasm(wasmSdk);

Expand Down
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/tests/unit/facades/group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('GroupFacade', () => {

beforeEach(async function setup() {
await init();
const builder = wasmSDKPackage.WasmSdkBuilder.testnetTrusted();
const builder = wasmSDKPackage.WasmSdkBuilder.testnet();
wasmSdk = await builder.build();
client = EvoSDK.fromWasm(wasmSdk);

Expand Down
12 changes: 8 additions & 4 deletions packages/js-evo-sdk/tests/unit/facades/identities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('IdentitiesFacade', () => {
let getIdentityByNonUniquePublicKeyHashStub: SinonStub;
let getIdentityByNonUniquePublicKeyHashWithProofInfoStub: SinonStub;
let getIdentitiesContractKeysStub: SinonStub;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let getIdentitiesContractKeysWithProofInfoStub: SinonStub;
let getIdentityTokenBalancesStub: SinonStub;
let getIdentityTokenBalancesWithProofInfoStub: SinonStub;
Expand All @@ -43,7 +44,7 @@ describe('IdentitiesFacade', () => {

beforeEach(async function setup() {
await init();
const builder = wasmSDKPackage.WasmSdkBuilder.testnetTrusted();
const builder = wasmSDKPackage.WasmSdkBuilder.testnet();
wasmSdk = await builder.build();
client = EvoSDK.fromWasm(wasmSdk);

Expand Down Expand Up @@ -75,7 +76,8 @@ describe('IdentitiesFacade', () => {
metadata: {},
});
getIdentityContractNonceStub = this.sinon.stub(wasmSdk, 'getIdentityContractNonce').resolves(BigInt(0));
getIdentityContractNonceWithProofInfoStub = this.sinon.stub(wasmSdk, 'getIdentityContractNonceWithProofInfo').resolves({
getIdentityContractNonceWithProofInfoStub = this.sinon
.stub(wasmSdk, 'getIdentityContractNonceWithProofInfo').resolves({
data: BigInt(0),
proof: {},
metadata: {},
Expand Down Expand Up @@ -109,7 +111,8 @@ describe('IdentitiesFacade', () => {
proof: {},
metadata: {},
});
getIdentityByNonUniquePublicKeyHashStub = this.sinon.stub(wasmSdk, 'getIdentityByNonUniquePublicKeyHash').resolves([]);
getIdentityByNonUniquePublicKeyHashStub = this.sinon
.stub(wasmSdk, 'getIdentityByNonUniquePublicKeyHash').resolves([]);
getIdentityByNonUniquePublicKeyHashWithProofInfoStub = this.sinon
.stub(wasmSdk, 'getIdentityByNonUniquePublicKeyHashWithProofInfo').resolves({
data: [],
Expand All @@ -124,7 +127,8 @@ describe('IdentitiesFacade', () => {
metadata: {},
});
getIdentityTokenBalancesStub = this.sinon.stub(wasmSdk, 'getIdentityTokenBalances').resolves(new Map());
getIdentityTokenBalancesWithProofInfoStub = this.sinon.stub(wasmSdk, 'getIdentityTokenBalancesWithProofInfo').resolves({
getIdentityTokenBalancesWithProofInfoStub = this.sinon
.stub(wasmSdk, 'getIdentityTokenBalancesWithProofInfo').resolves({
data: new Map(),
proof: {},
metadata: {},
Expand Down
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/tests/unit/facades/protocol.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('ProtocolFacade', () => {

beforeEach(async function setup() {
await init();
const builder = wasmSDKPackage.WasmSdkBuilder.testnetTrusted();
const builder = wasmSDKPackage.WasmSdkBuilder.testnet();
wasmSdk = await builder.build();
client = EvoSDK.fromWasm(wasmSdk);

Expand Down
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/tests/unit/facades/system.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('SystemFacade', () => {

beforeEach(async function setup() {
await init();
const builder = wasmSDKPackage.WasmSdkBuilder.testnetTrusted();
const builder = wasmSDKPackage.WasmSdkBuilder.testnet();
wasmSdk = await builder.build();
client = EvoSDK.fromWasm(wasmSdk);

Expand Down
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/tests/unit/facades/tokens.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('TokensFacade', () => {

beforeEach(async function setup() {
await init();
const builder = wasmSDKPackage.WasmSdkBuilder.testnetTrusted();
const builder = wasmSDKPackage.WasmSdkBuilder.testnet();
wasmSdk = await builder.build();
client = EvoSDK.fromWasm(wasmSdk);

Expand Down
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/tests/unit/facades/voting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('VotingFacade', () => {

beforeEach(async function setup() {
await init();
const builder = wasmSDKPackage.WasmSdkBuilder.testnetTrusted();
const builder = wasmSDKPackage.WasmSdkBuilder.testnet();
wasmSdk = await builder.build();
client = EvoSDK.fromWasm(wasmSdk);

Expand Down
1 change: 0 additions & 1 deletion packages/rs-platform-version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ thiserror = { version = "2.0.12" }
bincode = { version = "=2.0.1" }
versioned-feature-core = { git = "https://github.com/dashpay/versioned-feature-core", version = "1.0.0" }
grovedb-version = { git = "https://github.com/dashpay/grovedb", rev = "33dfd48a1718160cb333fa95424be491785f1897" }
once_cell = "1.19.0"

[features]
mock-versions = []
6 changes: 6 additions & 0 deletions packages/rs-sdk/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,12 @@ impl SdkBuilder {
}
}

/// Replace the address list on this builder.
pub fn with_address_list(mut self, addresses: AddressList) -> Self {
self.addresses = Some(addresses);
self
}

/// Create a new SdkBuilder that will generate mock client.
pub fn new_mock() -> Self {
Self::default()
Expand Down
5 changes: 4 additions & 1 deletion packages/simple-signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ state-transitions = [
]

[dependencies]
bincode = { version = "=2.0.1", features = ["serde"] }
dpp = { path = "../rs-dpp", default-features = false, features = [
"ed25519-dalek",
] }
bincode = { version = "=2.0.1", features = ["serde"] }
base64 = { version = "0.22.1" }
hex = { version = "0.4.3" }
tracing = "0.1.41"

[package.metadata.cargo-machete]
ignored = ["bincode"]
Loading
Loading