Skip to content

Commit 6533312

Browse files
Merge pull request #41 from no-witness-labs/feat/upgrade-modules-9
feat/upgrade modules 9
2 parents c54bb4a + 899f026 commit 6533312

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2667
-2158
lines changed

packages/evolution/src/core/AddressDetails.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class AddressDetails extends Schema.Class<AddressDetails>("AddressDetails
3131
hex: Bytes.HexSchema
3232
}) {}
3333

34-
export const FromBech32 = Schema.transformOrFail(Schema.String, AddressDetails, {
34+
export const FromBech32 = Schema.transformOrFail(Schema.String, Schema.typeSchema(AddressDetails), {
3535
strict: true,
3636
encode: (_, __, ___, toA) => ParseResult.succeed(toA.bech32),
3737
decode: (_, __, ___, fromA) =>
@@ -48,7 +48,7 @@ export const FromBech32 = Schema.transformOrFail(Schema.String, AddressDetails,
4848
})
4949
})
5050

51-
export const FromHex = Schema.transformOrFail(Bytes.HexSchema, AddressDetails, {
51+
export const FromHex = Schema.transformOrFail(Bytes.HexSchema, Schema.typeSchema(AddressDetails), {
5252
strict: true,
5353
encode: (_, __, ___, toA) => ParseResult.succeed(toA.hex),
5454
decode: (_, __, ___, fromA) =>

packages/evolution/src/core/AddressEras.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export type AddressEras = typeof AddressEras.Type
8686
* @since 2.0.0
8787
* @category schema
8888
*/
89-
export const FromBytes = Schema.transformOrFail(Schema.Uint8ArrayFromSelf, AddressEras, {
89+
export const FromBytes = Schema.transformOrFail(Schema.Uint8ArrayFromSelf, Schema.typeSchema(AddressEras), {
9090
strict: true,
9191
encode: (_, __, ___, toA) => {
9292
switch (toA._tag) {
@@ -156,7 +156,7 @@ export const FromHex = Schema.compose(Bytes.FromHex, FromBytes)
156156
* @since 2.0.0
157157
* @category schema
158158
*/
159-
export const FromBech32 = Schema.transformOrFail(Schema.String, AddressEras, {
159+
export const FromBech32 = Schema.transformOrFail(Schema.String, Schema.typeSchema(AddressEras), {
160160
strict: true,
161161
encode: (_, __, ast, toA) =>
162162
Eff.gen(function* () {

packages/evolution/src/core/AddressStructure.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export class AddressStructureError extends Data.TaggedError("AddressStructureErr
2525
*/
2626
export class AddressStructure extends Schema.Class<AddressStructure>("AddressStructure")({
2727
networkId: NetworkId.NetworkId,
28-
paymentCredential: Credential.Credential,
29-
stakingCredential: Schema.optional(Credential.Credential)
28+
paymentCredential: Credential.CredentialSchema,
29+
stakingCredential: Schema.optional(Credential.CredentialSchema)
3030
}) {
3131
toString(): string {
3232
const staking = this.stakingCredential ? `, stakingCredential: ${this.stakingCredential}` : ""
@@ -47,7 +47,7 @@ export class AddressStructure extends Schema.Class<AddressStructure>("AddressStr
4747
*/
4848
export const FromBytes = Schema.transformOrFail(
4949
Schema.Union(Bytes57.BytesSchema, Bytes29.BytesSchema),
50-
AddressStructure,
50+
Schema.typeSchema(AddressStructure),
5151
{
5252
strict: true,
5353
encode: (_, __, ___, toA) =>
@@ -84,28 +84,28 @@ export const FromBytes = Schema.transformOrFail(
8484
if (fromA.length === 57) {
8585
// BaseAddress (with staking credential)
8686
const isPaymentKey = (addressTypeBits & 0b0001) === 0
87-
const paymentCredential: Credential.Credential = isPaymentKey
87+
const paymentCredential: Credential.CredentialSchema = isPaymentKey
8888
? new KeyHash.KeyHash({ hash: fromA.slice(1, 29) })
8989
: new ScriptHash.ScriptHash({ hash: fromA.slice(1, 29) })
9090

9191
const isStakeKey = (addressTypeBits & 0b0010) === 0
92-
const stakingCredential: Credential.Credential = isStakeKey
92+
const stakingCredential: Credential.CredentialSchema = isStakeKey
9393
? new KeyHash.KeyHash({ hash: fromA.slice(29, 57) })
9494
: new ScriptHash.ScriptHash({ hash: fromA.slice(29, 57) })
9595

96-
return yield* ParseResult.decode(AddressStructure)({
96+
return AddressStructure.make({
9797
networkId,
9898
paymentCredential,
9999
stakingCredential
100100
})
101101
} else if (fromA.length === 29) {
102102
// EnterpriseAddress (no staking credential)
103103
const isPaymentKey = (addressTypeBits & 0b0001) === 0
104-
const paymentCredential: Credential.Credential = isPaymentKey
104+
const paymentCredential: Credential.CredentialSchema = isPaymentKey
105105
? new KeyHash.KeyHash({ hash: fromA.slice(1, 29) })
106106
: new ScriptHash.ScriptHash({ hash: fromA.slice(1, 29) })
107107

108-
return yield* ParseResult.decode(AddressStructure)({
108+
return AddressStructure.make({
109109
networkId,
110110
paymentCredential,
111111
stakingCredential: undefined
@@ -135,7 +135,7 @@ export const FromHex = Schema.compose(Bytes.FromHex, FromBytes).annotations({
135135
* @since 1.0.0
136136
* @category Transformations
137137
*/
138-
export const FromBech32 = Schema.transformOrFail(Schema.String, AddressStructure, {
138+
export const FromBech32 = Schema.transformOrFail(Schema.String, Schema.typeSchema(AddressStructure), {
139139
strict: true,
140140
encode: (_, __, ___, toA) =>
141141
Eff.gen(function* () {

packages/evolution/src/core/Anchor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class AnchorError extends Data.TaggedError("AnchorError")<{
2828
*/
2929
export class Anchor extends Schema.Class<Anchor>("Anchor")({
3030
anchorUrl: Url.Url,
31-
anchorDataHash: Bytes32.BytesSchema
31+
anchorDataHash: Bytes32.BytesFromHex
3232
}) {}
3333

3434
export const CDDLSchema = Schema.Tuple(

packages/evolution/src/core/AssetName.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,24 @@ export class AssetNameError extends Data.TaggedError("AssetNameError")<{
2222
* @category model
2323
*/
2424
export class AssetName extends Schema.TaggedClass<AssetName>()("AssetName", {
25-
bytes: Bytes32.VariableBytes
26-
}) {
27-
toJSON(): string {
28-
return toHex(this)
29-
}
30-
toString(): string {
31-
return toHex(this)
32-
}
33-
}
25+
bytes: Bytes32.VariableBytesFromHex
26+
}) {}
3427

3528
/**
3629
* Schema for encoding/decoding AssetName as bytes.
3730
*
3831
* @since 2.0.0
3932
* @category schemas
4033
*/
41-
export const FromBytes = Schema.transform(Bytes32.VariableBytes, AssetName, {
42-
strict: true,
43-
decode: (bytes) => new AssetName({ bytes }, { disableValidation: true }),
44-
encode: (assetName) => assetName.bytes
45-
}).annotations({
34+
export const FromBytes = Schema.transform(
35+
Schema.typeSchema(Bytes32.VariableBytesFromHex),
36+
Schema.typeSchema(AssetName),
37+
{
38+
strict: true,
39+
decode: (bytes) => new AssetName({ bytes }, { disableValidation: true }),
40+
encode: (assetName) => assetName.bytes
41+
}
42+
).annotations({
4643
identifier: "AssetName.FromBytes"
4744
})
4845

packages/evolution/src/core/AuxiliaryData.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class ConwayAuxiliaryData extends Schema.TaggedClass<ConwayAuxiliaryData>
4343
"ConwayAuxiliaryData",
4444
{
4545
metadata: Schema.optional(Metadata.Metadata),
46-
nativeScripts: Schema.optional(Schema.Array(NativeScripts.Native)),
46+
nativeScripts: Schema.optional(Schema.Array(NativeScripts.NativeScript)),
4747
plutusV1Scripts: Schema.optional(Schema.Array(PlutusV1.PlutusV1)),
4848
plutusV2Scripts: Schema.optional(Schema.Array(PlutusV2.PlutusV2)),
4949
plutusV3Scripts: Schema.optional(Schema.Array(PlutusV3.PlutusV3))
@@ -65,7 +65,7 @@ export class ShelleyMAAuxiliaryData extends Schema.TaggedClass<ShelleyMAAuxiliar
6565
"ShelleyMAAuxiliaryData",
6666
{
6767
metadata: Schema.optional(Metadata.Metadata),
68-
nativeScripts: Schema.optional(Schema.Array(NativeScripts.Native))
68+
nativeScripts: Schema.optional(Schema.Array(NativeScripts.NativeScript))
6969
}
7070
) {}
7171

@@ -240,7 +240,7 @@ export const FromCDDL = Schema.transformOrFail(AnyEraCDDL, Schema.typeSchema(Aux
240240
if (Array.isArray(input)) {
241241
const arr = input
242242
let metadata: Metadata.Metadata | undefined
243-
let nativeScripts: Array<NativeScripts.Native> | undefined
243+
let nativeScripts: Array<NativeScripts.NativeScript> | undefined
244244

245245
if (arr.length >= 1 && arr[0] !== undefined) {
246246
const m = yield* ParseResult.decodeEither(Metadata.FromCDDL)(arr[0])
@@ -325,7 +325,7 @@ export const empty = (): AuxiliaryData => new ConwayAuxiliaryData({})
325325
*/
326326
export const conway = (input: {
327327
metadata?: Metadata.Metadata
328-
nativeScripts?: Array<NativeScripts.Native>
328+
nativeScripts?: Array<NativeScripts.NativeScript>
329329
plutusV1Scripts?: Array<PlutusV1.PlutusV1>
330330
plutusV2Scripts?: Array<PlutusV2.PlutusV2>
331331
plutusV3Scripts?: Array<PlutusV3.PlutusV3>
@@ -339,7 +339,7 @@ export const conway = (input: {
339339
*/
340340
export const shelleyMA = (input: {
341341
metadata?: Metadata.Metadata
342-
nativeScripts?: Array<NativeScripts.Native>
342+
nativeScripts?: Array<NativeScripts.NativeScript>
343343
}): AuxiliaryData => new ShelleyMAAuxiliaryData({ ...input })
344344

345345
/**

packages/evolution/src/core/AuxiliaryDataHash.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,23 @@ export class AuxiliaryDataHashError extends Data.TaggedError("AuxiliaryDataHashE
3131
* @category model
3232
*/
3333
export class AuxiliaryDataHash extends Schema.TaggedClass<AuxiliaryDataHash>()("AuxiliaryDataHash", {
34-
bytes: Bytes32.BytesSchema
34+
bytes: Bytes32.BytesFromHex
3535
}) {}
3636

37-
export const FromBytes = Schema.transform(Bytes32.BytesSchema, AuxiliaryDataHash, {
38-
strict: true,
39-
decode: (bytes) => new AuxiliaryDataHash({ bytes }, { disableValidation: true }),
40-
encode: (a) => a.bytes
41-
}).annotations({
37+
export const FromBytes = Schema.transform(
38+
Schema.typeSchema(Bytes32.BytesFromHex),
39+
Schema.typeSchema(AuxiliaryDataHash),
40+
{
41+
strict: true,
42+
decode: (bytes) => new AuxiliaryDataHash({ bytes }, { disableValidation: true }),
43+
encode: (a) => a.bytes
44+
}
45+
).annotations({
4246
identifier: "AuxiliaryDataHash.FromBytes"
4347
})
4448

4549
export const FromHex = Schema.compose(
46-
Bytes32.FromHex, // string -> Bytes32
50+
Bytes32.BytesFromHex, // string -> Bytes32
4751
FromBytes // Bytes32 -> AuxiliaryDataHash
4852
).annotations({
4953
identifier: "AuxiliaryDataHash.FromHex"

packages/evolution/src/core/BaseAddress.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export class BaseAddressError extends Data.TaggedError("BaseAddressError")<{
2121
*/
2222
export class BaseAddress extends Schema.TaggedClass<BaseAddress>("BaseAddress")("BaseAddress", {
2323
networkId: NetworkId.NetworkId,
24-
paymentCredential: Credential.Credential,
25-
stakeCredential: Credential.Credential
24+
paymentCredential: Credential.CredentialSchema,
25+
stakeCredential: Credential.CredentialSchema
2626
}) {
2727
toString(): string {
2828
return `BaseAddress { networkId: ${this.networkId}, paymentCredential: ${this.paymentCredential}, stakeCredential: ${this.stakeCredential} }`
@@ -33,7 +33,7 @@ export class BaseAddress extends Schema.TaggedClass<BaseAddress>("BaseAddress")(
3333
}
3434
}
3535

36-
export const FromBytes = Schema.transformOrFail(Bytes57.BytesSchema, BaseAddress, {
36+
export const FromBytes = Schema.transformOrFail(Bytes57.BytesSchema, Schema.typeSchema(BaseAddress), {
3737
strict: true,
3838
encode: (_, __, ___, toA) =>
3939
Eff.gen(function* () {
@@ -57,23 +57,22 @@ export const FromBytes = Schema.transformOrFail(Bytes57.BytesSchema, BaseAddress
5757
const addressType = header >> 4
5858
// Script payment, Script stake
5959
const isPaymentKey = (addressType & 0b0001) === 0
60-
const paymentCredential: Credential.Credential = isPaymentKey
60+
const paymentCredential: Credential.CredentialSchema = isPaymentKey
6161
? new KeyHash.KeyHash({
6262
hash: fromA.slice(1, 29)
6363
})
6464
: new ScriptHash.ScriptHash({
6565
hash: fromA.slice(1, 29)
6666
})
6767
const isStakeKey = (addressType & 0b0010) === 0
68-
const stakeCredential: Credential.Credential = isStakeKey
68+
const stakeCredential: Credential.CredentialSchema = isStakeKey
6969
? new KeyHash.KeyHash({
7070
hash: fromA.slice(29, 57)
7171
})
7272
: new ScriptHash.ScriptHash({
7373
hash: fromA.slice(29, 57)
7474
})
75-
return yield* ParseResult.decode(BaseAddress)({
76-
_tag: "BaseAddress",
75+
return BaseAddress.make({
7776
networkId,
7877
paymentCredential,
7978
stakeCredential

packages/evolution/src/core/Bip32PublicKey.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Bip32PublicKeyError extends Data.TaggedError("Bip32PublicKeyError")
2929
* @category schemas
3030
*/
3131
export class Bip32PublicKey extends Schema.TaggedClass<Bip32PublicKey>()("Bip32PublicKey", {
32-
bytes: Bytes64.BytesSchema
32+
bytes: Bytes64.BytesFromHex
3333
}) {
3434
toJSON(): string {
3535
return toHex(this)
@@ -46,7 +46,7 @@ export class Bip32PublicKey extends Schema.TaggedClass<Bip32PublicKey>()("Bip32P
4646
* @since 2.0.0
4747
* @category schemas
4848
*/
49-
export const FromBytes = Schema.transform(Bytes64.BytesSchema, Bip32PublicKey, {
49+
export const FromBytes = Schema.transform(Schema.typeSchema(Bytes64.BytesFromHex), Schema.typeSchema(Bip32PublicKey), {
5050
strict: true,
5151
decode: (bytes) => new Bip32PublicKey({ bytes }, { disableValidation: true }),
5252
encode: (bip32PublicKey) => bip32PublicKey.bytes
@@ -61,7 +61,7 @@ export const FromBytes = Schema.transform(Bytes64.BytesSchema, Bip32PublicKey, {
6161
* @category schemas
6262
*/
6363
export const FromHex = Schema.compose(
64-
Bytes64.FromHex, // string -> Bytes64
64+
Bytes64.BytesFromHex, // string -> Bytes64
6565
FromBytes // Bytes64 -> Bip32PublicKey
6666
).annotations({
6767
identifier: "Bip32PublicKey.FromHex"

packages/evolution/src/core/BlockBodyHash.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class BlockBodyHashError extends Data.TaggedError("BlockBodyHashError")<{
2323
* @category model
2424
*/
2525
export class BlockBodyHash extends Schema.TaggedClass<BlockBodyHash>()("BlockBodyHash", {
26-
bytes: Bytes32.BytesSchema
26+
bytes: Bytes32.BytesFromHex
2727
}) {}
2828

2929
/**
@@ -32,7 +32,7 @@ export class BlockBodyHash extends Schema.TaggedClass<BlockBodyHash>()("BlockBod
3232
* @since 2.0.0
3333
* @category schemas
3434
*/
35-
export const FromBytes = Schema.transform(Bytes32.BytesSchema, BlockBodyHash, {
35+
export const FromBytes = Schema.transform(Schema.typeSchema(Bytes32.BytesFromHex), Schema.typeSchema(BlockBodyHash), {
3636
strict: true,
3737
decode: (bytes) => new BlockBodyHash({ bytes }, { disableValidation: true }),
3838
encode: (bbh) => bbh.bytes
@@ -47,7 +47,7 @@ export const FromBytes = Schema.transform(Bytes32.BytesSchema, BlockBodyHash, {
4747
* @category schemas
4848
*/
4949
export const FromHex = Schema.compose(
50-
Bytes32.FromHex, // string -> Bytes32
50+
Bytes32.BytesFromHex, // string -> Bytes32
5151
FromBytes // Bytes32 -> BlockBodyHash
5252
).annotations({
5353
identifier: "BlockBodyHash.FromHex"

0 commit comments

Comments
 (0)