Skip to content

Commit

Permalink
Use newly added Nimiq SDK enums for hardcoded values again
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Jan 13, 2025
1 parent 432abc8 commit 492331b
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/components/Network.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Network extends Vue {
value,
fee = 0,
validityStartHeight,
flags = 0 /* Nimiq.Transaction.Flag.NONE */,
flags = Nimiq.TransactionFlag.None,
recipientData,
signerPubKey,
signature,
Expand Down Expand Up @@ -51,12 +51,11 @@ class Network extends Vue {
(recipientData && recipientData.length > 0)
|| senderType !== Nimiq.AccountType.Basic
|| recipientType !== Nimiq.AccountType.Basic
|| flags !== 0 /* Nimiq.Transaction.Flag.NONE */
|| flags !== Nimiq.TransactionFlag.None
) {
let proof: Nimiq.SerialBuffer | undefined;
if (signature) {
// 1 type + 32 publicKey + 1 empty merkle path + 64 signature
proof = new Nimiq.SerialBuffer(proofPrefix.length + 1 + 32 + 1 + 64);
proof = new Nimiq.SerialBuffer(proofPrefix.length + Nimiq.SignatureProof.SINGLE_SIG_SIZE);
proof.write(proofPrefix);
proof.write(Nimiq.SignatureProof.singleSig(signerPubKey, signature).serialize());
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Cashlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class Cashlink {
this.address, Nimiq.AccountType.Basic, new Uint8Array(0),
recipient, recipientType, CashlinkExtraData.CLAIMING,
BigInt(balance - fee), BigInt(fee),
0 /* Nimiq.Transaction.Flag.NONE */,
Nimiq.TransactionFlag.None,
await this._getBlockchainHeight(),
await (await this._getNetwork()).getNetworkId(),
);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/LedgerSwapProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default class LedgerSwapProxy {

private static _getOriginalLocalSignerPublicKey(proxyFundingDataHex: string): Nimiq.PublicKey | null {
const expectedDataHexLength =
(LedgerSwapProxyMarker.FUND.length + 32 /* Nimiq.PublicKey.SIZE */) * 2; // * 2 for hex
(LedgerSwapProxyMarker.FUND.length + Nimiq.PublicKey.SIZE) * 2; // * 2 for hex
if (proxyFundingDataHex.length !== expectedDataHexLength
|| !proxyFundingDataHex.startsWith(Nimiq.BufferUtils.toHex(LedgerSwapProxyMarker.FUND))) return null;
return new Nimiq.PublicKey(Nimiq.BufferUtils.fromHex(
Expand Down
4 changes: 2 additions & 2 deletions src/lib/RequestParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class RequestParser {
data: typeof signTransactionRequest.extraData === 'string'
? Utf8Tools.stringToUtf8ByteArray(signTransactionRequest.extraData)
: signTransactionRequest.extraData || new Uint8Array(0),
flags: signTransactionRequest.flags || 0 /* Nimiq.Transaction.Flag.NONE */,
flags: signTransactionRequest.flags || Nimiq.TransactionFlag.None,
validityStartHeight: signTransactionRequest.validityStartHeight,
} as ParsedSignTransactionRequest;
case RequestType.SIGN_STAKING:
Expand Down Expand Up @@ -171,7 +171,7 @@ export class RequestParser {
sender: checkoutRequest.sender,
forceSender: !!checkoutRequest.forceSender,
fee: checkoutRequest.fee || 0,
flags: checkoutRequest.flags || 0 /* Nimiq.Transaction.Flag.NONE */,
flags: checkoutRequest.flags || Nimiq.TransactionFlag.None,
validityDuration: checkoutRequest.validityDuration,
},
})],
Expand Down
6 changes: 3 additions & 3 deletions src/lib/paymentOptions/NimiqPaymentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class ParsedNimiqDirectPaymentOptions extends ParsedPaymentOptions<Curren

const requiresExtendedTransaction = extraData && extraData.byteLength > 0
|| (recipientType !== undefined && recipientType !== Nimiq.AccountType.Basic)
|| (flags !== undefined && flags !== 0 /* Nimiq.Transaction.Flag.NONE */);
|| (flags !== undefined && flags !== Nimiq.TransactionFlag.None);
// Note that the transaction size can be bigger than this, for example if the sender type the user wants
// to use requires an extended transaction or if an extended transaction includes a multi signature proof.
// The size is therefore just an estimate. In the majority of cases the estimate will be accurate though
Expand Down Expand Up @@ -114,7 +114,7 @@ export class ParsedNimiqDirectPaymentOptions extends ParsedPaymentOptions<Curren
if (this.parserFlags.isPointOfSale && (
options.protocolSpecific.forceSender
|| (recipientType !== undefined && recipientType !== Nimiq.AccountType.Basic)
|| (flags !== undefined && flags !== 0 /* Nimiq.Transaction.Flag.NONE */)
|| (flags !== undefined && flags !== Nimiq.TransactionFlag.None)
|| (extraData && !Utf8Tools.isValidUtf8(extraData)) // only allow string data
)) {
throw new Error('isPointOfSale was set but requested sender, recipientType, flags or extraData can not '
Expand All @@ -127,7 +127,7 @@ export class ParsedNimiqDirectPaymentOptions extends ParsedPaymentOptions<Curren
fee,
feePerByte,
extraData,
flags: flags || 0 /* Nimiq.Transaction.Flag.NONE */,
flags: flags || Nimiq.TransactionFlag.None,
recipient,
recipientType,
validityDuration: !options.protocolSpecific.validityDuration
Expand Down
2 changes: 1 addition & 1 deletion src/views/SetupSwapSuccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
recipient: new Nimiq.Address(new Uint8Array(20)),
recipientType: Nimiq.AccountType.HTLC,
recipientData: htlcInfo.fund.htlcData,
flags: 1 /* Nimiq.Transaction.Flag.CONTRACT_CREATION */,
flags: Nimiq.TransactionFlag.ContractCreation,
signerPubKey: nimiqSignatureResult.publicKey,
signature: nimiqSignatureResult.signature,
});
Expand Down
4 changes: 2 additions & 2 deletions src/views/SignTransactionLedger.vue
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export default class SignTransactionLedger extends Vue {
({ recipient, value, fee } = this.cashlink!.getFundingDetails());
validityStartHeightPromise = network.getBlockchainHeight().then((blockchainHeight) => blockchainHeight + 1);
recipientData = CASHLINK_FUNDING_DATA;
flags = 0 /* Nimiq.Transaction.Flag.NONE */;
flags = Nimiq.TransactionFlag.None;
this.recipientDetails = {
address: this.cashlink.address.toUserFriendlyAddress(),
Expand Down Expand Up @@ -583,7 +583,7 @@ export default class SignTransactionLedger extends Vue {
}
// tslint:disable-next-line no-bitwise
if ((flags & 1 /* Nimiq.Transaction.Flag.CONTRACT_CREATION */) > 0) {
if ((flags & Nimiq.TransactionFlag.ContractCreation) > 0) {
// TODO: Decode contract creation transactions
// return ...
}
Expand Down

0 comments on commit 492331b

Please sign in to comment.