• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

proximax-storage / tsjs-xpx-chain-sdk / 5722694066

pending completion
5722694066

push

github

web-flow
Merge pull request #159 from proximax-storage/next

add storage transactions support

1167 of 2568 branches covered (45.44%)

Branch coverage included in aggregate %.

1604 of 1604 new or added lines in 66 files covered. (100.0%)

8621 of 11167 relevant lines covered (77.2%)

155987.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

15.09
/src/model/transaction/storage/NewDataModificationTransaction.ts
1
/*
2
 * Copyright 2023 ProximaX
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
import { Builder } from '../../../infrastructure/builders/storage/NewDataModificationTransaction';
1✔
18
import {VerifiableTransaction} from '../../../infrastructure/builders/VerifiableTransaction';
19
import { PublicAccount } from '../../account/PublicAccount';
20
import { NetworkType } from '../../blockchain/NetworkType';
21
import { UInt64 } from '../../UInt64';
22
import { Deadline } from '../Deadline';
23
import { Transaction, TransactionBuilder } from '../Transaction';
1✔
24
import { TransactionInfo } from '../TransactionInfo';
25
import { TransactionType } from '../TransactionType';
1✔
26
import { TransactionTypeVersion } from '../TransactionTypeVersion';
1✔
27
import { calculateFee } from '../FeeCalculationStrategy';
1✔
28
import { Convert } from '../../../core/format/Convert';
1✔
29

30
export class NewDataModificationTransaction extends Transaction {
1✔
31

32
    /**
33
     * Create a new replicator onboarding transaction object
34
     * @param deadline - The deadline to include the transaction.
35
     * @param driveKey - The drive key
36
     * @param downloadDataCdi - The download data CDI hash
37
     * @param uploadSize - The upload size
38
     * @param feedbackFeeAmount - The feedback fee amount.
39
     * @param networkType - The network type.
40
     * @param maxFee - (Optional) Max fee defined by the sender
41
     * @returns {NewDataModificationTransaction}
42
     */
43
    public static create(deadline: Deadline,
44
                         driveKey: PublicAccount,
45
                         downloadDataCdi: string,
46
                         uploadSize: UInt64,
47
                         feedbackFeeAmount: UInt64,
48
                         networkType: NetworkType,
49
                         maxFee?: UInt64): NewDataModificationTransaction {
50
        
51
        return new NewDataModificationTransactionBuilder()
×
52
            .networkType(networkType)
53
            .deadline(deadline)
54
            .driveKey(driveKey)
55
            .downloadDataCdi(downloadDataCdi)
56
            .uploadSize(uploadSize)
57
            .feedbackFeeAmount(feedbackFeeAmount)
58
            .maxFee(maxFee)
59
            .build();
60
    }
61

62
    /**
63
     * @param networkType
64
     * @param version
65
     * @param deadline
66
     * @param maxFee
67
     * @param driveKey - Public key of the drive
68
     * @param downloadDataCdi - Download data CDI of modification hash
69
     * @param uploadSize - Size of upload in MB
70
     * @param feedbackFeeAmount - Amount of XPXs to transfer to the drive
71
     * @param signature
72
     * @param signer
73
     * @param transactionInfo
74
     */
75
    constructor(networkType: NetworkType,
76
                version: number,
77
                deadline: Deadline,
78
                maxFee: UInt64,
79
                public readonly driveKey: PublicAccount,
×
80
                public readonly downloadDataCdi: string,
×
81
                public readonly uploadSize: UInt64,
×
82
                public readonly feedbackFeeAmount: UInt64,
×
83
                signature?: string,
84
                signer?: PublicAccount,
85
                transactionInfo?: TransactionInfo) {
86

87
        super(TransactionType.Data_Modification,
×
88
              networkType, version, deadline, maxFee, signature, signer, transactionInfo);
89
    
90
        if(!Convert.isHexString(downloadDataCdi) && downloadDataCdi.length !== 64 ){
×
91
            throw new Error("downloadDataCdi should be 32 bytes hash string")
×
92
        }
93

94
        if(uploadSize.toBigInt() <= BigInt(0)){
×
95
            throw new Error("uploadSize should be positive value")
×
96
        }
97

98
        if(feedbackFeeAmount.toBigInt() <= BigInt(0)){
×
99
            throw new Error("feedbackFeeAmount should be positive value")
×
100
        }
101
    }
102

103
    /**
104
     * @override Transaction.size()
105
     * @description get the byte size of a NewDataModificationTransaction
106
     * @returns {number}
107
     * @memberof NewDataModificationTransaction
108
     */
109
    public get size(): number {
110
        return NewDataModificationTransaction.calculateSize();
×
111
    }
112

113
    public static calculateSize(): number {
114
        const baseByteSize = Transaction.getHeaderSize();
×
115

116
        // set static byte size fields
117
        const driveKeySize = 32;
×
118
        const downloadDataCdiSize = 32;
×
119
        const uploadSizeSize = 8;
×
120
        const feedbackFeeAmountSize = 8;
×
121

122
        return baseByteSize + driveKeySize + downloadDataCdiSize + uploadSizeSize + feedbackFeeAmountSize;
×
123
    }
124

125
    /**
126
     * @override Transaction.toJSON()
127
     * @description Serialize a transaction object - add own fields to the result of Transaction.toJSON()
128
     * @return {Object}
129
     * @memberof NewDataModificationTransaction
130
     */
131
    public toJSON() {
132
        const parent = super.toJSON();
×
133
        return {
×
134
            ...parent,
135
            transaction: {
136
                ...parent.transaction,
137
                driveKey: this.driveKey.toDTO(),
138
                downloadDataCdi: this.downloadDataCdi,
139
                uploadSize: this.uploadSize.toDTO(),
140
                feedbackFeeAmount: this.feedbackFeeAmount.toDTO()
141
            }
142
        }
143
    }
144

145
    /**
146
     * @internal
147
     * @returns {VerifiableTransaction}
148
     */
149
    protected buildTransaction(): VerifiableTransaction {
150
        return new Builder()
×
151
            .addSize(this.size)
152
            .addDeadline(this.deadline.toDTO())
153
            .addMaxFee(this.maxFee.toDTO())
154
            .addVersion(this.versionToDTO())
155
            .addDriveKey(this.driveKey.publicKey)
156
            .addDownloadDataCdi(this.downloadDataCdi)
157
            .addUploadSize(this.uploadSize.toDTO())
158
            .addFeedbackFeeAmount(this.feedbackFeeAmount.toDTO())
159
            .build();
160
    }
161
}
162

163
export class NewDataModificationTransactionBuilder extends TransactionBuilder {
1✔
164
    private _driveKey: PublicAccount;
165
    private _downloadDataCdi: string;
166
    private _uploadSize: UInt64;
167
    private _feedbackFeeAmount: UInt64;
168

169
    public driveKey(driveKey: PublicAccount) {
170
        this._driveKey = driveKey;
×
171
        return this;
×
172
    }
173

174
    public downloadDataCdi(downloadDataCdi: string) {
175
        this._downloadDataCdi = downloadDataCdi;
×
176
        return this;
×
177
    }
178

179
    public uploadSize(uploadSize: UInt64) {
180
        this._uploadSize = uploadSize;
×
181
        return this;
×
182
    }
183

184
    public feedbackFeeAmount(feedbackFeeAmount: UInt64) {
185
        this._feedbackFeeAmount = feedbackFeeAmount;
×
186
        return this;
×
187
    }
188

189
    public build(): NewDataModificationTransaction {
190
        return new NewDataModificationTransaction(
×
191
            this._networkType,
192
            this._version || TransactionTypeVersion.Data_Modification,
×
193
            this._deadline ? this._deadline : this._createNewDeadlineFn(),
×
194
            this._maxFee ? this._maxFee : calculateFee(NewDataModificationTransaction.calculateSize(), this._feeCalculationStrategy),
×
195
            this._driveKey,
196
            this._downloadDataCdi,
197
            this._uploadSize,
198
            this._feedbackFeeAmount,
199
            this._signature,
200
            this._signer,
201
            this._transactionInfo
202
        );
203
    }
204
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc