Skip to content

Commit 0d30788

Browse files
committed
Added ts catbuffer codes (without aggregateTx)
Appended new signwithCatbuffer method in Transaction (temp) Applied catbuffer builders on standalone transaction (builder) Updated unit tests
1 parent 7b91ea5 commit 0d30788

File tree

134 files changed

+11043
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+11043
-138
lines changed

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ import {MosaicSupplyType} from '../../src/model/mosaic/MosaicSupplyType';
3737
import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic';
3838
import { AliasAction } from '../../src/model/namespace/AliasAction';
3939
import { NamespaceId } from '../../src/model/namespace/NamespaceId';
40-
import { AccountAddressRestrictionModificationTransaction } from '../../src/model/transaction/AccountAddressRestrictionModificationTransaction';
40+
import { AccountAddressRestrictionTransaction } from '../../src/model/transaction/AccountAddressRestrictionTransaction';
4141
import { AccountLinkTransaction } from '../../src/model/transaction/AccountLinkTransaction';
42-
import { AccountMosaicRestrictionModificationTransaction } from '../../src/model/transaction/AccountMosaicRestrictionModificationTransaction';
43-
import { AccountOperationRestrictionModificationTransaction } from '../../src/model/transaction/AccountOperationRestrictionModificationTransaction';
42+
import { AccountMosaicRestrictionTransaction } from '../../src/model/transaction/AccountMosaicRestrictionTransaction';
43+
import { AccountOperationRestrictionTransaction } from '../../src/model/transaction/AccountOperationRestrictionTransaction';
4444
import { AccountRestrictionModification } from '../../src/model/transaction/AccountRestrictionModification';
4545
import { AccountRestrictionTransaction } from '../../src/model/transaction/AccountRestrictionTransaction';
4646
import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction';
@@ -410,7 +410,7 @@ describe('TransactionHttp', () => {
410410
);
411411
const signedTransaction = addressModification.signWith(account, generationHash);
412412

413-
listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionModificationTransaction) => {
413+
listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionTransaction) => {
414414
expect(transaction.modifications, 'Modifications').not.to.be.undefined;
415415
expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined;
416416
expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined;
@@ -485,7 +485,7 @@ describe('TransactionHttp', () => {
485485
);
486486
const signedTransaction = addressModification.signWith(account, generationHash);
487487

488-
listener.confirmed(account.address).subscribe((transaction: AccountMosaicRestrictionModificationTransaction) => {
488+
listener.confirmed(account.address).subscribe((transaction: AccountMosaicRestrictionTransaction) => {
489489
expect(transaction.modifications, 'Modifications').not.to.be.undefined;
490490
expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined;
491491
expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined;
@@ -560,7 +560,7 @@ describe('TransactionHttp', () => {
560560
);
561561
const signedTransaction = addressModification.signWith(account3, generationHash);
562562

563-
listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionModificationTransaction) => {
563+
listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionTransaction) => {
564564
expect(transaction.modifications, 'Modifications').not.to.be.undefined;
565565
expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined;
566566
expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined;

src/infrastructure/QueryParams.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export enum Order {
2222
DESC = '-id',
2323
}
2424

25-
2625
/**
2726
* The query params structure describes pagination params for requests.
2827
*

src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class Builder {
4545
modifications: any;
4646
constructor() {
4747
this.maxFee = [0, 0];
48-
this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS;
48+
this.type = TransactionType.ACCOUNT_RESTRICTION_ADDRESS;
4949
}
5050

5151
addFee(maxFee) {

src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class Builder {
4545
modifications: any;
4646
constructor() {
4747
this.maxFee = [0, 0];
48-
this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION;
48+
this.type = TransactionType.ACCOUNT_RESTRICTION_OPERATION;
4949
}
5050

5151
addFee(maxFee) {

src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class Builder {
4545
modifications: any;
4646
constructor() {
4747
this.maxFee = [0, 0];
48-
this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC;
48+
this.type = TransactionType.ACCOUNT_RESTRICTION_MOSAIC;
4949
}
5050

5151
addFee(maxFee) {
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// tslint:disable: jsdoc-format
2+
/**
3+
*** Copyright (c) 2016-present,
4+
*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved.
5+
***
6+
*** This file is part of Catapult.
7+
***
8+
*** Catapult is free software: you can redistribute it and/or modify
9+
*** it under the terms of the GNU Lesser General Public License as published by
10+
*** the Free Software Foundation, either version 3 of the License, or
11+
*** (at your option) any later version.
12+
***
13+
*** Catapult is distributed in the hope that it will be useful,
14+
*** but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
*** GNU Lesser General Public License for more details.
17+
***
18+
*** You should have received a copy of the GNU Lesser General Public License
19+
*** along with Catapult. If not, see <http://www.gnu.org/licenses/>.
20+
**/
21+
22+
import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto';
23+
import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder';
24+
import { GeneratorUtils } from './GeneratorUtils';
25+
import { UnresolvedAddressDto } from './UnresolvedAddressDto';
26+
27+
/** Account address restriction modification. */
28+
export class AccountAddressRestrictionModificationBuilder extends AccountRestrictionModificationBuilder {
29+
/** Address restriction value. */
30+
value: UnresolvedAddressDto;
31+
32+
/**
33+
* Constructor.
34+
*
35+
* @param modificationAction Modification action.
36+
* @param value Address restriction value.
37+
*/
38+
public constructor(modificationAction: AccountRestrictionModificationActionDto, value: UnresolvedAddressDto) {
39+
super(modificationAction);
40+
this.value = value;
41+
}
42+
43+
/**
44+
* Creates an instance of AccountAddressRestrictionModificationBuilder from binary payload.
45+
*
46+
* @param payload Byte payload to use to serialize the object.
47+
* @return Instance of AccountAddressRestrictionModificationBuilder.
48+
*/
49+
public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionModificationBuilder {
50+
const byteArray = Array.from(payload);
51+
const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray));
52+
byteArray.splice(0, superObject.getSize());
53+
const value = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray));
54+
byteArray.splice(0, value.getSize());
55+
return new AccountAddressRestrictionModificationBuilder(superObject.modificationAction, value);
56+
}
57+
58+
/**
59+
* Gets address restriction value.
60+
*
61+
* @return Address restriction value.
62+
*/
63+
public getValue(): UnresolvedAddressDto {
64+
return this.value;
65+
}
66+
67+
/**
68+
* Gets the size of the object.
69+
*
70+
* @return Size in bytes.
71+
*/
72+
public getSize(): number {
73+
let size: number = super.getSize();
74+
size += this.value.getSize();
75+
return size;
76+
}
77+
78+
/**
79+
* Serializes an object to bytes.
80+
*
81+
* @return Serialized bytes.
82+
*/
83+
public serialize(): Uint8Array {
84+
let newArray = Uint8Array.from([]);
85+
const superBytes = super.serialize();
86+
newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes);
87+
const valueBytes = this.value.serialize();
88+
newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes);
89+
return newArray;
90+
}
91+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// tslint:disable: jsdoc-format
2+
/**
3+
*** Copyright (c) 2016-present,
4+
*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved.
5+
***
6+
*** This file is part of Catapult.
7+
***
8+
*** Catapult is free software: you can redistribute it and/or modify
9+
*** it under the terms of the GNU Lesser General Public License as published by
10+
*** the Free Software Foundation, either version 3 of the License, or
11+
*** (at your option) any later version.
12+
***
13+
*** Catapult is distributed in the hope that it will be useful,
14+
*** but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
*** GNU Lesser General Public License for more details.
17+
***
18+
*** You should have received a copy of the GNU Lesser General Public License
19+
*** along with Catapult. If not, see <http://www.gnu.org/licenses/>.
20+
**/
21+
22+
import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder';
23+
import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto';
24+
import { GeneratorUtils } from './GeneratorUtils';
25+
26+
/** Binary layout for an account address restriction transaction. */
27+
export class AccountAddressRestrictionTransactionBodyBuilder {
28+
/** Account restriction type. */
29+
restrictionType: AccountRestrictionTypeDto;
30+
/** Account restriction modifications. */
31+
modifications: AccountAddressRestrictionModificationBuilder[];
32+
33+
/**
34+
* Constructor.
35+
*
36+
* @param restrictionType Account restriction type.
37+
* @param modifications Account restriction modifications.
38+
*/
39+
// tslint:disable-next-line: max-line-length
40+
public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) {
41+
this.restrictionType = restrictionType;
42+
this.modifications = modifications;
43+
}
44+
45+
/**
46+
* Creates an instance of AccountAddressRestrictionTransactionBodyBuilder from binary payload.
47+
*
48+
* @param payload Byte payload to use to serialize the object.
49+
* @return Instance of AccountAddressRestrictionTransactionBodyBuilder.
50+
*/
51+
public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionTransactionBodyBuilder {
52+
const byteArray = Array.from(payload);
53+
const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1));
54+
byteArray.splice(0, 1);
55+
const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1));
56+
byteArray.splice(0, 1);
57+
const modifications: AccountAddressRestrictionModificationBuilder[] = [];
58+
for (let i = 0; i < modificationsCount; i++) {
59+
const item = AccountAddressRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray));
60+
modifications.push(item);
61+
byteArray.splice(0, item.getSize());
62+
}
63+
return new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications);
64+
}
65+
66+
/**
67+
* Gets account restriction type.
68+
*
69+
* @return Account restriction type.
70+
*/
71+
public getRestrictionType(): AccountRestrictionTypeDto {
72+
return this.restrictionType;
73+
}
74+
75+
/**
76+
* Gets account restriction modifications.
77+
*
78+
* @return Account restriction modifications.
79+
*/
80+
public getModifications(): AccountAddressRestrictionModificationBuilder[] {
81+
return this.modifications;
82+
}
83+
84+
/**
85+
* Gets the size of the object.
86+
*
87+
* @return Size in bytes.
88+
*/
89+
public getSize(): number {
90+
let size = 0;
91+
size += 1; // restrictionType
92+
size += 1; // modificationsCount
93+
this.modifications.forEach((o) => size += o.getSize());
94+
return size;
95+
}
96+
97+
/**
98+
* Serializes an object to bytes.
99+
*
100+
* @return Serialized bytes.
101+
*/
102+
public serialize(): Uint8Array {
103+
let newArray = Uint8Array.from([]);
104+
const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1);
105+
newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes);
106+
const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1);
107+
newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes);
108+
this.modifications.forEach((item) => {
109+
const modificationsBytes = item.serialize();
110+
newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes);
111+
});
112+
return newArray;
113+
}
114+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// tslint:disable: jsdoc-format
2+
/**
3+
*** Copyright (c) 2016-present,
4+
*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved.
5+
***
6+
*** This file is part of Catapult.
7+
***
8+
*** Catapult is free software: you can redistribute it and/or modify
9+
*** it under the terms of the GNU Lesser General Public License as published by
10+
*** the Free Software Foundation, either version 3 of the License, or
11+
*** (at your option) any later version.
12+
***
13+
*** Catapult is distributed in the hope that it will be useful,
14+
*** but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
*** GNU Lesser General Public License for more details.
17+
***
18+
*** You should have received a copy of the GNU Lesser General Public License
19+
*** along with Catapult. If not, see <http://www.gnu.org/licenses/>.
20+
**/
21+
22+
import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder';
23+
import { AccountAddressRestrictionTransactionBodyBuilder } from './AccountAddressRestrictionTransactionBodyBuilder';
24+
import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto';
25+
import { AmountDto } from './AmountDto';
26+
import { EntityTypeDto } from './EntityTypeDto';
27+
import { GeneratorUtils } from './GeneratorUtils';
28+
import { KeyDto } from './KeyDto';
29+
import { SignatureDto } from './SignatureDto';
30+
import { TimestampDto } from './TimestampDto';
31+
import { TransactionBuilder } from './TransactionBuilder';
32+
33+
/** Binary layout for a non-embedded account address restriction transaction. */
34+
export class AccountAddressRestrictionTransactionBuilder extends TransactionBuilder {
35+
/** Account address restriction transaction body. */
36+
accountAddressRestrictionTransactionBody: AccountAddressRestrictionTransactionBodyBuilder;
37+
38+
/**
39+
* Constructor.
40+
*
41+
* @param signature Entity signature.
42+
* @param signer Entity signer's public key.
43+
* @param version Entity version.
44+
* @param type Entity type.
45+
* @param fee Transaction fee.
46+
* @param deadline Transaction deadline.
47+
* @param restrictionType Account restriction type.
48+
* @param modifications Account restriction modifications.
49+
*/
50+
// tslint:disable-next-line: max-line-length
51+
public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) {
52+
super(signature, signer, version, type, fee, deadline);
53+
// tslint:disable-next-line: max-line-length
54+
this.accountAddressRestrictionTransactionBody = new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications);
55+
}
56+
57+
/**
58+
* Creates an instance of AccountAddressRestrictionTransactionBuilder from binary payload.
59+
*
60+
* @param payload Byte payload to use to serialize the object.
61+
* @return Instance of AccountAddressRestrictionTransactionBuilder.
62+
*/
63+
public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionTransactionBuilder {
64+
const byteArray = Array.from(payload);
65+
const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray));
66+
byteArray.splice(0, superObject.getSize());
67+
// tslint:disable-next-line: max-line-length
68+
const accountAddressRestrictionTransactionBody = AccountAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray));
69+
byteArray.splice(0, accountAddressRestrictionTransactionBody.getSize());
70+
// tslint:disable-next-line: max-line-length
71+
return new AccountAddressRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountAddressRestrictionTransactionBody.restrictionType, accountAddressRestrictionTransactionBody.modifications);
72+
}
73+
74+
/**
75+
* Gets account restriction type.
76+
*
77+
* @return Account restriction type.
78+
*/
79+
public getRestrictionType(): AccountRestrictionTypeDto {
80+
return this.accountAddressRestrictionTransactionBody.getRestrictionType();
81+
}
82+
83+
/**
84+
* Gets account restriction modifications.
85+
*
86+
* @return Account restriction modifications.
87+
*/
88+
public getModifications(): AccountAddressRestrictionModificationBuilder[] {
89+
return this.accountAddressRestrictionTransactionBody.getModifications();
90+
}
91+
92+
/**
93+
* Gets the size of the object.
94+
*
95+
* @return Size in bytes.
96+
*/
97+
public getSize(): number {
98+
let size: number = super.getSize();
99+
size += this.accountAddressRestrictionTransactionBody.getSize();
100+
return size;
101+
}
102+
103+
/**
104+
* Serializes an object to bytes.
105+
*
106+
* @return Serialized bytes.
107+
*/
108+
public serialize(): Uint8Array {
109+
let newArray = Uint8Array.from([]);
110+
const superBytes = super.serialize();
111+
newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes);
112+
const accountAddressRestrictionTransactionBodyBytes = this.accountAddressRestrictionTransactionBody.serialize();
113+
newArray = GeneratorUtils.concatTypedArrays(newArray, accountAddressRestrictionTransactionBodyBytes);
114+
return newArray;
115+
}
116+
}

0 commit comments

Comments
 (0)