|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
| 17 | +import { SignSchema } from '../../core/crypto/SignSchema'; |
17 | 18 | import { Convert, RawAddress } from '../../core/format'; |
18 | 19 | import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; |
19 | 20 | import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; |
20 | 21 | import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; |
21 | | -import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; |
| 22 | +import { EmbeddedAccountAddressRestrictionTransactionBuilder }from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; |
22 | 23 | import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; |
23 | 24 | import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; |
24 | 25 | import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; |
25 | 26 | import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; |
| 27 | +import { Address } from '../account/Address'; |
26 | 28 | import { PublicAccount } from '../account/PublicAccount'; |
27 | 29 | import { RestrictionType } from '../account/RestrictionType'; |
28 | 30 | import { NetworkType } from '../blockchain/NetworkType'; |
29 | 31 | import { UInt64 } from '../UInt64'; |
30 | 32 | import { AccountRestrictionModification } from './AccountRestrictionModification'; |
31 | 33 | import { Deadline } from './Deadline'; |
| 34 | +import { InnerTransaction } from './InnerTransaction'; |
32 | 35 | import { Transaction } from './Transaction'; |
33 | 36 | import { TransactionInfo } from './TransactionInfo'; |
34 | 37 | import { TransactionType } from './TransactionType'; |
@@ -82,6 +85,36 @@ export class AccountAddressRestrictionTransaction extends Transaction { |
82 | 85 | networkType, version, deadline, maxFee, signature, signer, transactionInfo); |
83 | 86 | } |
84 | 87 |
|
| 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 | + |
85 | 118 | /** |
86 | 119 | * @override Transaction.size() |
87 | 120 | * @description get the byte size of a AccountAddressRestrictionTransaction |
|
0 commit comments