Skip to content

Commit 70947d6

Browse files
author
Grégory Saive
authored
Merge branch 'master' into fix/accountRepository
2 parents ee92c49 + f3ea076 commit 70947d6

32 files changed

+562
-131
lines changed

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# CHANGELOG
22

3-
# v0.10.3
3+
# v0.11
44

55
- Fixed NetworkCurrencyMosaic, NetworkHarvestMosaic
66
- Added exposed UInt64.fromHex and UInt64.toHex
77
- Added MosaicId.createFromNonce
88
- Added MosaicNonce, MosaicNonce.createRandom
99
- Fixed AliasDTO.mosaicId to be UInt64
1010
- Added [email protected] version update (cow compatibility)
11-
12-
# v0.10.2
13-
1411
- Added cow network update *base* compatibility
1512
- Added AliasTransaction, AddressAliasTransaction, MosaicAliasTransaction
1613
- Changed MosaicDefinition to hold MosaicNonce
1714
- Changed SecretLock transaction to work with Sha3_256 instead of Sha3_512
15+
- Added delegated harvesting
16+
- Fixed #38: error message for aggregate as inner tx
17+
- Added TransferTransaction.recipient NamespaceId argument type
1818

1919
# v0.10.1-beta
2020

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ with the NEM2 (a.k.a Catapult)
1010

1111
## Important Notes
1212

13-
Due to a network upgrade with [catapult-server@cow](https://github.com/nemtech/catapult-server/releases/tag/v0.3.0.1) version, **transactions from Alpaca&Bison are not compatible anymore**.
13+
Due to a network upgrade with [catapult-server@cow](https://github.com/nemtech/catapult-server/releases/tag/v0.3.0.2) version, **transactions from Alpaca&Bison are not compatible anymore**.
1414

15-
The upgrade to this SDK's [version v0.10.2](https://github.com/nemtech/nem2-sdk-typescript-javascript/releases/tag/v0.10.2) is mandatory for **cow compatibility**.
15+
The upgrade to this SDK's [version v0.11](https://github.com/nemtech/nem2-sdk-typescript-javascript/releases/tag/v0.11) is mandatory for **cow compatibility**.
1616

1717
Other versions like [version v0.10.1-beta](https://github.com/nemtech/nem2-sdk-typescript-javascript/releases/tag/v0.10.1-beta) can be used for **bison** network version.
1818

@@ -55,9 +55,8 @@ Please, use the following available resources to get help:
5555

5656
Important versions listed below. Refer to the [Changelog](CHANGELOG.md) for a full history of the project.
5757

58-
- [0.10.3](CHANGELOG.md#v0103) - **Cow compatible** - TBD
59-
- [0.10.2](CHANGELOG.md#v0102) - **Cow compatible** - 2019-02-25
60-
- [0.10.1-beta](CHANGELOG.md#v0101-beta) - **Alpaca compatible**
58+
- [0.11](CHANGELOG.md#v011) - **Cow compatible** - 14.03.2019
59+
- [0.10.1-beta](CHANGELOG.md#v0101-beta) - **Alpaca compatible** 07.2018
6160

6261
## License
6362

e2e/service/MosaicService.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { map, mergeMap, toArray } from 'rxjs/operators';
22
import { AccountHttp } from '../../src/infrastructure/AccountHttp';
33
import { MosaicHttp } from '../../src/infrastructure/MosaicHttp';
4-
import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp';
54
import { Address } from '../../src/model/account/Address';
65
import { MosaicService } from '../../src/service/MosaicService';
76
import { APIUrl } from '../conf/conf.spec';
@@ -12,7 +11,6 @@ describe('MosaicService', () => {
1211
const mosaicService = new MosaicService(
1312
new AccountHttp(APIUrl),
1413
new MosaicHttp(APIUrl),
15-
new NamespaceHttp(APIUrl),
1614
);
1715

1816
const address = Address.createFromRawAddress('SCO2JY-N6OJSM-CJPPVS-Z3OX7P-TWPQEJ-GZTI6W-GLKK');

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nem2-sdk",
3-
"version": "0.10.3-4",
3+
"version": "0.11.1",
44
"description": "Reactive Nem2 sdk for typescript and javascript",
55
"scripts": {
66
"pretest": "npm run build",
@@ -53,7 +53,7 @@
5353
"@types/crypto-js": "^3.1.43",
5454
"crypto-js": "^3.1.9-1",
5555
"js-joda": "^1.6.2",
56-
"nem2-library": "^0.9.11",
56+
"nem2-library": "^0.9.12",
5757
"request": "^2.83.0",
5858
"request-promise-native": "^1.0.5",
5959
"rxjs": "^6.2.1",

src/infrastructure/AccountHttp.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {from as observableFrom, Observable} from 'rxjs';
1919
import {map, mergeMap} from 'rxjs/operators';
2020
import {AccountInfo} from '../model/account/AccountInfo';
2121
import { AccountPropertiesInfo } from '../model/account/AccountPropertiesInfo';
22-
import { AccountProperty } from '../model/account/AccountProperty';
2322
import {Address} from '../model/account/Address';
2423
import {MultisigAccountGraphInfo} from '../model/account/MultisigAccountGraphInfo';
2524
import {MultisigAccountInfo} from '../model/account/MultisigAccountInfo';

src/infrastructure/Listener.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as WebSocket from 'ws';
2020
import {Address} from '../model/account/Address';
2121
import {PublicAccount} from '../model/account/PublicAccount';
2222
import {BlockInfo} from '../model/blockchain/BlockInfo';
23+
import {NamespaceId} from '../model/namespace/NamespaceId';
2324
import {AggregateTransaction} from '../model/transaction/AggregateTransaction';
2425
import {AggregateTransactionCosignature} from '../model/transaction/AggregateTransactionCosignature';
2526
import {CosignatureSignedTransaction} from '../model/transaction/CosignatureSignedTransaction';
@@ -375,8 +376,16 @@ export class Listener {
375376
* @param address
376377
* @returns {boolean}
377378
*/
378-
private transactionHasSignerOrReceptor(transaction: Transaction, address: Address): boolean {
379-
return transaction.signer!.address.equals(address) ||
380-
(transaction instanceof TransferTransaction && transaction.recipient.equals(address));
379+
private transactionHasSignerOrReceptor(transaction: Transaction, address: Address | NamespaceId): boolean {
380+
381+
if (address instanceof NamespaceId) {
382+
return transaction instanceof TransferTransaction
383+
&& (transaction.recipient as NamespaceId).equals(address);
384+
}
385+
386+
return transaction.signer!.address.equals(address) || (
387+
transaction instanceof TransferTransaction
388+
&& (transaction.recipient as Address).equals(address)
389+
);
381390
}
382391
}

src/infrastructure/MosaicHttp.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,12 @@ export class MosaicHttp extends Http implements MosaicRepository {
6161
mergeMap((networkType) => observableFrom(
6262
this.mosaicRoutesApi.getMosaic(mosaicId.toHex())).pipe(map((mosaicInfoDTO) => {
6363
return new MosaicInfo(
64-
mosaicInfoDTO.meta.active,
65-
mosaicInfoDTO.meta.index,
6664
mosaicInfoDTO.meta.id,
6765
new MosaicId(mosaicInfoDTO.mosaic.mosaicId),
68-
new UInt64(mosaicInfoDTO.mosaic.nonce),
6966
new UInt64(mosaicInfoDTO.mosaic.supply),
7067
new UInt64(mosaicInfoDTO.mosaic.height),
7168
PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType),
69+
mosaicInfoDTO.mosaic.revision,
7270
new MosaicProperties(
7371
new UInt64(mosaicInfoDTO.mosaic.properties[0]),
7472
(new UInt64(mosaicInfoDTO.mosaic.properties[1])).compact(),
@@ -93,14 +91,12 @@ export class MosaicHttp extends Http implements MosaicRepository {
9391
this.mosaicRoutesApi.getMosaics(mosaicIdsBody)).pipe(map((mosaicInfosDTO) => {
9492
return mosaicInfosDTO.map((mosaicInfoDTO) => {
9593
return new MosaicInfo(
96-
mosaicInfoDTO.meta.active,
97-
mosaicInfoDTO.meta.index,
9894
mosaicInfoDTO.meta.id,
9995
new MosaicId(mosaicInfoDTO.mosaic.mosaicId),
100-
new UInt64(mosaicInfoDTO.mosaic.nonce),
10196
new UInt64(mosaicInfoDTO.mosaic.supply),
10297
new UInt64(mosaicInfoDTO.mosaic.height),
10398
PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType),
99+
mosaicInfoDTO.mosaic.revision,
104100
new MosaicProperties(
105101
new UInt64(mosaicInfoDTO.mosaic.properties[0]),
106102
(new UInt64(mosaicInfoDTO.mosaic.properties[1])).compact(),

src/infrastructure/transaction/CreateTransactionFromDTO.ts

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,28 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
16+
import {convert} from 'nem2-library';
17+
import {uint64 as UInt64Library} from 'nem2-library';
1718
import {Address} from '../../model/account/Address';
1819
import {PublicAccount} from '../../model/account/PublicAccount';
1920
import {NetworkType} from '../../model/blockchain/NetworkType';
20-
import { AccountPropertyModification,
21-
ModifyAccountPropertyAddressTransaction,
22-
ModifyAccountPropertyEntityTypeTransaction,
23-
ModifyAccountPropertyMosaicTransaction } from '../../model/model';
21+
import {Id} from '../../model/Id';
2422
import {Mosaic} from '../../model/mosaic/Mosaic';
2523
import {MosaicId} from '../../model/mosaic/MosaicId';
2624
import {MosaicProperties} from '../../model/mosaic/MosaicProperties';
2725
import {NamespaceId} from '../../model/namespace/NamespaceId';
26+
import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction';
27+
import {AccountPropertyModification} from '../../model/transaction/AccountPropertyModification';
2828
import {AddressAliasTransaction} from '../../model/transaction/AddressAliasTransaction';
2929
import {AggregateTransaction} from '../../model/transaction/AggregateTransaction';
3030
import {AggregateTransactionCosignature} from '../../model/transaction/AggregateTransactionCosignature';
3131
import {AggregateTransactionInfo} from '../../model/transaction/AggregateTransactionInfo';
3232
import {Deadline} from '../../model/transaction/Deadline';
33+
import { LinkAction } from '../../model/transaction/LinkAction';
3334
import {LockFundsTransaction} from '../../model/transaction/LockFundsTransaction';
35+
import {ModifyAccountPropertyAddressTransaction} from '../../model/transaction/ModifyAccountPropertyAddressTransaction';
36+
import {ModifyAccountPropertyEntityTypeTransaction} from '../../model/transaction/ModifyAccountPropertyEntityTypeTransaction';
37+
import {ModifyAccountPropertyMosaicTransaction} from '../../model/transaction/ModifyAccountPropertyMosaicTransaction';
3438
import {ModifyMultisigAccountTransaction} from '../../model/transaction/ModifyMultisigAccountTransaction';
3539
import {MosaicAliasTransaction} from '../../model/transaction/MosaicAliasTransaction';
3640
import {MosaicDefinitionTransaction} from '../../model/transaction/MosaicDefinitionTransaction';
@@ -119,10 +123,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
119123
extractTransactionVersion(transactionDTO.version),
120124
Deadline.createFromDTO(transactionDTO.deadline),
121125
new UInt64(transactionDTO.fee || [0, 0]),
122-
Address.createFromEncoded(transactionDTO.recipient),
123-
transactionDTO.mosaics === undefined ? [] :
124-
transactionDTO.mosaics
125-
.map((mosaicDTO) => new Mosaic(new MosaicId(mosaicDTO.id), new UInt64(mosaicDTO.amount))),
126+
extractRecipient(transactionDTO.recipient),
127+
extractMosaics(transactionDTO.mosaics),
126128
transactionDTO.message !== undefined ?
127129
PlainMessage.createFromDTO(transactionDTO.message.payload) : EmptyMessage,
128130
transactionDTO.signature,
@@ -303,6 +305,18 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
303305
PublicAccount.createFromPublicKey(transactionDTO.signer, extractNetworkType(transactionDTO.version)),
304306
transactionInfo,
305307
);
308+
} else if (transactionDTO.type === TransactionType.LINK_ACCOUNT) {
309+
return new AccountLinkTransaction(
310+
extractNetworkType(transactionDTO.version),
311+
extractTransactionVersion(transactionDTO.version),
312+
Deadline.createFromDTO(transactionDTO.deadline),
313+
new UInt64(transactionDTO.fee || [0, 0]),
314+
transactionDTO.remoteAccountKey,
315+
transactionDTO.linkAction,
316+
transactionDTO.signature,
317+
PublicAccount.createFromPublicKey(transactionDTO.signer, extractNetworkType(transactionDTO.version)),
318+
transactionInfo,
319+
);
306320
}
307321

308322
throw new Error('Unimplemented transaction with type ' + transactionDTO.type);
@@ -325,3 +339,60 @@ const extractNetworkType = (version: number): NetworkType => {
325339
const extractTransactionVersion = (version: number): number => {
326340
return parseInt(version.toString(16).substr(2, 2), 16);
327341
};
342+
343+
/**
344+
* Extract recipient value from encoded hexadecimal notation.
345+
*
346+
* If bit 0 of byte 0 is not set (e.g. 0x90), then it is a regular address.
347+
* Else (e.g. 0x91) it represents a namespace id which starts at byte 1.
348+
*
349+
* @param recipient {string} Encoded hexadecimal recipient notation
350+
* @return {Address | NamespaceId}
351+
*/
352+
const extractRecipient = (recipient: string): Address | NamespaceId => {
353+
// If bit 0 of byte 0 is not set (like in 0x90), then it is a regular address.
354+
// Else (e.g. 0x91) it represents a namespace id which starts at byte 1.
355+
const bit0 = convert.hexToUint8(recipient.substr(1, 2))[0];
356+
357+
if ((bit0 & 16) === 16) {
358+
// namespaceId encoded hexadecimal notation provided
359+
// only 8 bytes are relevant to resolve the NamespaceId
360+
const relevantPart = recipient.substr(2, 16);
361+
return NamespaceId.createFromEncoded(relevantPart);
362+
}
363+
364+
// read address from encoded hexadecimal notation
365+
return Address.createFromEncoded(recipient);
366+
};
367+
368+
/**
369+
* Extract mosaics from encoded UInt64 notation.
370+
*
371+
* If most significant bit of byte 0 is set, then it is a namespaceId.
372+
* If most significant bit of byte 0 is not set, then it is a mosaicId.
373+
*
374+
* @param mosaics {Array | undefined} The DTO array of mosaics (with UInt64 Id notation)
375+
* @return {Mosaic[]}
376+
*/
377+
const extractMosaics = (mosaics: any): Mosaic[] => {
378+
379+
if (mosaics === undefined) {
380+
return [];
381+
}
382+
383+
return mosaics.map((mosaicDTO) => {
384+
385+
// convert ID to UInt8 bytes array and get first byte (most significant byte)
386+
const uint64 = new Id(mosaicDTO.id);
387+
const bytes = convert.hexToUint8(UInt64Library.toHex(uint64.toDTO()));
388+
const byte0 = bytes[0];
389+
390+
// if most significant bit of byte 0 is set, then we have a namespaceId
391+
if ((byte0 & 128) === 128) {
392+
return new Mosaic(new NamespaceId(mosaicDTO.id), new UInt64(mosaicDTO.amount));
393+
}
394+
395+
// most significant bit of byte 0 is not set => mosaicId
396+
return new Mosaic(new MosaicId(mosaicDTO.id), new UInt64(mosaicDTO.amount));
397+
});
398+
};

src/model/model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export * from './namespace/NamespaceType';
6161
export * from './namespace/AliasActionType';
6262

6363
// Transaction
64+
export * from './transaction/AccountLinkTransaction';
6465
export * from './transaction/AccountPropertyTransaction';
6566
export * from './transaction/ModifyAccountPropertyAddressTransaction';
6667
export * from './transaction/ModifyAccountPropertyEntityTypeTransaction';
@@ -77,6 +78,7 @@ export * from './transaction/Deadline';
7778
export * from './transaction/HashLockTransaction';
7879
export * from './transaction/HashType';
7980
export * from './transaction/InnerTransaction';
81+
export * from './transaction/LinkAction';
8082
export * from './transaction/LockFundsTransaction';
8183
export * from './transaction/Message';
8284
export * from './transaction/ModifyMultisigAccountTransaction';

0 commit comments

Comments
 (0)