-
Notifications
You must be signed in to change notification settings - Fork 16
/
txOther.ts
88 lines (79 loc) · 2.54 KB
/
txOther.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
import { InvalidDataReason } from "../../errors/invalidDataReason"
import type { Int64_str, ParsedAssetGroup, ParsedInput, ParsedToken, ParsedWithdrawal, Uint32_t, Uint64_str, ValidBIP32Path, Version } from "../../types/internal"
import { StakeCredentialType } from "../../types/internal"
import { assert } from "../../utils/assert"
import { hex_to_buf, path_to_buf, stake_credential_to_buf,uint32_to_buf, uint64_to_buf } from "../../utils/serialize"
import { getCompatibility } from "../getVersion"
import type {SerializeTokenAmountFn} from "../signTx"
export function serializeTxInput(
input: ParsedInput
) {
return Buffer.concat([
hex_to_buf(input.txHashHex),
uint32_to_buf(input.outputIndex),
])
}
export function serializeTxWithdrawal(
withdrawal: ParsedWithdrawal,
version: Version,
) {
if (getCompatibility(version).supportsMultisigTransaction) {
return Buffer.concat([
uint64_to_buf(withdrawal.amount),
stake_credential_to_buf(withdrawal.stakeCredential),
])
} else {
// pre-multisig
assert(withdrawal.stakeCredential.type === StakeCredentialType.KEY_PATH, InvalidDataReason.WITHDRAWAL_INVALID_STAKE_CREDENTIAL)
return Buffer.concat([
uint64_to_buf(withdrawal.amount),
path_to_buf(withdrawal.stakeCredential.path),
])
}
}
export function serializeTxFee(
fee: Uint64_str
) {
return Buffer.concat([
uint64_to_buf(fee),
])
}
export function serializeTxTtl(
ttl: Uint64_str
) {
return Buffer.concat([
uint64_to_buf(ttl),
])
}
export function serializeTxValidityStart(
validityIntervalStart: Uint64_str
) {
return Buffer.concat([
uint64_to_buf(validityIntervalStart),
])
}
export function serializeTxWitnessRequest(
path: ValidBIP32Path
) {
return Buffer.concat([
path_to_buf(path),
])
}
export function serializeAssetGroup<T>(assetGroup: ParsedAssetGroup<T>) {
return Buffer.concat([
hex_to_buf(assetGroup.policyIdHex),
uint32_to_buf(assetGroup.tokens.length as Uint32_t),
])
}
export function serializeToken<T>(token: ParsedToken<T>, serializeTokenAmountFn: SerializeTokenAmountFn<T>) {
return Buffer.concat([
uint32_to_buf(token.assetNameHex.length / 2 as Uint32_t),
hex_to_buf(token.assetNameHex),
serializeTokenAmountFn(token.amount),
])
}
export function serializeMintBasicParams(mint: Array<ParsedAssetGroup<Int64_str>>) {
return Buffer.concat([
uint32_to_buf(mint.length as Uint32_t),
])
}