Skip to content

Commit eee1574

Browse files
authored
Merge pull request #7 from XYOracleNetwork/feature/update-deps
Updates dependencies and use locator
2 parents 047da8f + a0f32f1 commit eee1574

13 files changed

Lines changed: 204 additions & 98 deletions

.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Wallet mnemonic (seed phrase)
22
# Ensure default account has sufficient funds for transactions
3-
# This is my seed phrase for sequence
43
XYO_WALLET_MNEMONIC="orbit torch boil interest warrior spoon lounge ecology knock cereal mango habit"
54

65
# RPC URL for the XYO network [Localhost]

.vscode/launch.json

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,22 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7-
{
7+
{
88
"type": "node",
99
"request": "launch",
10-
"name": "Node Hello World Sample",
11-
"program": "${workspaceFolder}/dist/index.js",
12-
"args": [],
13-
"outFiles": [
14-
"${workspaceFolder}/dist/**"
15-
],
10+
"name": "Node Hello World Runner",
11+
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/tsx",
1612
"runtimeArgs": [
1713
"--max-old-space-size=8192"
1814
],
15+
"program": "${workspaceFolder}/src/index.ts",
16+
"args": [],
1917
"envFile": "${workspaceFolder}/.env",
2018
"sourceMaps": true,
21-
"resolveSourceMapLocations": [
22-
"!**/node_modules/**",
23-
],
24-
"pauseForSourceMap": true,
2519
"cwd": "${workspaceFolder}",
26-
"preLaunchTask": "build",
20+
"skipFiles": [
21+
"<node_internals>/**"
22+
],
2723
},
2824
{
2925
"type": "node",

package.json

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,26 @@
2525
"updo": "npx npm-check-updates -i"
2626
},
2727
"dependencies": {
28-
"@xylabs/assert": "5.0.33",
29-
"@xylabs/delay": "5.0.33",
30-
"@xylabs/typeof": "5.0.33",
31-
"@xylabs/tsconfig": "7.2.8",
32-
"@xyo-network/payload-builder": "5.1.22",
33-
"@xyo-network/wallet": "5.1.22",
34-
"@xyo-network/xl1-protocol": "1.13.11",
35-
"@xyo-network/xl1-protocol-sdk": "1.16.12",
36-
"@xyo-network/xl1-rpc": "1.16.12",
28+
"@xylabs/assert": "5.0.63",
29+
"@xylabs/delay": "5.0.63",
30+
"@xylabs/tsconfig": "7.2.32",
31+
"@xylabs/typeof": "5.0.63",
32+
"@xyo-network/payload-builder": "5.2.25",
33+
"@xyo-network/wallet": "5.2.25",
34+
"@xyo-network/xl1-sdk": "1.18.33",
3735
"dotenv": "17.2.3"
3836
},
3937
"devDependencies": {
40-
"@types/node": "24.10.1",
41-
"@xylabs/eslint-config-flat": "7.2.8",
42-
"@xyo-network/payload-model": "5.1.22",
43-
"@xyo-network/xl1-cli": "1.16.12",
44-
"eslint": "9.39.1",
38+
"@types/node": "25.0.9",
39+
"@xylabs/eslint-config-flat": "7.2.32",
40+
"@xyo-network/account-model": "5.2.25",
41+
"@xyo-network/payload-model": "5.2.25",
42+
"@xyo-network/xl1-cli": "1.18.1",
43+
"eslint": "9.39.2",
4544
"eslint-import-resolver-typescript": "4.4.4",
46-
"npm-check-updates": "19.1.2",
47-
"tsx": "4.20.6",
48-
"typedoc": "0.28.14",
45+
"npm-check-updates": "19.3.1",
46+
"tsx": "4.21.0",
47+
"typedoc": "0.28.16",
4948
"typedoc-plugin-markdown": "4.9.0",
5049
"typescript": "5.9.3"
5150
},
@@ -60,4 +59,4 @@
6059
"publishConfig": {
6160
"access": "restricted"
6261
}
63-
}
62+
}

src/getGateway.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { isDefined } from '@xylabs/typeof'
2+
import type { SimpleXyoSigner, XyoConnection } from '@xyo-network/xl1-sdk'
3+
import {
4+
SimpleXyoGatewayRunner, XyoConnectionMoniker, XyoSignerMoniker,
5+
} from '@xyo-network/xl1-sdk'
6+
7+
import { getLocator } from './getLocator.ts'
8+
9+
let gateway: SimpleXyoGatewayRunner | undefined
10+
11+
export const getGateway = async () => {
12+
// If existing gateway, return it
13+
if (isDefined(gateway)) return gateway
14+
15+
// Otherwise, build a new gateway
16+
17+
// Get locator
18+
const locator = await getLocator()
19+
20+
// Use locator to get connection and signer
21+
const connection = await locator.getInstance<XyoConnection>(XyoConnectionMoniker)
22+
const signer = await locator.getInstance<SimpleXyoSigner>(XyoSignerMoniker)
23+
24+
// Create gateway from connection and signer
25+
gateway = new SimpleXyoGatewayRunner(connection, signer)
26+
return gateway
27+
}

src/getLocator.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { isDefined } from '@xylabs/typeof'
2+
import type { ProviderFactoryLocator } from '@xyo-network/xl1-sdk'
3+
import { buildJsonRpcProviderLocator, SimpleXyoSigner } from '@xyo-network/xl1-sdk'
4+
5+
import { getSignerAccount } from './getSignerAccount.ts'
6+
import { getTransportFactory } from './getTransportFactory.ts'
7+
8+
let locator: ProviderFactoryLocator
9+
10+
export const getLocator = async () => {
11+
// If existing locator, return it
12+
if (isDefined(locator)) return locator
13+
14+
// Build a new locator
15+
const transportFactory = getTransportFactory()
16+
locator = await buildJsonRpcProviderLocator({ transportFactory })
17+
18+
// Register the signer with the locator
19+
const account = await getSignerAccount()
20+
locator.register(SimpleXyoSigner.factory<SimpleXyoSigner>(SimpleXyoSigner.dependencies, { account }))
21+
22+
// Return the locator
23+
return locator
24+
}

src/getRandomTransactionData.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { PayloadBuilder } from '@xyo-network/payload-builder'
2+
import type { Payload } from '@xyo-network/payload-model'
3+
import type { HashPayload } from '@xyo-network/xl1-sdk'
4+
5+
/**
6+
* Generates random data for a transaction.
7+
* @returns An object containing off-chain and on-chain data for the transaction.
8+
*/
9+
export const getRandomTransactionData = async () => {
10+
// Data to store off-chain
11+
const salt = `Hello from Sample - ${new Date().toISOString()}`
12+
const idPayload: Payload<{ salt: string }> = { schema: 'network.xyo.id', salt }
13+
14+
// Data to store on-chain (can reference the off-chain data)
15+
const hash = await PayloadBuilder.hash(idPayload)
16+
const hashPayload: HashPayload = { schema: 'network.xyo.hash', hash }
17+
18+
return {
19+
offChainData: [idPayload],
20+
onChainData: [hashPayload],
21+
}
22+
}

src/getRpcUrl.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { config } from 'dotenv'
2+
3+
// Load environment variables from .env file
4+
config({ quiet: true })
5+
6+
// Parse the relevant ENV VARs or use defaults
7+
const rpcUrl = process.env.XYO_CHAIN_RPC_URL ?? 'http://localhost:8080/rpc'
8+
9+
/**
10+
* Gets the rpcUrl to use for interacting with the chain
11+
* @returns The rpcUrl to use for interacting with the chain
12+
*/
13+
export const getRpcUrl = (): string => rpcUrl

src/getSignerAccount.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { isDefined } from '@xylabs/typeof'
2+
import type { AccountInstance } from '@xyo-network/account-model'
3+
import { ADDRESS_INDEX, generateXyoBaseWalletFromPhrase } from '@xyo-network/xl1-sdk'
4+
5+
import { getWalletMnemonic } from './getWalletMnemonic.ts'
6+
7+
let signerAccount: AccountInstance | undefined
8+
9+
/**
10+
* Retrieves the signer account derived from the configured mnemonic.
11+
* @returns The derived account
12+
*/
13+
export const getSignerAccount = async () => {
14+
// If existing signer account, return it
15+
if (isDefined (signerAccount)) return signerAccount
16+
17+
// Create new signer account
18+
const walletMnemonic = getWalletMnemonic()
19+
const wallet = await generateXyoBaseWalletFromPhrase(walletMnemonic)
20+
signerAccount = await wallet.derivePath(ADDRESS_INDEX.XYO)
21+
console.log('Using signer account:', signerAccount.address)
22+
return signerAccount
23+
}

src/getTransportFactory.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { isDefined } from '@xylabs/typeof'
2+
import type { RpcSchemaMap, TransportFactory } from '@xyo-network/xl1-sdk'
3+
import { HttpRpcTransport } from '@xyo-network/xl1-sdk'
4+
5+
import { getRpcUrl } from './getRpcUrl.ts'
6+
7+
let transportFactory: TransportFactory | undefined
8+
9+
/**
10+
* Retrieves a transport factory for the configured RPC URL.
11+
* @returns A transport factory for the configured RPC URL
12+
*/
13+
export const getTransportFactory = () => {
14+
// If existing transport factory, return it
15+
if (isDefined(transportFactory)) return transportFactory
16+
17+
// Build a new transport factory
18+
const rpcUrl = getRpcUrl()
19+
console.log('Using rpcUrl:', rpcUrl)
20+
transportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(rpcUrl, schemas)
21+
return transportFactory
22+
}

src/getWalletMnemonic.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { HDWallet } from '@xyo-network/wallet'
2+
import { config } from 'dotenv'
3+
4+
// Load environment variables from .env file
5+
config({ quiet: true })
6+
7+
// Parse the relevant ENV VARs or use defaults
8+
const mnemonic = process.env.XYO_WALLET_MNEMONIC ?? HDWallet.generateMnemonic()
9+
10+
/**
11+
* Gets the mnemonic to use for the wallet
12+
* @returns The mnemonic to use for the wallet
13+
*/
14+
export const getWalletMnemonic = (): string => mnemonic

0 commit comments

Comments
 (0)