Skip to content

Commit 51fc076

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 2194c8a commit 51fc076

12 files changed

+90
-183
lines changed

src/model/transaction/AccountAddressRestrictionTransaction.ts

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,23 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { SignSchema } from '../../core/crypto/SignSchema';
18-
import { Convert, RawAddress } from '../../core/format';
17+
import { RawAddress } from '../../core/format';
18+
import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction';
19+
import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction';
1920
import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder';
2021
import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder';
2122
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
22-
import { EmbeddedAccountAddressRestrictionTransactionBuilder }from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder';
23+
import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto';
2324
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
2425
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
2526
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
2627
import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto';
27-
import { Address } from '../account/Address';
2828
import { PublicAccount } from '../account/PublicAccount';
2929
import { RestrictionType } from '../account/RestrictionType';
3030
import { NetworkType } from '../blockchain/NetworkType';
3131
import { UInt64 } from '../UInt64';
3232
import { AccountRestrictionModification } from './AccountRestrictionModification';
3333
import { Deadline } from './Deadline';
34-
import { InnerTransaction } from './InnerTransaction';
3534
import { Transaction } from './Transaction';
3635
import { TransactionInfo } from './TransactionInfo';
3736
import { TransactionType } from './TransactionType';
@@ -85,36 +84,6 @@ export class AccountAddressRestrictionTransaction extends Transaction {
8584
networkType, version, deadline, maxFee, signature, signer, transactionInfo);
8685
}
8786

88-
/**
89-
* Create a transaction object from payload
90-
* @param {string} payload Binary payload
91-
* @param {Boolean} isEmbedded Is embedded transaction (Default: false)
92-
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
93-
* @returns {Transaction | InnerTransaction}
94-
*/
95-
public static createFromPayload(payload: string,
96-
isEmbedded: boolean = false,
97-
signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction {
98-
const builder = isEmbedded ? EmbeddedAccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) :
99-
AccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload));
100-
const signer = Convert.uint8ToHex(builder.getSigner().key);
101-
const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0];
102-
const transaction = AccountAddressRestrictionTransaction.create(
103-
isEmbedded ? Deadline.create() : Deadline.createFromDTO(
104-
(builder as AccountAddressRestrictionTransactionBuilder).getDeadline().timestamp),
105-
builder.getRestrictionType().valueOf(),
106-
builder.getModifications().map((modification) => {
107-
return AccountRestrictionModification.createForAddress(
108-
modification.modificationAction.valueOf(),
109-
Address.createFromEncoded(Convert.uint8ToHex(modification.value.unresolvedAddress)),
110-
);
111-
}),
112-
networkType,
113-
isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountAddressRestrictionTransactionBuilder).fee.amount),
114-
);
115-
return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction;
116-
}
117-
11887
/**
11988
* @override Transaction.size()
12089
* @description get the byte size of a AccountAddressRestrictionTransaction
@@ -136,6 +105,20 @@ export class AccountAddressRestrictionTransaction extends Transaction {
136105
return byteSize + byteRestrictionType + byteModificationCount + byteModifications;
137106
}
138107

108+
/**
109+
* @internal
110+
* @returns {VerifiableTransaction}
111+
*/
112+
protected buildTransaction(): VerifiableTransaction {
113+
return new Builder()
114+
.addDeadline(this.deadline.toDTO())
115+
.addFee(this.maxFee.toDTO())
116+
.addVersion(this.versionToDTO())
117+
.addRestrictionType(this.restrictionType)
118+
.addModifications(this.modifications.map((modification) => modification.toDTO()))
119+
.build();
120+
}
121+
139122
/**
140123
* @internal
141124
* @returns {Uint8Array}
@@ -161,24 +144,4 @@ export class AccountAddressRestrictionTransaction extends Transaction {
161144
);
162145
return transactionBuilder.serialize();
163146
}
164-
165-
/**
166-
* @internal
167-
* @returns {Uint8Array}
168-
*/
169-
protected generateEmbeddedBytes(): Uint8Array {
170-
const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder(
171-
new KeyDto(Convert.hexToUint8(this.signer!.publicKey)),
172-
this.versionToDTO(),
173-
TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(),
174-
this.restrictionType.valueOf(),
175-
this.modifications.map((modification) => {
176-
return new AccountAddressRestrictionModificationBuilder(
177-
modification.modificationType.valueOf(),
178-
new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)),
179-
);
180-
}),
181-
);
182-
return transactionBuilder.serialize();
183-
}
184147
}

src/model/transaction/AccountMosaicRestrictionTransaction.ts

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { SignSchema } from '../../core/crypto/SignSchema';
18-
import { Convert } from '../../core/format';
17+
import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction';
18+
import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction';
1919
import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder';
2020
import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder';
2121
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
22-
import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder';
22+
import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto';
2323
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
2424
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
2525
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
2626
import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto';
2727
import { PublicAccount } from '../account/PublicAccount';
28+
import { RestrictionType } from '../account/RestrictionType';
2829
import { NetworkType } from '../blockchain/NetworkType';
29-
import { MosaicId } from '../mosaic/MosaicId';
3030
import { UInt64 } from '../UInt64';
3131
import { AccountRestrictionModification } from './AccountRestrictionModification';
3232
import { Deadline } from './Deadline';
33-
import { InnerTransaction } from './InnerTransaction';
3433
import { Transaction } from './Transaction';
3534
import { TransactionInfo } from './TransactionInfo';
3635
import { TransactionType } from './TransactionType';
@@ -48,7 +47,7 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
4847
* @returns {AccountAddressRestrictionTransaction}
4948
*/
5049
public static create(deadline: Deadline,
51-
restrictionType: AccountRestrictionType,
50+
restrictionType: RestrictionType,
5251
modifications: Array<AccountRestrictionModification<number[]>>,
5352
networkType: NetworkType,
5453
maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionTransaction {
@@ -75,7 +74,7 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
7574
version: number,
7675
deadline: Deadline,
7776
maxFee: UInt64,
78-
public readonly restrictionType: AccountRestrictionType,
77+
public readonly restrictionType: RestrictionType,
7978
public readonly modifications: Array<AccountRestrictionModification<number[]>>,
8079
signature?: string,
8180
signer?: PublicAccount,
@@ -84,36 +83,6 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
8483
networkType, version, deadline, maxFee, signature, signer, transactionInfo);
8584
}
8685

87-
/**
88-
* Create a transaction object from payload
89-
* @param {string} payload Binary payload
90-
* @param {Boolean} isEmbedded Is embedded transaction (Default: false)
91-
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
92-
* @returns {Transaction | InnerTransaction}
93-
*/
94-
public static createFromPayload(payload: string,
95-
isEmbedded: boolean = false,
96-
signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction {
97-
const builder = isEmbedded ? EmbeddedAccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) :
98-
AccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload));
99-
const signer = Convert.uint8ToHex(builder.getSigner().key);
100-
const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0];
101-
const transaction = AccountMosaicRestrictionTransaction.create(
102-
isEmbedded ? Deadline.create() : Deadline.createFromDTO(
103-
(builder as AccountMosaicRestrictionTransactionBuilder).getDeadline().timestamp),
104-
builder.getRestrictionType().valueOf(),
105-
builder.getModifications().map((modification) => {
106-
return AccountRestrictionModification.createForMosaic(
107-
modification.modificationAction.valueOf(),
108-
new MosaicId(modification.value.unresolvedMosaicId),
109-
);
110-
}),
111-
networkType,
112-
isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountMosaicRestrictionTransactionBuilder).fee.amount),
113-
);
114-
return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction;
115-
}
116-
11786
/**
11887
* @override Transaction.size()
11988
* @description get the byte size of a AccountMosaicRestrictionTransaction
@@ -135,6 +104,20 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
135104
return byteSize + byteRestrictionType + byteModificationCount + byteModifications;
136105
}
137106

107+
/**
108+
* @internal
109+
* @returns {VerifiableTransaction}
110+
*/
111+
protected buildTransaction(): VerifiableTransaction {
112+
return new Builder()
113+
.addDeadline(this.deadline.toDTO())
114+
.addFee(this.maxFee.toDTO())
115+
.addVersion(this.versionToDTO())
116+
.addRestrictionType(this.restrictionType)
117+
.addModifications(this.modifications.map((modification) => modification.toDTO()))
118+
.build();
119+
}
120+
138121
/**
139122
* @internal
140123
* @returns {Uint8Array}
@@ -160,24 +143,4 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
160143
);
161144
return transactionBuilder.serialize();
162145
}
163-
164-
/**
165-
* @internal
166-
* @returns {Uint8Array}
167-
*/
168-
protected generateEmbeddedBytes(): Uint8Array {
169-
const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder(
170-
new KeyDto(Convert.hexToUint8(this.signer!.publicKey)),
171-
this.versionToDTO(),
172-
TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(),
173-
this.restrictionType.valueOf(),
174-
this.modifications.map((modification) => {
175-
return new AccountMosaicRestrictionModificationBuilder(
176-
modification.modificationType.valueOf(),
177-
new UnresolvedMosaicIdDto(modification.value),
178-
);
179-
}),
180-
);
181-
return transactionBuilder.serialize();
182-
}
183146
}

src/model/transaction/AccountOperationRestrictionTransaction.ts

Lines changed: 26 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,25 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { SignSchema } from '../../core/crypto/SignSchema';
18-
import { Convert } from '../../core/format';
19-
import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder';
20-
import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder';
21-
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
22-
import { EmbeddedAccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder';
23-
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
24-
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
25-
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
26-
import { AccountRestrictionType } from '../account/AccountRestrictionType';
17+
import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction';
18+
import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction';
2719
import { PublicAccount } from '../account/PublicAccount';
20+
import { RestrictionType } from '../account/RestrictionType';
2821
import { NetworkType } from '../blockchain/NetworkType';
2922
import { UInt64 } from '../UInt64';
3023
import { AccountRestrictionModification } from './AccountRestrictionModification';
3124
import { Deadline } from './Deadline';
32-
import { InnerTransaction } from './InnerTransaction';
3325
import { Transaction } from './Transaction';
3426
import { TransactionInfo } from './TransactionInfo';
3527
import { TransactionType } from './TransactionType';
3628
import { TransactionVersion } from './TransactionVersion';
29+
import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder';
30+
import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder';
31+
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
32+
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
33+
import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto';
34+
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
35+
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
3736

3837
export class AccountOperationRestrictionTransaction extends Transaction {
3938

@@ -47,7 +46,7 @@ export class AccountOperationRestrictionTransaction extends Transaction {
4746
* @returns {AccountOperationRestrictionTransaction}
4847
*/
4948
public static create(deadline: Deadline,
50-
restrictionType: AccountRestrictionType,
49+
restrictionType: RestrictionType,
5150
modifications: Array<AccountRestrictionModification<TransactionType>>,
5251
networkType: NetworkType,
5352
maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionTransaction {
@@ -74,7 +73,7 @@ export class AccountOperationRestrictionTransaction extends Transaction {
7473
version: number,
7574
deadline: Deadline,
7675
maxFee: UInt64,
77-
public readonly restrictionType: AccountRestrictionType,
76+
public readonly restrictionType: RestrictionType,
7877
public readonly modifications: Array<AccountRestrictionModification<TransactionType>>,
7978
signature?: string,
8079
signer?: PublicAccount,
@@ -83,36 +82,6 @@ export class AccountOperationRestrictionTransaction extends Transaction {
8382
networkType, version, deadline, maxFee, signature, signer, transactionInfo);
8483
}
8584

86-
/**
87-
* Create a transaction object from payload
88-
* @param {string} payload Binary payload
89-
* @param {Boolean} isEmbedded Is embedded transaction (Default: false)
90-
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
91-
* @returns {Transaction | InnerTransaction}
92-
*/
93-
public static createFromPayload(payload: string,
94-
isEmbedded: boolean = false,
95-
signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction {
96-
const builder = isEmbedded ? EmbeddedAccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) :
97-
AccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload));
98-
const signer = Convert.uint8ToHex(builder.getSigner().key);
99-
const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0];
100-
const transaction = AccountOperationRestrictionTransaction.create(
101-
isEmbedded ? Deadline.create() : Deadline.createFromDTO(
102-
(builder as AccountOperationRestrictionTransactionBuilder).getDeadline().timestamp),
103-
builder.getRestrictionType().valueOf(),
104-
builder.getModifications().map((modification) => {
105-
return AccountRestrictionModification.createForOperation(
106-
modification.modificationAction.valueOf(),
107-
modification.value.valueOf(),
108-
);
109-
}),
110-
networkType,
111-
isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountOperationRestrictionTransactionBuilder).fee.amount),
112-
);
113-
return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction;
114-
}
115-
11685
/**
11786
* @override Transaction.size()
11887
* @description get the byte size of a AccountOperationRestrictionTransaction
@@ -134,6 +103,20 @@ export class AccountOperationRestrictionTransaction extends Transaction {
134103
return byteSize + byteRestrictionType + byteModificationCount + byteModifications;
135104
}
136105

106+
/**
107+
* @internal
108+
* @returns {VerifiableTransaction}
109+
*/
110+
protected buildTransaction(): VerifiableTransaction {
111+
return new Builder()
112+
.addDeadline(this.deadline.toDTO())
113+
.addFee(this.maxFee.toDTO())
114+
.addVersion(this.versionToDTO())
115+
.addRestrictionType(this.restrictionType)
116+
.addModifications(this.modifications.map((modification) => modification.toDTO()))
117+
.build();
118+
}
119+
137120
/**
138121
* @internal
139122
* @returns {Uint8Array}
@@ -159,24 +142,4 @@ export class AccountOperationRestrictionTransaction extends Transaction {
159142
);
160143
return transactionBuilder.serialize();
161144
}
162-
163-
/**
164-
* @internal
165-
* @returns {Uint8Array}
166-
*/
167-
protected generateEmbeddedBytes(): Uint8Array {
168-
const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder(
169-
new KeyDto(Convert.hexToUint8(this.signer!.publicKey)),
170-
this.versionToDTO(),
171-
TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(),
172-
this.restrictionType.valueOf(),
173-
this.modifications.map((modification) => {
174-
return new AccountOperationRestrictionModificationBuilder(
175-
modification.modificationType.valueOf(),
176-
modification.value.valueOf(),
177-
);
178-
}),
179-
);
180-
return transactionBuilder.serialize();
181-
}
182145
}

0 commit comments

Comments
 (0)