/
types.ts
104 lines (90 loc) · 3.39 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { Cardano } from '@cardano-sdk/core';
import { InputSelectionError } from '@cardano-sdk/cip2';
import { SignTransactionOptions } from '../KeyManagement';
type DeepPartial<T> = T extends object
? {
[P in keyof T]?: DeepPartial<T[P]>;
}
: T;
export type WalletNotInitializedError = {};
export type ValueValidationError = {} | WalletNotInitializedError;
export type TxOutValidationError = ValueValidationError;
export type TxBodyValidationError = TxOutValidationError | InputSelectionError;
export type Valid<TValid> = TValid & {
isValid: true;
};
export interface Invalid<TError> {
isValid: false;
errors: TError[];
}
export interface ValidTxOutData {
readonly txOut: Cardano.TxOut;
}
export type ValidTxOut = Valid<ValidTxOutData>;
export type InvalidTxOut = Invalid<TxOutValidationError>;
export type MaybeValidTxOut = ValidTxOut | InvalidTxOut;
export interface OutputBuilder {
partialOutput: DeepPartial<Cardano.TxOut>;
value(value: Cardano.Value): OutputBuilder;
/**
* Does not setValue
*/
coin(coin: Cardano.Lovelace): OutputBuilder;
assets(assets: Cardano.TokenMap): OutputBuilder;
/**
* @param quantity To remove an asset, set quantity to 0
*/
asset(assetId: Cardano.AssetId, quantity: bigint): OutputBuilder;
address(address: Cardano.Address): OutputBuilder;
datum(datum: Cardano.util.Hash32ByteBase16): OutputBuilder;
build(): Promise<MaybeValidTxOut>;
}
export interface SignedTx {
readonly tx: Cardano.NewTxAlonzo;
submit(): Promise<void>;
}
export interface ValidTxBody {
readonly body: Cardano.NewTxBodyAlonzo;
readonly auxiliaryData?: Cardano.AuxiliaryData;
readonly extraWitness?: Partial<Cardano.Witness>;
sign(props?: SignTransactionOptions): Promise<SignedTx>;
}
export type ValidTx = Valid<ValidTxBody>;
export type InvalidTx = Invalid<TxBodyValidationError>;
export type MaybeValidTx = ValidTx | InvalidTx;
export interface TxBuilder {
partialTxBody: Partial<Cardano.NewTxBodyAlonzo>;
auxiliaryData?: Cardano.AuxiliaryData;
extraWitness?: Partial<Cardano.Witness>;
addOutput(txOut: Cardano.TxOut): TxBuilder;
/**
* @param txOut must be in partialTxBody.outputs (===)
*/
removeOutput(txOut: Cardano.TxOut): TxBuilder;
/**
* Does not addOutput
*/
buildOutput(txOut?: DeepPartial<Cardano.TxOut>): OutputBuilder;
/**
* Add StakeDelegation and (if needed) StakeKeyRegistration certificate
*/
delegate(poolId: Cardano.PoolId): TxBuilder;
setMetadata(metadata: Cardano.TxMetadata): TxBuilder;
// REVIEW: a design decision here:
// - if this is async, then
// - buildTx(wallet) can be sync.
// - it uses more up-to-date wallet state when building a tx, which is good
// - if this is sync, then
// - buildTx(wallet) must be async and capture a snapshot of wallet state
// at the point when builder is created
build(): Promise<MaybeValidTx>;
// REVIEW: assuming fields below are not needed for Lace right now, so out of scope of MVP:
// - setMint
// TODO: maybe this, or maybe datum should be added together with an output?
// collaterals should be automatically computed and added to tx when you add scripts
// - setScripts(scripts: Array<{script, datum, redeemer}>)
// - setValidityInterval
// TODO: figure out what script_data_hash is used for
// - setScriptIntegrityHash(hash: Cardano.Hash32ByteBase16 | null);
// - setRequiredExtraSignatures(keyHashes: Cardano.Ed25519KeyHash[]);
}