Skip to content

Commit c172805

Browse files
committed
refactor: update remaining bech32 to proper address type
1 parent 91559e5 commit c172805

24 files changed

+297
-293
lines changed

docs/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
import "./out/dev/types/routes.d.ts";
3+
import "./.next/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

packages/evolution/src/sdk/builders/TransactionBuilder.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import { Context, Data, Effect, Layer, Logger, LogLevel, Ref } from "effect"
2929
import type { Either } from "effect/Either"
3030

31+
import type * as CoreAddress from "../../core/Address.js"
3132
import * as CoreAssets from "../../core/Assets/index.js"
3233
import type * as Coin from "../../core/Coin.js"
3334
import type * as Network from "../../core/Network.js"
@@ -150,7 +151,7 @@ const resolveProtocolParameters = (
150151
const resolveChangeAddress = (
151152
config: TxBuilderConfig,
152153
options?: BuildOptions
153-
): Effect.Effect<string, TransactionBuilderError | WalletNew.WalletError> => {
154+
): Effect.Effect<CoreAddress.Address, TransactionBuilderError | WalletNew.WalletError> => {
154155
if (options?.changeAddress) {
155156
return Effect.succeed(options.changeAddress)
156157
}
@@ -781,13 +782,13 @@ export interface BuildOptions {
781782
* // Use different account for change
782783
* builder.build({ changeAddress: wallet.addresses[5] })
783784
*
784-
* // Custom address
785-
* builder.build({ changeAddress: "addr_test1..." })
785+
* // Custom Core Address
786+
* builder.build({ changeAddress: Core.Address.fromBech32("addr_test1...") })
786787
* ```
787788
*
788789
* @since 2.0.0
789790
*/
790-
readonly changeAddress?: string
791+
readonly changeAddress?: CoreAddress.Address
791792

792793
/**
793794
* Override the available UTxOs for this specific transaction build.
@@ -1216,7 +1217,7 @@ export class TxContext extends Context.Tag("TxContext")<TxContext, Ref.Ref<TxBui
12161217
* @since 2.0.0
12171218
* @category context
12181219
*/
1219-
export class ChangeAddressTag extends Context.Tag("ChangeAddress")<ChangeAddressTag, string>() {}
1220+
export class ChangeAddressTag extends Context.Tag("ChangeAddress")<ChangeAddressTag, CoreAddress.Address>() {}
12201221

12211222
/**
12221223
* Resolved protocol parameters for the current build.

packages/evolution/src/sdk/builders/TxBuilderImpl.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Effect, Ref, Schema } from "effect"
33
import type * as Array from "effect/Array"
44

55
// Core imports
6-
import * as CoreAddress from "../../core/Address.js"
6+
import type * as CoreAddress from "../../core/Address.js"
77
import * as CoreAssets from "../../core/Assets/index.js"
88
import * as Bytes32 from "../../core/Bytes32.js"
99
import * as PlutusData from "../../core/Data.js"
@@ -234,14 +234,14 @@ export const makeDatumOption = (datum: Datum.Datum): Effect.Effect<DatumOption.D
234234
* @category helpers
235235
*/
236236
export const makeTxOutput = (params: {
237-
address: string
237+
address: CoreAddress.Address
238238
assets: CoreAssets.Assets
239239
datum?: Datum.Datum
240240
scriptRef?: any // TODO: Add ScriptRef type
241241
}): Effect.Effect<TxOut.TransactionOutput, TransactionBuilderError> =>
242242
Effect.gen(function* () {
243-
// Parse address from bech32 string to core Address type
244-
const address = yield* Schema.decodeUnknown(CoreAddress.FromBech32)(params.address)
243+
// Address is already a Core Address type
244+
const address = params.address
245245

246246
// Convert datum if provided
247247
let datumOption: DatumOption.DatumOption | undefined
@@ -262,7 +262,7 @@ export const makeTxOutput = (params: {
262262
Effect.mapError(
263263
(error) =>
264264
new TransactionBuilderError({
265-
message: `Failed to create TxOutput for address: ${params.address}`,
265+
message: `Failed to create TxOutput`,
266266
cause: error
267267
})
268268
)
@@ -278,14 +278,14 @@ export const makeTxOutput = (params: {
278278
* @internal
279279
*/
280280
export const txOutputToTransactionOutput = (params: {
281-
address: string
281+
address: CoreAddress.Address
282282
assets: CoreAssets.Assets
283283
datum?: Datum.Datum
284284
scriptRef?: any // TODO: Add ScriptRef type
285285
}): Effect.Effect<TxOut.TransactionOutput, TransactionBuilderError> =>
286286
Effect.gen(function* () {
287-
// Parse address from bech32 string to core Address type using Schema
288-
const address = yield* Schema.decodeUnknown(CoreAddress.FromBech32)(params.address)
287+
// Address is already a Core Address type
288+
const address = params.address
289289

290290
// Convert datum if provided
291291
let datumOption: DatumOption.DatumOption | undefined
@@ -306,7 +306,7 @@ export const txOutputToTransactionOutput = (params: {
306306
Effect.mapError(
307307
(error) =>
308308
new TransactionBuilderError({
309-
message: `Failed to create transaction output for address: ${params.address}`,
309+
message: `Failed to create transaction output`,
310310
cause: error
311311
})
312312
)
@@ -1114,7 +1114,7 @@ export const calculateLeftoverAssets = (params: {
11141114
* @category change
11151115
*/
11161116
export const calculateMinimumUtxoLovelace = (params: {
1117-
address: string
1117+
address: CoreAddress.Address
11181118
assets: CoreAssets.Assets
11191119
datum?: Datum.Datum
11201120
scriptRef?: any
@@ -1165,7 +1165,7 @@ export const calculateMinimumUtxoLovelace = (params: {
11651165
*/
11661166
export const createChangeOutput = (params: {
11671167
leftoverAssets: CoreAssets.Assets
1168-
changeAddress: string
1168+
changeAddress: CoreAddress.Address
11691169
coinsPerUtxoByte: bigint
11701170
unfrackOptions?: UnfrackOptions
11711171
}): Effect.Effect<ReadonlyArray<TxOut.TransactionOutput>, TransactionBuilderError> =>

packages/evolution/src/sdk/builders/Unfrack.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import * as Effect from "effect/Effect"
1414

15+
import type * as CoreAddress from "../../core/Address.js"
1516
import * as CoreAssets from "../../core/Assets/index.js"
1617
import type * as TxOut from "../../core/TxOut.js"
1718
import type { UnfrackOptions } from "./TransactionBuilder.js"
@@ -117,7 +118,7 @@ export interface TokenBundle {
117118
*/
118119
const calculateBundleMinUTxO = (
119120
bundleTokens: ReadonlyArray<TokenInfo>,
120-
changeAddress: string,
121+
changeAddress: CoreAddress.Address,
121122
coinsPerUtxoByte: bigint
122123
): Effect.Effect<bigint, Error, never> => Effect.gen(function* () {
123124
// Build Assets object with the bundle tokens using CoreAssets
@@ -147,7 +148,7 @@ const calculateBundleMinUTxO = (
147148
export const calculateTokenBundles = (
148149
tokens: ReadonlyArray<TokenInfo>,
149150
options: UnfrackOptions,
150-
changeAddress: string,
151+
changeAddress: CoreAddress.Address,
151152
coinsPerUtxoByte: bigint
152153
): Effect.Effect<ReadonlyArray<TokenBundle>, Error, never> => Effect.gen(function* () {
153154
const bundleSize = options.tokens?.bundleSize ?? 10
@@ -208,7 +209,7 @@ export const calculateTokenBundles = (
208209
const bundleTokensWithRules = (
209210
tokens: ReadonlyArray<TokenInfo>,
210211
bundleSize: number,
211-
changeAddress: string,
212+
changeAddress: CoreAddress.Address,
212213
coinsPerUtxoByte: bigint
213214
): Effect.Effect<ReadonlyArray<TokenBundle>, Error, never> => Effect.gen(function* () {
214215
const bundles: Array<TokenBundle> = []
@@ -349,7 +350,7 @@ export type UnfrackResult = {
349350
* @category builders
350351
*/
351352
export const createUnfrackedChangeOutputs = (
352-
changeAddress: string,
353+
changeAddress: CoreAddress.Address,
353354
changeAssets: CoreAssets.Assets,
354355
options: UnfrackOptions = {},
355356
coinsPerUtxoByte: bigint

packages/evolution/src/sdk/builders/operations/Operations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type * as CoreAddress from "../../../core/Address.js"
12
import type * as CoreAssets from "../../../core/Assets/index.js"
23
import type * as UTxO from "../../../core/UTxO.js"
3-
import type * as Address from "../../Address.js"
44
import type * as Datum from "../../Datum.js"
55
import type * as Script from "../../Script.js"
66

@@ -9,7 +9,7 @@ import type * as Script from "../../Script.js"
99
// ============================================================================
1010

1111
export interface PayToAddressParams {
12-
readonly address: Address.Address // Mandatory: Recipient address
12+
readonly address: CoreAddress.Address // Mandatory: Recipient address (Core Address object)
1313
readonly assets: CoreAssets.Assets // Mandatory: ADA and/or native tokens to send
1414
readonly datum?: Datum.Datum // Optional: Datum to attach for script addresses
1515
readonly scriptRef?: Script.Script // Optional: Reference script to attach

packages/evolution/src/sdk/builders/phases/ChangeCreation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import { Effect, Ref } from "effect"
1212

13+
import type * as CoreAddress from "../../../core/Address.js"
1314
import * as CoreAssets from "../../../core/Assets/index.js"
1415
import type * as TxOut from "../../../core/TxOut.js"
1516
import * as CoreUTxO from "../../../core/UTxO.js"
@@ -57,7 +58,7 @@ const getAvailableUtxos = (
5758
*/
5859
const createChangeOutputs = (
5960
leftoverAfterFee: CoreAssets.Assets,
60-
changeAddress: string,
61+
changeAddress: CoreAddress.Address,
6162
coinsPerUtxoByte: bigint
6263
): Effect.Effect<ReadonlyArray<TxOut.TransactionOutput>, TransactionBuilderError, BuildOptionsTag> =>
6364
Effect.gen(function* () {

packages/evolution/src/sdk/builders/phases/Collateral.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import { Effect, Ref } from "effect"
1313

14-
import * as CoreAddress from "../../../core/Address.js"
1514
import * as CoreAssets from "../../../core/Assets/index.js"
1615
import * as TxOut from "../../../core/TxOut.js"
1716
import * as UTxO from "../../../core/UTxO.js"
@@ -302,9 +301,8 @@ export const executeCollateral = (): Effect.Effect<
302301
// ═══════════════════════════════════════════════════════════
303302
// STEP 9: Create Return Output
304303
// ═══════════════════════════════════════════════════════════
305-
const coreAddress = CoreAddress.fromBech32(changeAddress)
306304
const collateralReturn = new TxOut.TransactionOutput({
307-
address: coreAddress,
305+
address: changeAddress,
308306
assets: returnAssets,
309307
datumOption: undefined, // No datum for collateral return
310308
scriptRef: undefined // No script reference

packages/evolution/src/sdk/client/ClientImpl.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Effect, Equal, ParseResult } from "effect"
22

3+
import * as CoreAddress from "../../core/Address.js"
34
import * as KeyHash from "../../core/KeyHash.js"
45
import * as PrivateKey from "../../core/PrivateKey.js"
56
import * as Transaction from "../../core/Transaction.js"
@@ -9,7 +10,6 @@ import * as CoreUTxO from "../../core/UTxO.js"
910
import * as VKey from "../../core/VKey.js"
1011
import { runEffectPromise } from "../../utils/effect-runtime.js"
1112
import { hashTransaction } from "../../utils/Hash.js"
12-
import type * as Address from "../Address.js"
1313
import {
1414
makeTxBuilder,
1515
type ReadOnlyTransactionBuilder,
@@ -114,13 +114,14 @@ const createReadOnlyWallet = (
114114
address: string,
115115
rewardAddress?: string
116116
): WalletNew.ReadOnlyWallet => {
117+
const coreAddress = CoreAddress.fromBech32(address)
117118
const walletEffect: WalletNew.ReadOnlyWalletEffect = {
118-
address: () => Effect.succeed(address),
119+
address: () => Effect.succeed(coreAddress),
119120
rewardAddress: () => Effect.succeed(rewardAddress ?? null)
120121
}
121122

122123
return {
123-
address: () => Promise.resolve(address),
124+
address: () => Promise.resolve(coreAddress),
124125
rewardAddress: () => Promise.resolve(rewardAddress ?? null),
125126
Effect: walletEffect,
126127
type: "read-only"
@@ -167,12 +168,14 @@ const createReadOnlyClient = (
167168
const provider = createProvider(providerConfig)
168169
const walletNetwork = toWalletNetwork(network)
169170
const wallet = createReadOnlyWallet(walletNetwork, walletConfig.address, walletConfig.rewardAddress)
171+
// Parse the bech32 address to Core Address for provider calls
172+
const coreAddress = CoreAddress.fromBech32(walletConfig.address)
170173

171174
const result = {
172175
...provider,
173176
address: wallet.address,
174177
rewardAddress: wallet.rewardAddress,
175-
getWalletUtxos: () => provider.getUtxos(walletConfig.address),
178+
getWalletUtxos: () => provider.getUtxos(coreAddress),
176179
getWalletDelegation: async () => {
177180
const rewardAddr = walletConfig.rewardAddress
178181
if (!rewardAddr) throw new Error("No reward address configured")
@@ -187,7 +190,7 @@ const createReadOnlyClient = (
187190
Effect: {
188191
...provider.Effect,
189192
...wallet.Effect,
190-
getWalletUtxos: () => provider.Effect.getUtxos(walletConfig.address),
193+
getWalletUtxos: () => provider.Effect.getUtxos(coreAddress),
191194
getWalletDelegation: () => {
192195
const rewardAddr = walletConfig.rewardAddress
193196
if (!rewardAddr)
@@ -324,7 +327,7 @@ const createSigningWallet = (network: WalletNew.Network, config: SeedWalletConfi
324327

325328
return witnesses.length > 0 ? TransactionWitnessSet.fromVKeyWitnesses(witnesses) : TransactionWitnessSet.empty()
326329
}),
327-
signMessage: (_address: Address.Address | RewardAddress.RewardAddress, payload: WalletNew.Payload) =>
330+
signMessage: (_address: CoreAddress.Address | RewardAddress.RewardAddress, payload: WalletNew.Payload) =>
328331
Effect.map(derivationEffect, (derivation) => {
329332
// For now, always use payment key for message signing
330333
const paymentSk = PrivateKey.fromBech32(derivation.paymentKey)
@@ -406,7 +409,7 @@ const createPrivateKeyWallet = (
406409

407410
return witnesses.length > 0 ? TransactionWitnessSet.fromVKeyWitnesses(witnesses) : TransactionWitnessSet.empty()
408411
}),
409-
signMessage: (_address: Address.Address | RewardAddress.RewardAddress, payload: WalletNew.Payload) =>
412+
signMessage: (_address: CoreAddress.Address | RewardAddress.RewardAddress, payload: WalletNew.Payload) =>
410413
Effect.map(derivationEffect, (derivation) => {
411414
const paymentSk = PrivateKey.fromBech32(derivation.paymentKey)
412415
const vk = VKey.fromPrivateKey(paymentSk)
@@ -435,7 +438,7 @@ const createPrivateKeyWallet = (
435438
*/
436439
const createApiWallet = (_network: WalletNew.Network, config: ApiWalletConfig): WalletNew.ApiWallet => {
437440
const api = config.api
438-
let cachedAddress: Address.Address | null = null
441+
let cachedAddress: CoreAddress.Address | null = null
439442
let cachedReward: RewardAddress.RewardAddress | null = null
440443

441444
const getPrimaryAddress = Effect.gen(function* () {
@@ -448,12 +451,13 @@ const createApiWallet = (_network: WalletNew.Network, config: ApiWalletConfig):
448451
try: () => api.getUnusedAddresses(),
449452
catch: (cause) => new WalletNew.WalletError({ message: (cause as Error).message, cause: cause as Error })
450453
})
451-
const addr = used[0] ?? unused[0]
452-
if (!addr) {
454+
const addrStr = used[0] ?? unused[0]
455+
if (!addrStr) {
453456
return yield* Effect.fail(new WalletNew.WalletError({ message: "Wallet API returned no addresses", cause: null }))
454457
}
455-
cachedAddress = addr
456-
return addr
458+
// Convert bech32 string to Core Address
459+
cachedAddress = CoreAddress.fromBech32(addrStr)
460+
return cachedAddress
457461
})
458462

459463
const getPrimaryRewardAddress = Effect.gen(function* () {
@@ -483,10 +487,12 @@ const createApiWallet = (_network: WalletNew.Network, config: ApiWalletConfig):
483487
)
484488
)
485489
}),
486-
signMessage: (address: Address.Address | RewardAddress.RewardAddress, payload: WalletNew.Payload) =>
490+
signMessage: (address: CoreAddress.Address | RewardAddress.RewardAddress, payload: WalletNew.Payload) =>
487491
Effect.gen(function* () {
492+
// Convert Core Address to bech32 string for the CIP-30 API
493+
const addressStr = address instanceof CoreAddress.Address ? CoreAddress.toBech32(address) : address
488494
const result = yield* Effect.tryPromise({
489-
try: () => api.signData(address, payload),
495+
try: () => api.signData(addressStr, payload),
490496
catch: (cause) => new WalletNew.WalletError({ message: "User rejected message signing", cause })
491497
})
492498
return { payload, signature: result.signature }

packages/evolution/src/sdk/provider/Provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Effect } from "effect"
22
import { Context, Data } from "effect"
33

4+
import type * as CoreAddress from "../../core/Address.js"
45
import type * as CoreUTxO from "../../core/UTxO.js"
5-
import type * as Address from "../Address.js"
66
import type * as Credential from "../Credential.js"
77
import type * as Delegation from "../Delegation.js"
88
import type { EvalRedeemer } from "../EvalRedeemer.js"
@@ -38,12 +38,12 @@ export interface ProviderEffect {
3838
/**
3939
* Query UTxOs at a given address or by credential.
4040
*/
41-
readonly getUtxos: (addressOrCredential: Address.Address | Credential.Credential) => Effect.Effect<Array<CoreUTxO.UTxO>, ProviderError>
41+
readonly getUtxos: (addressOrCredential: CoreAddress.Address | Credential.Credential) => Effect.Effect<Array<CoreUTxO.UTxO>, ProviderError>
4242
/**
4343
* Query UTxOs at a given address or credential filtered by specific unit.
4444
*/
4545
readonly getUtxosWithUnit: (
46-
addressOrCredential: Address.Address | Credential.Credential,
46+
addressOrCredential: CoreAddress.Address | Credential.Credential,
4747
unit: string
4848
) => Effect.Effect<Array<CoreUTxO.UTxO>, ProviderError>
4949
/**

0 commit comments

Comments
 (0)