@xyo-network/xl1-protocol-sdk 1.26.11 → 1.26.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +29 -16
- package/src/ChainContextHelpers.ts +0 -50
- package/src/CreatableProvider/AbstractCreatableProvider.ts +0 -97
- package/src/CreatableProvider/CreatableProvider.ts +0 -102
- package/src/CreatableProvider/CreatableProviderRegistry.ts +0 -94
- package/src/CreatableProvider/GetInstanceOptions.ts +0 -11
- package/src/CreatableProvider/LabeledCreatableProviderFactory.ts +0 -24
- package/src/CreatableProvider/ProviderFactory.ts +0 -138
- package/src/CreatableProvider/ProviderFactoryLocator.ts +0 -170
- package/src/CreatableProvider/ProviderFactoryLocatorInstance.ts +0 -70
- package/src/CreatableProvider/index.ts +0 -8
- package/src/SignedBigInt.ts +0 -59
- package/src/_internal/context/getTestProviderContext.ts +0 -13
- package/src/_internal/context/index.ts +0 -1
- package/src/_internal/index.ts +0 -2
- package/src/actor/ActorV3.ts +0 -177
- package/src/actor/index.ts +0 -1
- package/src/amount/ShiftedBigInt.ts +0 -73
- package/src/amount/XL1Amount.ts +0 -103
- package/src/amount/index.ts +0 -4
- package/src/amount/splitOnDecimal.ts +0 -6
- package/src/amount/splitOnDecimalToString.ts +0 -40
- package/src/block/hydrate/allHashesPresent.ts +0 -8
- package/src/block/hydrate/blockPayloadsFromHydratedBlock.ts +0 -12
- package/src/block/hydrate/flattenHydratedBlock.ts +0 -28
- package/src/block/hydrate/flattenHydratedBlocks.ts +0 -7
- package/src/block/hydrate/hydrateBlock.ts +0 -43
- package/src/block/hydrate/index.ts +0 -7
- package/src/block/hydrate/transactionsFromHydratedBlock.ts +0 -7
- package/src/block/hydrate/tryHydrateBlock.ts +0 -26
- package/src/block/index.ts +0 -2
- package/src/block/primitives/blockFromBlockNumber.ts +0 -69
- package/src/block/primitives/frames/calculateFramesFromRange.ts +0 -30
- package/src/block/primitives/frames/deepCalculateFramesFromRange.ts +0 -28
- package/src/block/primitives/frames/index.ts +0 -2
- package/src/block/primitives/hashFromBlockNumber.ts +0 -9
- package/src/block/primitives/index.ts +0 -7
- package/src/block/primitives/model.ts +0 -18
- package/src/block/primitives/payloads/ChainWindow.ts +0 -7
- package/src/block/primitives/payloads/index.ts +0 -1
- package/src/block/primitives/toStepIdentityString.ts +0 -6
- package/src/block/primitives/validateTransactionOpcodes.ts +0 -45
- package/src/config/Actor.ts +0 -32
- package/src/config/Actors.ts +0 -9
- package/src/config/Base.ts +0 -27
- package/src/config/Chain.ts +0 -23
- package/src/config/Config.ts +0 -24
- package/src/config/DataLake/DataLake.ts +0 -12
- package/src/config/DataLake/DataLakeRemoteConfig.ts +0 -11
- package/src/config/DataLake/RestDataLakeConfig.ts +0 -18
- package/src/config/DataLake/RouterDataLakeConfig.ts +0 -22
- package/src/config/DataLake/index.ts +0 -4
- package/src/config/DeepPartial.ts +0 -4
- package/src/config/Evm.ts +0 -38
- package/src/config/HostActor.ts +0 -32
- package/src/config/Log.ts +0 -25
- package/src/config/Provider.ts +0 -20
- package/src/config/Providers.ts +0 -9
- package/src/config/Remote.ts +0 -59
- package/src/config/Telemetry.ts +0 -49
- package/src/config/UsageMeta.ts +0 -46
- package/src/config/Validation.ts +0 -29
- package/src/config/index.ts +0 -12
- package/src/config/storage/Storage.ts +0 -16
- package/src/config/storage/driver/Mongo.ts +0 -53
- package/src/config/storage/driver/index.ts +0 -1
- package/src/config/storage/index.ts +0 -2
- package/src/constants.ts +0 -4
- package/src/context/Actor.ts +0 -20
- package/src/context/HostActor.ts +0 -20
- package/src/context/getEmptyProviderContext.ts +0 -19
- package/src/context/index.ts +0 -3
- package/src/createDeclarationPayload.ts +0 -15
- package/src/createTransferPayload.ts +0 -16
- package/src/driver/cache/LruCacheMap.ts +0 -48
- package/src/driver/cache/index.ts +0 -1
- package/src/driver/index.ts +0 -2
- package/src/driver/memory/MemoryMap.ts +0 -48
- package/src/driver/memory/index.ts +0 -1
- package/src/eip-712/Payloads/EIP712Data.ts +0 -35
- package/src/eip-712/Payloads/EIP712Signature.ts +0 -32
- package/src/eip-712/Payloads/index.ts +0 -2
- package/src/eip-712/Types.ts +0 -41
- package/src/eip-712/index.ts +0 -4
- package/src/eip-712/sign.ts +0 -19
- package/src/eip-712/spec/fixtures.ts +0 -27
- package/src/eip-712/verify.ts +0 -20
- package/src/getFileConfig.ts +0 -36
- package/src/index.ts +0 -27
- package/src/instances/Address.ts +0 -16
- package/src/instances/BoundWitness.ts +0 -13
- package/src/instances/Data.ts +0 -4
- package/src/instances/Fees.ts +0 -9
- package/src/instances/HydratedBoundWitness.ts +0 -16
- package/src/instances/Object.ts +0 -6
- package/src/instances/Payload.ts +0 -7
- package/src/instances/Signature.ts +0 -12
- package/src/instances/block/BlockFields.ts +0 -18
- package/src/instances/block/HydratedBlock.ts +0 -10
- package/src/instances/block/index.ts +0 -1
- package/src/instances/index.ts +0 -10
- package/src/instances/modifiers/BlockWindowInstance.ts +0 -8
- package/src/instances/modifiers/BlockWindowState.ts +0 -6
- package/src/instances/modifiers/Signed.ts +0 -9
- package/src/instances/modifiers/Validatable.ts +0 -6
- package/src/instances/modifiers/index.ts +0 -4
- package/src/instances/transaction/HydratedTransaction.ts +0 -9
- package/src/instances/transaction/TransactionFields.ts +0 -22
- package/src/instances/transaction/index.ts +0 -1
- package/src/isInternetAvailable.ts +0 -11
- package/src/model/ChainFork/ChainForkStatic.ts +0 -9
- package/src/model/ChainFork/index.ts +0 -1
- package/src/model/ChainIdentity.ts +0 -6
- package/src/model/ChainStore.ts +0 -16
- package/src/model/CreatableProviderContext.ts +0 -6
- package/src/model/CreatableProviderContext.zod.ts +0 -55
- package/src/model/PayloadBundle/bundledPayloadToHydratedBlock.ts +0 -15
- package/src/model/PayloadBundle/bundledPayloadToHydratedTransaction.ts +0 -15
- package/src/model/PayloadBundle/hydratedBlockToPayloadBundle.ts +0 -19
- package/src/model/PayloadBundle/hydratedTransactionToPayloadBundle.ts +0 -19
- package/src/model/PayloadBundle/index.ts +0 -4
- package/src/model/index.ts +0 -6
- package/src/multipliers.ts +0 -18
- package/src/payloads/AddressPairPayload.ts +0 -27
- package/src/payloads/index.ts +0 -4
- package/src/payloads/netBalancesForPayloads.ts +0 -24
- package/src/payloads/netSchemasForPayloads.ts +0 -24
- package/src/payloads/netTransfersForPayloads.ts +0 -27
- package/src/primitives/block/index.ts +0 -2
- package/src/primitives/block/range/blockRangeSteps.ts +0 -23
- package/src/primitives/block/range/index.ts +0 -1
- package/src/primitives/block/rate/blockRate.ts +0 -77
- package/src/primitives/block/rate/index.ts +0 -4
- package/src/primitives/block/rate/stepRate.ts +0 -37
- package/src/primitives/block/rate/timeHelpers.ts +0 -61
- package/src/primitives/block/rate/timeRate.ts +0 -121
- package/src/primitives/chain/getWindowedChain.ts +0 -50
- package/src/primitives/chain/index.ts +0 -3
- package/src/primitives/chain/step/chainStepRewardAddress.ts +0 -30
- package/src/primitives/chain/step/index.ts +0 -4
- package/src/primitives/chain/step/stepRewardBlock.ts +0 -13
- package/src/primitives/chain/step/stepRewardTotal.ts +0 -46
- package/src/primitives/chain/step/stepsRewardTotal.ts +0 -37
- package/src/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.ts +0 -32
- package/src/primitives/chain/time/externalBlockRangeFromStep.ts +0 -21
- package/src/primitives/chain/time/externalBlockRangeFromXL1BlockRange.ts +0 -17
- package/src/primitives/chain/time/index.ts +0 -3
- package/src/primitives/datalake/addDataLakePayloads.ts +0 -18
- package/src/primitives/datalake/addDataLakePayloadsToPayloads.ts +0 -24
- package/src/primitives/datalake/index.ts +0 -2
- package/src/primitives/index.ts +0 -13
- package/src/primitives/mapToMapType.ts +0 -35
- package/src/primitives/payload/index.ts +0 -1
- package/src/primitives/payload/mergeTransfers.ts +0 -16
- package/src/primitives/readPayloadMapFromStore.ts +0 -58
- package/src/primitives/rewardFromBlockNumber.ts +0 -19
- package/src/primitives/rewards/index.ts +0 -1
- package/src/primitives/rewards/networkStakeStepRewardPositionWeight.ts +0 -26
- package/src/primitives/stake/activeStakeAtTimeByAddress.ts +0 -27
- package/src/primitives/stake/activeStakeAtTimeByPosition.ts +0 -25
- package/src/primitives/stake/allStakersForRange.ts +0 -32
- package/src/primitives/stake/allStakersForStep.ts +0 -24
- package/src/primitives/stake/index.ts +0 -6
- package/src/primitives/stake/mergedAddRemoveStakeEventsByPosition.ts +0 -15
- package/src/primitives/stake/mergedAddRemoveStakeEventsByStaker.ts +0 -17
- package/src/primitives/stake/weightedStakeForRangeByPosition.ts +0 -69
- package/src/primitives/state/findMostRecentBlock.ts +0 -44
- package/src/primitives/state/hydratedBlockByNumber.ts +0 -25
- package/src/primitives/state/index.ts +0 -2
- package/src/primitives/step/completedStepRewardAddress.ts +0 -10
- package/src/primitives/step/derivedReceiveAddress.ts +0 -9
- package/src/primitives/step/index.ts +0 -4
- package/src/primitives/step/stepBlockRange.ts +0 -9
- package/src/primitives/step/stepTransferIndex.ts +0 -19
- package/src/primitives/transaction/elevatedPayloads.ts +0 -24
- package/src/primitives/transaction/index.ts +0 -1
- package/src/primitives/uncle/findBestUncle.ts +0 -9
- package/src/primitives/uncle/findUncles.ts +0 -75
- package/src/primitives/uncle/index.ts +0 -3
- package/src/primitives/uncle/scoreUncle.ts +0 -7
- package/src/services/AccountTransfersService.ts +0 -13
- package/src/services/BlockProducerService.ts +0 -11
- package/src/services/Chain/BaseChainService.ts +0 -4
- package/src/services/Chain/ChainHeadService.ts +0 -8
- package/src/services/Chain/ChainService.ts +0 -6
- package/src/services/Chain/index.ts +0 -3
- package/src/services/Election.ts +0 -14
- package/src/services/NetworkStakeService.ts +0 -4
- package/src/services/Params.ts +0 -13
- package/src/services/PendingTransactionsService.ts +0 -7
- package/src/services/SchemasService.ts +0 -11
- package/src/services/StakeIntentService/ChainIndexingServiceStateSchema.ts +0 -50
- package/src/services/StakeIntentService/StakeIntentService.ts +0 -35
- package/src/services/StakeIntentService/index.ts +0 -2
- package/src/services/index.ts +0 -8
- package/src/simple/StakeEventsViewer/SimpleStakeEventsViewer.ts +0 -93
- package/src/simple/StakeEventsViewer/index.ts +0 -1
- package/src/simple/StakeTotalsViewer/SimpleStakeTotalsViewer.ts +0 -116
- package/src/simple/StakeTotalsViewer/index.ts +0 -1
- package/src/simple/StakeViewer/SimpleStakeViewer.ts +0 -164
- package/src/simple/StakeViewer/index.ts +0 -1
- package/src/simple/TransactionViewer/SimpleTransactionViewer.ts +0 -100
- package/src/simple/TransactionViewer/index.ts +0 -1
- package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +0 -271
- package/src/simple/accountBalance/index.ts +0 -1
- package/src/simple/block/SimpleBlockViewer.ts +0 -231
- package/src/simple/block/index.ts +0 -1
- package/src/simple/blockInvalidation/SimpleBlockInvalidationViewer.ts +0 -197
- package/src/simple/blockInvalidation/index.ts +0 -1
- package/src/simple/blockReward/SimpleBlockRewardViewer.ts +0 -27
- package/src/simple/blockReward/index.ts +0 -1
- package/src/simple/blockValidation/SimpleBlockValidationViewer.ts +0 -194
- package/src/simple/blockValidation/index.ts +0 -1
- package/src/simple/chainContractViewer/SimpleChainContractViewer.ts +0 -92
- package/src/simple/chainContractViewer/index.ts +0 -1
- package/src/simple/client/SimpleXyoClient.ts +0 -14
- package/src/simple/client/index.ts +0 -1
- package/src/simple/datalake/AbstractRestDataLake.ts +0 -70
- package/src/simple/datalake/AbstractSimpleDataLake.ts +0 -62
- package/src/simple/datalake/RestDataLakeRunner.ts +0 -54
- package/src/simple/datalake/RestDataLakeViewer.ts +0 -22
- package/src/simple/datalake/SimpleDataLakeRunner.ts +0 -44
- package/src/simple/datalake/SimpleDataLakeViewer.ts +0 -24
- package/src/simple/datalake/index.ts +0 -4
- package/src/simple/finalization/SimpleFinalizationRunner.ts +0 -45
- package/src/simple/finalization/SimpleFinalizationViewer.ts +0 -123
- package/src/simple/finalization/index.ts +0 -2
- package/src/simple/gateway/SimpleXyoGateway.ts +0 -30
- package/src/simple/gateway/SimpleXyoGatewayRunner.ts +0 -137
- package/src/simple/gateway/index.ts +0 -2
- package/src/simple/index.ts +0 -22
- package/src/simple/mempool/SimpleMempoolRunner.ts +0 -390
- package/src/simple/mempool/SimpleMempoolViewer.ts +0 -215
- package/src/simple/mempool/index.ts +0 -2
- package/src/simple/network/SimpleXyoNetwork.ts +0 -48
- package/src/simple/network/index.ts +0 -1
- package/src/simple/network/lib/FailedNetworkStatusPayloads.ts +0 -16
- package/src/simple/network/lib/StatusNetworks.ts +0 -32
- package/src/simple/network/lib/index.ts +0 -2
- package/src/simple/permissions/SimpleXyoPermissions.ts +0 -82
- package/src/simple/permissions/index.ts +0 -2
- package/src/simple/permissions/store/MemoryPermissions.ts +0 -32
- package/src/simple/permissions/store/PermissionsStore.ts +0 -17
- package/src/simple/permissions/store/index.ts +0 -2
- package/src/simple/runner/SimpleXyoRunner.ts +0 -41
- package/src/simple/runner/index.ts +0 -1
- package/src/simple/signer/SimpleXyoSigner.ts +0 -78
- package/src/simple/signer/index.ts +0 -1
- package/src/simple/timeSync2/SimpleTimeSyncViewer.ts +0 -132
- package/src/simple/timeSync2/index.ts +0 -1
- package/src/simple/transactionInvalidation/SimpleTransactionInvalidationViewer.ts +0 -197
- package/src/simple/transactionInvalidation/index.ts +0 -1
- package/src/simple/transactionValidation/SimpleTransactionValidationViewer.ts +0 -173
- package/src/simple/transactionValidation/index.ts +0 -1
- package/src/simple/windowedBlock/SimpleWindowedBlockViewer.ts +0 -207
- package/src/simple/windowedBlock/index.ts +0 -1
- package/src/status/RuntimeStatusMonitor.ts +0 -120
- package/src/status/ServiceStatus.ts +0 -21
- package/src/status/index.ts +0 -2
- package/src/summary/index.ts +0 -2
- package/src/summary/model/BalancesStepSummary.ts +0 -35
- package/src/summary/model/SchemasStepSummary.ts +0 -33
- package/src/summary/model/StepSummary.ts +0 -20
- package/src/summary/model/TransfersSummary.ts +0 -36
- package/src/summary/model/index.ts +0 -4
- package/src/summary/primitives/balances/balancesStepSummaryFromRange.ts +0 -94
- package/src/summary/primitives/balances/balancesSummary.ts +0 -48
- package/src/summary/primitives/balances/index.ts +0 -2
- package/src/summary/primitives/index.ts +0 -3
- package/src/summary/primitives/schemas/index.ts +0 -2
- package/src/summary/primitives/schemas/schemasStepSummaryFromRange.ts +0 -86
- package/src/summary/primitives/schemas/schemasSummary.ts +0 -44
- package/src/summary/primitives/transfers/index.ts +0 -2
- package/src/summary/primitives/transfers/transfersStepSummaryFromRange.ts +0 -109
- package/src/summary/primitives/transfers/transfersSummary.ts +0 -52
- package/src/test/BuildBlockOptions.ts +0 -81
- package/src/test/buildBlock.ts +0 -105
- package/src/test/buildGenesisBlock.ts +0 -29
- package/src/test/buildNextBlock.ts +0 -37
- package/src/test/buildRandomChain.ts +0 -92
- package/src/test/buildRandomGenesisBlock.ts +0 -47
- package/src/test/createGenesisBlock.ts +0 -41
- package/src/test/createProducerChainStakeIntentTransaction.ts +0 -48
- package/src/test/getSimpleBlockViewerLocator.ts +0 -41
- package/src/test/getTestProviderContext.ts +0 -8
- package/src/test/index.ts +0 -2
- package/src/time/index.ts +0 -1
- package/src/time/primitives/index.ts +0 -1
- package/src/time/primitives/xl1BlockNumberToEthBlockNumber.ts +0 -13
- package/src/transaction/TransactionBuilder.ts +0 -164
- package/src/transaction/buildRandomTransaction.ts +0 -38
- package/src/transaction/buildTransaction.ts +0 -68
- package/src/transaction/buildUnsignedTransaction.ts +0 -56
- package/src/transaction/confirmSubmittedTransaction.ts +0 -42
- package/src/transaction/hydrateTransaction.ts +0 -117
- package/src/transaction/index.ts +0 -9
- package/src/transaction/primitives/index.ts +0 -4
- package/src/transaction/primitives/transactionBlockByteCount.ts +0 -10
- package/src/transaction/primitives/transactionElevatedPayloads.ts +0 -18
- package/src/transaction/primitives/transactionOperations.ts +0 -13
- package/src/transaction/primitives/transactionRequiredGas.ts +0 -22
- package/src/transaction/script.ts +0 -48
- package/src/transaction/signTransaction.ts +0 -32
- package/src/utils/HydratedCache.ts +0 -39
- package/src/utils/index.ts +0 -2
- package/src/utils/isZodError.ts +0 -11
- package/src/validation/index.ts +0 -2
- package/src/validation/lib/getUrl.ts +0 -7
- package/src/validation/lib/index.ts +0 -2
- package/src/validation/lib/isLocalhost.ts +0 -9
- package/src/validation/schema/Address.ts +0 -2
- package/src/validation/schema/Mnemonic.ts +0 -21
- package/src/validation/schema/index.ts +0 -2
- package/src/wallet/generateXyoBaseWalletFromPhrase.ts +0 -13
- package/src/wallet/index.ts +0 -2
- package/src/wallet/paths.ts +0 -17
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { asAddress, assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import type { AccountInstance, Id } from '@xyo-network/sdk-js'
|
|
3
|
-
import {
|
|
4
|
-
Account, asAnyPayload, asSchema, IdSchema,
|
|
5
|
-
PayloadBuilder,
|
|
6
|
-
} from '@xyo-network/sdk-js'
|
|
7
|
-
import {
|
|
8
|
-
asXL1BlockNumber, type ChainId, type HydratedBlockWithHashMeta,
|
|
9
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
10
|
-
|
|
11
|
-
import { buildRandomTransaction } from '../transaction/index.ts'
|
|
12
|
-
import { buildGenesisBlock } from './buildGenesisBlock.ts'
|
|
13
|
-
|
|
14
|
-
/** TestChainId constant. */
|
|
15
|
-
export const TestChainId = assertEx(asAddress('c5fe2e6F6841Cbab12d8C0618Be2DF8C6156cC44')) as ChainId
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Creates a random block
|
|
19
|
-
* @param chainId The chain id for the block
|
|
20
|
-
* @param blockProducer The producer for the blocks
|
|
21
|
-
* @param transactionAccount The account to use for the transaction
|
|
22
|
-
* @returns A block
|
|
23
|
-
*/
|
|
24
|
-
export const buildRandomGenesisBlock = async (
|
|
25
|
-
chainId: ChainId = TestChainId,
|
|
26
|
-
blockProducer?: AccountInstance,
|
|
27
|
-
transactionAccount?: AccountInstance,
|
|
28
|
-
): Promise<HydratedBlockWithHashMeta> => {
|
|
29
|
-
const producer = blockProducer ?? (await Account.random())
|
|
30
|
-
const txAccount = transactionAccount ?? await Account.random()
|
|
31
|
-
const additionalPayload = new PayloadBuilder<Id>({ schema: IdSchema }).fields({ salt: `${Date.now()}` }).build()
|
|
32
|
-
const additionalPrivatePayload = new PayloadBuilder({ schema: asSchema('network.xyo.private', true) }).fields({ salt: `${Date.now()}` }).build()
|
|
33
|
-
const txs = [await buildRandomTransaction(
|
|
34
|
-
chainId,
|
|
35
|
-
[additionalPayload, additionalPrivatePayload],
|
|
36
|
-
txAccount,
|
|
37
|
-
asXL1BlockNumber(0, true),
|
|
38
|
-
asXL1BlockNumber(1000, true),
|
|
39
|
-
[asSchema('network.xyo.private', true)],
|
|
40
|
-
)]
|
|
41
|
-
const block = await buildGenesisBlock(chainId, txs, [], [producer])
|
|
42
|
-
const payloads = [
|
|
43
|
-
...block[1],
|
|
44
|
-
await PayloadBuilder.addHashMeta(additionalPayload),
|
|
45
|
-
]
|
|
46
|
-
return [block[0], payloads.map(p => asAnyPayload(p, true))]
|
|
47
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import type { AccountInstance, WithHashMeta } from '@xyo-network/sdk-js'
|
|
3
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
4
|
-
import type {
|
|
5
|
-
AllowedBlockPayload, ChainId, SignedHydratedBlockWithHashMeta,
|
|
6
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
7
|
-
import {
|
|
8
|
-
BlockBoundWitnessSchemaPayload, BlockBoundWitnessWithStorageMetaSchemaPayload,
|
|
9
|
-
ChainStakeIntentPayloadJsonSchemaPayload, HashPayloadJsonSchemaPayload, TransactionBoundWitnessSchemaPayload, TransactionBoundWitnessWithStorageMetaSchemaPayload, TransferPayloadJsonSchemaPayload,
|
|
10
|
-
} from '@xyo-network/xl1-schema'
|
|
11
|
-
|
|
12
|
-
import { createTransferPayload } from '../createTransferPayload.ts'
|
|
13
|
-
import { buildGenesisBlock } from './buildGenesisBlock.ts'
|
|
14
|
-
import { createProducerChainStakeIntent } from './createProducerChainStakeIntentTransaction.ts'
|
|
15
|
-
|
|
16
|
-
/** createGenesisBlock constant. */
|
|
17
|
-
export const createGenesisBlock = async (
|
|
18
|
-
initialBlockProducer: AccountInstance,
|
|
19
|
-
nextContractAddress: ChainId,
|
|
20
|
-
genesisBlockRewardAmount: bigint,
|
|
21
|
-
genesisBlockRewardAddress: Address,
|
|
22
|
-
): Promise<SignedHydratedBlockWithHashMeta> => {
|
|
23
|
-
const blockPayloads: WithHashMeta<AllowedBlockPayload>[] = await PayloadBuilder.addHashMeta([
|
|
24
|
-
TransferPayloadJsonSchemaPayload,
|
|
25
|
-
BlockBoundWitnessSchemaPayload,
|
|
26
|
-
BlockBoundWitnessWithStorageMetaSchemaPayload,
|
|
27
|
-
TransactionBoundWitnessSchemaPayload,
|
|
28
|
-
TransactionBoundWitnessWithStorageMetaSchemaPayload,
|
|
29
|
-
ChainStakeIntentPayloadJsonSchemaPayload,
|
|
30
|
-
HashPayloadJsonSchemaPayload,
|
|
31
|
-
])
|
|
32
|
-
const intentPayload = await createProducerChainStakeIntent(initialBlockProducer.address, 1, 0)
|
|
33
|
-
blockPayloads.push(intentPayload)
|
|
34
|
-
if (genesisBlockRewardAmount > 0n) {
|
|
35
|
-
blockPayloads.push(await PayloadBuilder.addHashMeta(createTransferPayload(
|
|
36
|
-
nextContractAddress as Address,
|
|
37
|
-
{ [genesisBlockRewardAddress]: genesisBlockRewardAmount },
|
|
38
|
-
)))
|
|
39
|
-
}
|
|
40
|
-
return await buildGenesisBlock(nextContractAddress, [], blockPayloads, [initialBlockProducer])
|
|
41
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import type { AccountInstance } from '@xyo-network/sdk-js'
|
|
3
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
4
|
-
import type {
|
|
5
|
-
ChainId, ChainStakeIntent,
|
|
6
|
-
HydratedTransactionWithHashMeta,
|
|
7
|
-
XL1BlockNumber,
|
|
8
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
9
|
-
import {
|
|
10
|
-
asXL1BlockNumber, ChainStakeIntentSchema,
|
|
11
|
-
defaultTransactionFees,
|
|
12
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
13
|
-
|
|
14
|
-
import { buildTransaction } from '../transaction/index.ts'
|
|
15
|
-
|
|
16
|
-
/** Creates a ProducerChainStakeIntent instance. */
|
|
17
|
-
export async function createProducerChainStakeIntent(from: Address, exp: number, nbf = 0) {
|
|
18
|
-
return await PayloadBuilder.addHashMeta(new PayloadBuilder<ChainStakeIntent>({ schema: ChainStakeIntentSchema }).fields({
|
|
19
|
-
from,
|
|
20
|
-
exp,
|
|
21
|
-
nbf,
|
|
22
|
-
intent: 'producer',
|
|
23
|
-
}).build())
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Creates a ProducerChainStakeIntentTransaction instance. */
|
|
27
|
-
export async function createProducerChainStakeIntentTransaction(
|
|
28
|
-
chain: ChainId,
|
|
29
|
-
signers: AccountInstance[] = [],
|
|
30
|
-
producer: Address,
|
|
31
|
-
exp: XL1BlockNumber,
|
|
32
|
-
nbf = asXL1BlockNumber(0, true),
|
|
33
|
-
fees = defaultTransactionFees,
|
|
34
|
-
): Promise<HydratedTransactionWithHashMeta> {
|
|
35
|
-
// Create staked intents for all the block producers declaring their intent to produce blocks
|
|
36
|
-
const intent = await createProducerChainStakeIntent(producer, exp, nbf)
|
|
37
|
-
const tx = await buildTransaction(
|
|
38
|
-
chain,
|
|
39
|
-
[intent],
|
|
40
|
-
[],
|
|
41
|
-
signers,
|
|
42
|
-
nbf,
|
|
43
|
-
exp,
|
|
44
|
-
signers[0].address,
|
|
45
|
-
fees,
|
|
46
|
-
)
|
|
47
|
-
return tx
|
|
48
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import type { ArchivistInstance } from '@xyo-network/sdk-js'
|
|
3
|
-
import { type ChainId, XYO_ZERO_ADDRESS } from '@xyo-network/xl1-protocol-lib'
|
|
4
|
-
|
|
5
|
-
import { getTestProviderContext } from '../_internal/index.ts'
|
|
6
|
-
import { type Config, ConfigZod } from '../config/index.ts'
|
|
7
|
-
import {
|
|
8
|
-
SimpleBlockViewer, SimpleChainContractViewer, SimpleFinalizationViewer,
|
|
9
|
-
} from '../simple/index.ts'
|
|
10
|
-
import { buildRandomChainArchivist } from './buildRandomChain.ts'
|
|
11
|
-
|
|
12
|
-
/** Parameters for TestSimpleBlockViewerLocator. */
|
|
13
|
-
export interface TestSimpleBlockViewerLocatorParams {
|
|
14
|
-
chainId?: ChainId
|
|
15
|
-
config?: Config
|
|
16
|
-
finalizedArchivist?: ArchivistInstance
|
|
17
|
-
minWithdrawalBlocks?: number
|
|
18
|
-
rewardsContract?: Address
|
|
19
|
-
stakingTokenAddress?: Address
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Retrieves the TestSimpleBlockViewerLocator. */
|
|
23
|
-
export async function getTestSimpleBlockViewerLocator({
|
|
24
|
-
minWithdrawalBlocks = 10,
|
|
25
|
-
config = ConfigZod.parse({}),
|
|
26
|
-
finalizedArchivist: finalizedArchivistIn,
|
|
27
|
-
rewardsContract = XYO_ZERO_ADDRESS, stakingTokenAddress = XYO_ZERO_ADDRESS,
|
|
28
|
-
}: TestSimpleBlockViewerLocatorParams) {
|
|
29
|
-
const finalizedArchivist = finalizedArchivistIn ?? await buildRandomChainArchivist()
|
|
30
|
-
const context = getTestProviderContext(config)
|
|
31
|
-
context.locator.registerMany([
|
|
32
|
-
SimpleChainContractViewer.factory<SimpleChainContractViewer>(SimpleChainContractViewer.dependencies, {
|
|
33
|
-
minWithdrawalBlocks,
|
|
34
|
-
rewardsContract,
|
|
35
|
-
stakingTokenAddress,
|
|
36
|
-
}),
|
|
37
|
-
SimpleFinalizationViewer.factory<SimpleFinalizationViewer>(SimpleFinalizationViewer.dependencies, { finalizedArchivist }),
|
|
38
|
-
SimpleBlockViewer.factory<SimpleBlockViewer>(SimpleBlockViewer.dependencies, { finalizedArchivist }),
|
|
39
|
-
])
|
|
40
|
-
return context.locator
|
|
41
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { getTestProviderContext as getTestProviderContextInternal } from '../_internal/index.ts'
|
|
2
|
-
import type { Config } from '../config/index.ts'
|
|
3
|
-
import type { CreatableProviderContext } from '../model/index.ts'
|
|
4
|
-
|
|
5
|
-
/** Retrieves the TestProviderContext. */
|
|
6
|
-
export function getTestProviderContext(config: Config): CreatableProviderContext {
|
|
7
|
-
return getTestProviderContextInternal(config)
|
|
8
|
-
}
|
package/src/test/index.ts
DELETED
package/src/time/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './primitives/index.ts'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './xl1BlockNumberToEthBlockNumber.ts'
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import type { ChainContextRead, XL1BlockNumber } from '@xyo-network/xl1-protocol-lib'
|
|
3
|
-
import { asTimePayload, TimeSchema } from '@xyo-network/xl1-protocol-lib'
|
|
4
|
-
|
|
5
|
-
import { hashFromBlockNumber, hydrateBlock } from '../../block/index.ts'
|
|
6
|
-
|
|
7
|
-
/** Xl1BlockNumberToEthBlockNumber helper function. */
|
|
8
|
-
export async function xl1BlockNumberToEthBlockNumber(context: ChainContextRead, xl1BlockNumber: XL1BlockNumber): Promise<number> {
|
|
9
|
-
const blockHash = await hashFromBlockNumber(context, xl1BlockNumber)
|
|
10
|
-
const hydratedBlock = await hydrateBlock(context, blockHash)
|
|
11
|
-
const timePayload = asTimePayload(hydratedBlock[1].find(p => p.schema === TimeSchema), { required: true })
|
|
12
|
-
return assertEx(timePayload.ethereum, () => 'No ethereum timestamp found on block')
|
|
13
|
-
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import type { Hex } from '@xylabs/sdk-js'
|
|
2
|
-
import { assertEx, Base } from '@xylabs/sdk-js'
|
|
3
|
-
import type {
|
|
4
|
-
AccountInstance, Payload, PayloadBuilderOptions,
|
|
5
|
-
} from '@xyo-network/sdk-js'
|
|
6
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
7
|
-
import type {
|
|
8
|
-
AllowedBlockPayload,
|
|
9
|
-
ChainId,
|
|
10
|
-
TransactionFeesBigInt,
|
|
11
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
12
|
-
import {
|
|
13
|
-
asXL1BlockNumber,
|
|
14
|
-
defaultTransactionFees, isAllowedBlockPayload, minTransactionFees, XYO_ZERO_ADDRESS,
|
|
15
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
16
|
-
|
|
17
|
-
import { buildTransaction } from './buildTransaction.ts'
|
|
18
|
-
import { transactionRequiredGas } from './primitives/index.ts'
|
|
19
|
-
|
|
20
|
-
/** Builder for constructing Transaction instances. */
|
|
21
|
-
export class TransactionBuilder<TPayload extends Payload> extends Base<Omit<PayloadBuilderOptions, 'schema'>> {
|
|
22
|
-
private _blockRange?: [number, number]
|
|
23
|
-
private _chain?: Hex
|
|
24
|
-
private _elevatedPayloads: AllowedBlockPayload[] = []
|
|
25
|
-
private _fees: TransactionFeesBigInt | undefined
|
|
26
|
-
private _payloads: TPayload[] = []
|
|
27
|
-
private _signers: AccountInstance[] = []
|
|
28
|
-
|
|
29
|
-
constructor(options: Omit<PayloadBuilderOptions, 'schema'> = {}) {
|
|
30
|
-
super(options)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async build() {
|
|
34
|
-
const chain = assertEx(this._chain, () => 'Chain must be set before building the transaction')
|
|
35
|
-
const fees = assertEx(this._fees, () => 'Fees must be set before building the transaction')
|
|
36
|
-
const blockRange = assertEx(this._blockRange, () => 'Block range must be set before building the transaction')
|
|
37
|
-
return await buildTransaction(
|
|
38
|
-
chain,
|
|
39
|
-
this._elevatedPayloads,
|
|
40
|
-
this._payloads,
|
|
41
|
-
this._signers,
|
|
42
|
-
asXL1BlockNumber(blockRange[0], true),
|
|
43
|
-
asXL1BlockNumber(blockRange[1], true),
|
|
44
|
-
this._signers[0]?.address,
|
|
45
|
-
fees,
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
chain(chain: ChainId) {
|
|
50
|
-
this._chain = chain
|
|
51
|
-
return this
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async dryRun() {
|
|
55
|
-
return await buildTransaction(
|
|
56
|
-
XYO_ZERO_ADDRESS,
|
|
57
|
-
this._elevatedPayloads,
|
|
58
|
-
this._payloads,
|
|
59
|
-
this._signers,
|
|
60
|
-
asXL1BlockNumber(0, true),
|
|
61
|
-
asXL1BlockNumber(1000, true),
|
|
62
|
-
this._signers[0]?.address,
|
|
63
|
-
defaultTransactionFees,
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
elevatedPayload(payload?: AllowedBlockPayload) {
|
|
68
|
-
const allowedPayload = isAllowedBlockPayload(payload) ? payload : undefined
|
|
69
|
-
const allowPayloadExists = assertEx(allowedPayload, () => 'Payload must be an AllowedBlockPayload')
|
|
70
|
-
this._elevatedPayloads.push(allowPayloadExists)
|
|
71
|
-
return this
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
elevatedPayloads(payloads?: AllowedBlockPayload[]) {
|
|
75
|
-
if (payloads)
|
|
76
|
-
for (const payload of payloads) {
|
|
77
|
-
this.elevatedPayload(payload)
|
|
78
|
-
}
|
|
79
|
-
return this
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async estimatedMinimumFees(): Promise<TransactionFeesBigInt> {
|
|
83
|
-
const tx = await this.dryRun()
|
|
84
|
-
const requiredGas = transactionRequiredGas(tx)
|
|
85
|
-
return {
|
|
86
|
-
base: minTransactionFees.base,
|
|
87
|
-
// eslint-disable-next-line unicorn/prefer-math-min-max
|
|
88
|
-
gasLimit: requiredGas > minTransactionFees.gasLimit ? requiredGas : minTransactionFees.gasLimit,
|
|
89
|
-
gasPrice: minTransactionFees.gasPrice,
|
|
90
|
-
priority: minTransactionFees.priority,
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
fees(fees: TransactionFeesBigInt) {
|
|
95
|
-
this._fees = fees
|
|
96
|
-
return this
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
payload(payload?: TPayload) {
|
|
100
|
-
this._payloads.push(payload as TPayload)
|
|
101
|
-
return this
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
payloads(payloads?: TPayload[]) {
|
|
105
|
-
if (payloads)
|
|
106
|
-
for (const payload of payloads) {
|
|
107
|
-
if (payload !== null) {
|
|
108
|
-
this.payload(payload)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return this
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
range(blockRange: [number, number]) {
|
|
115
|
-
if (blockRange.length !== 2) {
|
|
116
|
-
throw new Error('Block range must be an array of two numbers')
|
|
117
|
-
}
|
|
118
|
-
this._blockRange = blockRange
|
|
119
|
-
return this
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async removeElevatedPayload(payload: AllowedBlockPayload) {
|
|
123
|
-
const hash = await PayloadBuilder.hash(payload)
|
|
124
|
-
const existingHashes = await PayloadBuilder.hashes(this._elevatedPayloads)
|
|
125
|
-
|
|
126
|
-
// no async after this point to prevent changing _elevatedPayloads from other promise
|
|
127
|
-
const existingPayloadIndex = existingHashes.indexOf(hash)
|
|
128
|
-
if (existingPayloadIndex === -1) {
|
|
129
|
-
throw new Error('Payload not found in the transaction')
|
|
130
|
-
}
|
|
131
|
-
this._elevatedPayloads = this._elevatedPayloads.filter((_, index) => index !== existingPayloadIndex)
|
|
132
|
-
return this
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async removePayload(payload: TPayload) {
|
|
136
|
-
const hash = await PayloadBuilder.hash(payload)
|
|
137
|
-
const existingHashes = await PayloadBuilder.hashes(this._payloads)
|
|
138
|
-
|
|
139
|
-
// no async after this point to prevent changing _payloads from other promise
|
|
140
|
-
const existingPayloadIndex = existingHashes.indexOf(hash)
|
|
141
|
-
if (existingPayloadIndex === -1) {
|
|
142
|
-
throw new Error('Payload not found in the transaction')
|
|
143
|
-
}
|
|
144
|
-
this._payloads = this._payloads.filter((_, index) => index !== existingPayloadIndex)
|
|
145
|
-
return this
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
signer(signer?: AccountInstance) {
|
|
149
|
-
if (signer) {
|
|
150
|
-
this._signers.push(signer)
|
|
151
|
-
}
|
|
152
|
-
return this
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
signers(signers?: (AccountInstance | null)[]) {
|
|
156
|
-
if (signers)
|
|
157
|
-
for (const signer of signers) {
|
|
158
|
-
if (signer !== null) {
|
|
159
|
-
this.signer(signer)
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return this
|
|
163
|
-
}
|
|
164
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
AccountInstance, Payload, Schema,
|
|
4
|
-
} from '@xyo-network/sdk-js'
|
|
5
|
-
import { Account } from '@xyo-network/sdk-js'
|
|
6
|
-
import type {
|
|
7
|
-
AllowedBlockPayload, ChainId,
|
|
8
|
-
SignedHydratedTransactionWithHashMeta,
|
|
9
|
-
Transfer,
|
|
10
|
-
XL1BlockNumber,
|
|
11
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
12
|
-
import { asXL1BlockNumber, isAllowedBlockPayload } from '@xyo-network/xl1-protocol-lib'
|
|
13
|
-
|
|
14
|
-
import { createTransferPayload } from '../createTransferPayload.ts'
|
|
15
|
-
import { buildTransaction } from './buildTransaction.ts'
|
|
16
|
-
|
|
17
|
-
/** buildRandomTransaction constant. */
|
|
18
|
-
export const buildRandomTransaction = async (
|
|
19
|
-
chain: ChainId,
|
|
20
|
-
payloads?: Payload[],
|
|
21
|
-
account?: AccountInstance,
|
|
22
|
-
nbf: XL1BlockNumber = asXL1BlockNumber(0, true),
|
|
23
|
-
exp: XL1BlockNumber = asXL1BlockNumber(nbf + 1000, true),
|
|
24
|
-
privatePayloadSchemas: Schema[] = [],
|
|
25
|
-
receiverAddress?: Address,
|
|
26
|
-
): Promise<SignedHydratedTransactionWithHashMeta> => {
|
|
27
|
-
const elevatedPayloads: AllowedBlockPayload[] = (payloads ?? []).filter(isAllowedBlockPayload)
|
|
28
|
-
const additionalPayloads: Payload[] = (payloads ?? []).filter(payload => !isAllowedBlockPayload(payload))
|
|
29
|
-
const sender = account ?? await Account.random()
|
|
30
|
-
if (elevatedPayloads?.length === 0) {
|
|
31
|
-
const receiver = receiverAddress ?? (await Account.random()).address
|
|
32
|
-
const transferPayload: Transfer = createTransferPayload(sender.address, { [receiver]: 1n })
|
|
33
|
-
elevatedPayloads.push(transferPayload)
|
|
34
|
-
}
|
|
35
|
-
const hydratedTransaction = await buildTransaction(chain, elevatedPayloads, additionalPayloads, sender, nbf, exp)
|
|
36
|
-
// remove private payloads from hydrated
|
|
37
|
-
return [hydratedTransaction[0], hydratedTransaction[1].filter(p => !privatePayloadSchemas.includes(p.schema))]
|
|
38
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import { assertEx, toHex } from '@xylabs/sdk-js'
|
|
3
|
-
import type { AccountInstance, Payload } from '@xyo-network/sdk-js'
|
|
4
|
-
import {
|
|
5
|
-
asAnyPayload, BoundWitnessBuilder, PayloadBuilder,
|
|
6
|
-
} from '@xyo-network/sdk-js'
|
|
7
|
-
import type {
|
|
8
|
-
AllowedBlockPayload,
|
|
9
|
-
ChainId,
|
|
10
|
-
ExecutableFields,
|
|
11
|
-
FromFields,
|
|
12
|
-
SignedHydratedTransactionWithHashMeta,
|
|
13
|
-
TransactionBoundWitness, TransactionBoundWitnessFields, TransactionFeesBigInt,
|
|
14
|
-
XL1BlockNumber,
|
|
15
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
16
|
-
import { defaultTransactionFees } from '@xyo-network/xl1-protocol-lib'
|
|
17
|
-
|
|
18
|
-
/** Builds a Transaction instance. */
|
|
19
|
-
export async function buildTransaction(
|
|
20
|
-
chain: ChainId,
|
|
21
|
-
onChainPayloads: AllowedBlockPayload[],
|
|
22
|
-
offChainPayloads: Payload[],
|
|
23
|
-
signer: AccountInstance | AccountInstance[],
|
|
24
|
-
nbf: XL1BlockNumber,
|
|
25
|
-
exp: XL1BlockNumber,
|
|
26
|
-
from?: Address,
|
|
27
|
-
fees: TransactionFeesBigInt = defaultTransactionFees,
|
|
28
|
-
): Promise<SignedHydratedTransactionWithHashMeta> {
|
|
29
|
-
if (from === undefined && Array.isArray(signer)) {
|
|
30
|
-
throw new Error('from is required when signer is an array')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const txBoundWitnessFields: Omit<TransactionBoundWitnessFields, 'from'> = {
|
|
34
|
-
chain,
|
|
35
|
-
fees: {
|
|
36
|
-
base: toHex(fees.base),
|
|
37
|
-
gasLimit: toHex(fees.gasLimit),
|
|
38
|
-
gasPrice: toHex(fees.gasPrice),
|
|
39
|
-
priority: toHex(fees.priority),
|
|
40
|
-
},
|
|
41
|
-
nbf,
|
|
42
|
-
exp,
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const elevatedHashes = await PayloadBuilder.hashes(onChainPayloads)
|
|
46
|
-
const script: string[] = []
|
|
47
|
-
for (const elevatedHash of elevatedHashes) {
|
|
48
|
-
script.push(`elevate|${elevatedHash}`)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const fields: TransactionBoundWitnessFields & FromFields & Partial<ExecutableFields> = {
|
|
52
|
-
...txBoundWitnessFields,
|
|
53
|
-
from: from ?? (Array.isArray(signer) ? assertEx(signer.at(0)?.address) : signer.address),
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (script.length > 0) {
|
|
57
|
-
fields.script = script
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const [tx, txPayloads] = await new BoundWitnessBuilder<TransactionBoundWitness>()
|
|
61
|
-
.fields(fields)
|
|
62
|
-
.meta({ $signatures: [] })
|
|
63
|
-
.payloads([...onChainPayloads, ...offChainPayloads])
|
|
64
|
-
.signers(Array.isArray(signer) ? signer : [signer])
|
|
65
|
-
.build()
|
|
66
|
-
|
|
67
|
-
return [await PayloadBuilder.addHashMeta(tx), await PayloadBuilder.addHashMeta(txPayloads.map(p => asAnyPayload(p, true)))]
|
|
68
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import { toHex } from '@xylabs/sdk-js'
|
|
3
|
-
import type { Payload } from '@xyo-network/sdk-js'
|
|
4
|
-
import { BoundWitnessBuilder, PayloadBuilder } from '@xyo-network/sdk-js'
|
|
5
|
-
import type {
|
|
6
|
-
AllowedBlockPayload, ChainId, ExecutableFields, FromFields, TransactionBoundWitness, TransactionBoundWitnessFields, TransactionFeesBigInt,
|
|
7
|
-
UnsignedHydratedTransaction,
|
|
8
|
-
XL1BlockNumber,
|
|
9
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
10
|
-
import { defaultTransactionFees } from '@xyo-network/xl1-protocol-lib'
|
|
11
|
-
|
|
12
|
-
/** Builds a UnsignedTransaction instance. */
|
|
13
|
-
export async function buildUnsignedTransaction(
|
|
14
|
-
chain: ChainId,
|
|
15
|
-
onChainPayloads: AllowedBlockPayload[],
|
|
16
|
-
offChainPayloads: Payload[],
|
|
17
|
-
nbf: XL1BlockNumber,
|
|
18
|
-
exp: XL1BlockNumber,
|
|
19
|
-
from: Address,
|
|
20
|
-
fees: TransactionFeesBigInt = defaultTransactionFees,
|
|
21
|
-
): Promise<UnsignedHydratedTransaction> {
|
|
22
|
-
const txBoundWitnessFields: Omit<TransactionBoundWitnessFields, 'from'> = {
|
|
23
|
-
chain,
|
|
24
|
-
fees: {
|
|
25
|
-
base: toHex(fees.base),
|
|
26
|
-
gasLimit: toHex(fees.gasLimit),
|
|
27
|
-
gasPrice: toHex(fees.gasPrice),
|
|
28
|
-
priority: toHex(fees.priority),
|
|
29
|
-
},
|
|
30
|
-
nbf,
|
|
31
|
-
exp,
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const elevatedHashes = await PayloadBuilder.hashes(onChainPayloads)
|
|
35
|
-
const script: string[] = []
|
|
36
|
-
for (const elevatedHash of elevatedHashes) {
|
|
37
|
-
script.push(`elevate|${elevatedHash}`)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const fields: TransactionBoundWitnessFields & FromFields & Partial<ExecutableFields> = {
|
|
41
|
-
...txBoundWitnessFields,
|
|
42
|
-
from,
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (script.length > 0) {
|
|
46
|
-
fields.script = script
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const [tx, txPayloads] = await new BoundWitnessBuilder<TransactionBoundWitness>()
|
|
50
|
-
.fields(fields)
|
|
51
|
-
.meta({ $signatures: [] })
|
|
52
|
-
.payloads([...onChainPayloads, ...offChainPayloads])
|
|
53
|
-
.build(false)
|
|
54
|
-
|
|
55
|
-
return [tx, txPayloads]
|
|
56
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { delay, isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import type {
|
|
4
|
-
ConfirmSubmittedTransactionOptions, SignedHydratedTransaction,
|
|
5
|
-
XyoViewer,
|
|
6
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
7
|
-
|
|
8
|
-
const DEFAULT_CONFIRMATION_ATTEMPTS = 20
|
|
9
|
-
const DEFAULT_DELAY_BETWEEN_ATTEMPTS = 1000 // milliseconds
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Confirms a submitted transaction by checking if it has been included in the blockchain.
|
|
13
|
-
* @param viewer The viewer
|
|
14
|
-
* @param txHash The hash of the transaction to confirm
|
|
15
|
-
* @param options Options for confirmation
|
|
16
|
-
* @returns The confirmed transaction or throws an error if not confirmed
|
|
17
|
-
*/
|
|
18
|
-
export const confirmSubmittedTransaction = async (
|
|
19
|
-
viewer: XyoViewer,
|
|
20
|
-
txHash: Hash,
|
|
21
|
-
options?: ConfirmSubmittedTransactionOptions,
|
|
22
|
-
): Promise<SignedHydratedTransaction> => {
|
|
23
|
-
const { attempts: maxAttempts = DEFAULT_CONFIRMATION_ATTEMPTS, delay: attemptDelay = DEFAULT_DELAY_BETWEEN_ATTEMPTS } = options ?? {}
|
|
24
|
-
options?.logger?.log('🚀 confirming transaction:', txHash, '\n')
|
|
25
|
-
let attempts = 0
|
|
26
|
-
while (true) {
|
|
27
|
-
const tx = await viewer.transaction.byHash(txHash) ?? undefined
|
|
28
|
-
if (isDefined(tx)) {
|
|
29
|
-
options?.logger?.log('✅ Transaction confirmed:', txHash, '\n')
|
|
30
|
-
return tx
|
|
31
|
-
} else {
|
|
32
|
-
attempts++
|
|
33
|
-
if (attempts > maxAttempts) {
|
|
34
|
-
options?.logger?.error(`⚠️ Transaction not confirmed after ${maxAttempts} attempts`)
|
|
35
|
-
throw new Error(`Transaction ${txHash} not confirmed after ${maxAttempts} attempts`)
|
|
36
|
-
} else {
|
|
37
|
-
options?.logger?.log(`🔄 Transaction not confirmed yet, attempt ${attempts}. Retrying...`, '\n')
|
|
38
|
-
await delay(attemptDelay)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|