Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Task/604 address formatting #611

Merged
merged 20 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions catapult-sdk/src/model/ModelSchemaBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ModelSchemaBuilder {
transactionsHash: ModelType.binary,
receiptsHash: ModelType.binary,
stateHash: ModelType.binary,
beneficiaryAddress: ModelType.binary,
beneficiaryAddress: ModelType.encodedAddress,
feeMultiplier: ModelType.uint32,
// optional. How to create subclasses?
votingEligibleAccountsCount: ModelType.uint32,
Expand Down Expand Up @@ -169,7 +169,7 @@ class ModelSchemaBuilder {
},
account: {
version: ModelType.uint16,
address: ModelType.binary,
address: ModelType.encodedAddress,
addressHeight: ModelType.uint64,
publicKey: ModelType.binary,
publicKeyHeight: ModelType.uint64,
Expand Down
7 changes: 5 additions & 2 deletions catapult-sdk/src/model/ModelType.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ const ModelType = {
int: SchemaType.max + 10,

/** Schema property type indicating a boolean value. */
boolean: SchemaType.max + 11
boolean: SchemaType.max + 11,

/** Schema property type indicating a binary value as base32Address. */
encodedAddress: SchemaType.max + 12
};

Object.assign(ModelType, SchemaType);
ModelType.max = ModelType.boolean;
ModelType.max = ModelType.encodedAddress;

module.exports = ModelType;
2 changes: 1 addition & 1 deletion catapult-sdk/src/plugins/lockHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const lockHashPlugin = {
});
builder.addSchema('hashLockInfo.lock', {
version: ModelType.uint16,
ownerAddress: ModelType.binary,
ownerAddress: ModelType.encodedAddress,
mosaicId: ModelType.uint64HexIdentifier,
amount: ModelType.uint64,
endHeight: ModelType.uint64,
Expand Down
8 changes: 4 additions & 4 deletions catapult-sdk/src/plugins/lockSecret.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ const lockSecretPlugin = {
});
builder.addSchema('secretLockInfo.lock', {
version: ModelType.uint16,
ownerAddress: ModelType.binary,
ownerAddress: ModelType.encodedAddress,
mosaicId: ModelType.uint64HexIdentifier,
amount: ModelType.uint64,
endHeight: ModelType.uint64,
status: ModelType.uint8,
hashAlgorithm: ModelType.uint8,
secret: ModelType.binary,
recipientAddress: ModelType.binary,
recipientAddress: ModelType.encodedAddress,
compositeHash: ModelType.binary
});

builder.addTransactionSupport(EntityType.secretLock, {
recipientAddress: ModelType.binary,
recipientAddress: ModelType.encodedAddress,
secret: ModelType.binary,
mosaicId: ModelType.uint64HexIdentifier,
amount: ModelType.uint64,
Expand All @@ -59,7 +59,7 @@ const lockSecretPlugin = {
});
builder.addTransactionSupport(EntityType.secretProof, {
secret: ModelType.binary,
recipientAddress: ModelType.binary,
recipientAddress: ModelType.encodedAddress,
proof: ModelType.binary,
hashAlgorithm: ModelType.uint8
});
Expand Down
10 changes: 5 additions & 5 deletions catapult-sdk/src/plugins/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ const constants = { sizes };
const metadataPlugin = {
registerSchema: builder => {
builder.addTransactionSupport(EntityType.accountMetadata, {
targetAddress: ModelType.binary,
targetAddress: ModelType.encodedAddress,
scopedMetadataKey: ModelType.uint64HexIdentifier,
valueSizeDelta: ModelType.int,
valueSize: ModelType.uint16,
value: ModelType.binary
});

builder.addTransactionSupport(EntityType.mosaicMetadata, {
targetAddress: ModelType.binary,
targetAddress: ModelType.encodedAddress,
scopedMetadataKey: ModelType.uint64HexIdentifier,
targetMosaicId: ModelType.uint64HexIdentifier,
valueSizeDelta: ModelType.int,
Expand All @@ -51,7 +51,7 @@ const metadataPlugin = {
});

builder.addTransactionSupport(EntityType.namespaceMetadata, {
targetAddress: ModelType.binary,
targetAddress: ModelType.encodedAddress,
scopedMetadataKey: ModelType.uint64HexIdentifier,
targetNamespaceId: ModelType.uint64HexIdentifier,
valueSizeDelta: ModelType.int,
Expand All @@ -67,8 +67,8 @@ const metadataPlugin = {
builder.addSchema('metadataEntry', {
version: ModelType.uint16,
compositeHash: ModelType.binary,
sourceAddress: ModelType.binary,
targetAddress: ModelType.binary,
sourceAddress: ModelType.encodedAddress,
targetAddress: ModelType.encodedAddress,
scopedMetadataKey: ModelType.uint64HexIdentifier,
targetId: ModelType.uint64HexIdentifier,
metadataType: ModelType.int,
Expand Down
2 changes: 1 addition & 1 deletion catapult-sdk/src/plugins/mosaic.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const mosaicPlugin = {
id: ModelType.uint64HexIdentifier,
supply: ModelType.uint64,
startHeight: ModelType.uint64,
ownerAddress: ModelType.binary,
ownerAddress: ModelType.encodedAddress,
revision: ModelType.int,
flags: ModelType.uint8,
divisibility: ModelType.uint8,
Expand Down
10 changes: 5 additions & 5 deletions catapult-sdk/src/plugins/multisig.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ const multisigPlugin = {
builder.addTransactionSupport(EntityType.modifyMultisigAccount, {
minRemovalDelta: ModelType.int,
minApprovalDelta: ModelType.int,
addressAdditions: { type: ModelType.array, schemaName: ModelType.binary },
addressDeletions: { type: ModelType.array, schemaName: ModelType.binary }
addressAdditions: { type: ModelType.array, schemaName: ModelType.encodedAddress },
addressDeletions: { type: ModelType.array, schemaName: ModelType.encodedAddress }
});

builder.addSchema('multisigEntry', {
multisig: { type: ModelType.object, schemaName: 'multisigEntry.multisig' }
});
builder.addSchema('multisigEntry.multisig', {
version: ModelType.uint16,
accountAddress: ModelType.binary,
accountAddress: ModelType.encodedAddress,
minApproval: ModelType.int,
minRemoval: ModelType.int,
multisigAddresses: { type: ModelType.array, schemaName: ModelType.binary },
cosignatoryAddresses: { type: ModelType.array, schemaName: ModelType.binary }
multisigAddresses: { type: ModelType.array, schemaName: ModelType.encodedAddress },
cosignatoryAddresses: { type: ModelType.array, schemaName: ModelType.encodedAddress }
});
builder.addSchema('multisigGraph', {
level: ModelType.none,
Expand Down
8 changes: 4 additions & 4 deletions catapult-sdk/src/plugins/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const namespacePlugin = {
registerSchema: builder => {
builder.addTransactionSupport(EntityType.aliasAddress, {
namespaceId: ModelType.uint64HexIdentifier,
address: ModelType.binary,
address: ModelType.encodedAddress,
aliasAction: ModelType.uint8
});

Expand Down Expand Up @@ -91,7 +91,7 @@ const namespacePlugin = {
alias: { type: ModelType.object, schemaName: entity => getAliasBasicType(entity.type) },

parentId: ModelType.uint64HexIdentifier,
ownerAddress: ModelType.binary,
ownerAddress: ModelType.encodedAddress,

startHeight: ModelType.uint64,
endHeight: ModelType.uint64
Expand All @@ -104,7 +104,7 @@ const namespacePlugin = {

builder.addSchema('namespaceDescriptor.alias.address', {
type: ModelType.uint8,
address: ModelType.binary
address: ModelType.encodedAddress
});

builder.addSchema('namespaceDescriptor.alias.empty', {
Expand All @@ -131,7 +131,7 @@ const namespacePlugin = {
});

builder.addSchema('accountNamesTuple', {
address: ModelType.binary,
address: ModelType.encodedAddress,
names: { type: ModelType.array, schemaName: ModelType.string }
});
},
Expand Down
10 changes: 5 additions & 5 deletions catapult-sdk/src/plugins/receipts.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const receiptsPlugin = {

addStatementSchema('addressResolution', {
height: ModelType.uint64,
unresolved: ModelType.binary,
unresolved: ModelType.encodedAddress,
resolutionEntries: { type: ModelType.array, schemaName: 'receipts.entry.address' }
});
addStatementSchema('mosaicResolution', {
Expand All @@ -67,7 +67,7 @@ const receiptsPlugin = {
// addressResolution statements
builder.addSchema('receipts.entry.address', {
source: { type: ModelType.object, schemaName: 'receipts.source' },
resolved: ModelType.binary
resolved: ModelType.encodedAddress
});

// mosaicResolution statements
Expand All @@ -80,16 +80,16 @@ const receiptsPlugin = {
builder.addSchema('receipts.balanceChange', {
version: ModelType.int,
type: ModelType.int,
targetAddress: ModelType.binary,
targetAddress: ModelType.encodedAddress,
mosaicId: ModelType.uint64HexIdentifier,
amount: ModelType.uint64
});

builder.addSchema('receipts.balanceTransfer', {
version: ModelType.int,
type: ModelType.int,
senderAddress: ModelType.binary,
recipientAddress: ModelType.binary,
senderAddress: ModelType.encodedAddress,
recipientAddress: ModelType.encodedAddress,
mosaicId: ModelType.uint64HexIdentifier,
amount: ModelType.uint64
});
Expand Down
6 changes: 3 additions & 3 deletions catapult-sdk/src/plugins/restrictions.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const restrictionsPlugin = {
});
builder.addSchema('accountRestriction.restrictions', {
version: ModelType.uint16,
address: ModelType.binary,
address: ModelType.encodedAddress,
restrictions: {
type: ModelType.array,
schemaName: entity => {
Expand All @@ -148,7 +148,7 @@ const restrictionsPlugin = {
builder.addTransactionSupport(EntityType.mosaicRestrictionAddress, {
mosaicId: ModelType.uint64HexIdentifier,
restrictionKey: ModelType.uint64HexIdentifier,
targetAddress: ModelType.binary,
targetAddress: ModelType.encodedAddress,
previousRestrictionValue: ModelType.uint64,
newRestrictionValue: ModelType.uint64
});
Expand All @@ -174,7 +174,7 @@ const restrictionsPlugin = {
compositeHash: ModelType.binary,
entryType: ModelType.uint32,
mosaicId: ModelType.uint64HexIdentifier,
targetAddress: ModelType.binary,
targetAddress: ModelType.encodedAddress,
restrictions: { type: ModelType.array, schemaName: 'mosaicRestrictions.entry.restrictions' }
});
builder.addSchema('mosaicRestrictions.entry.restrictions', {
Expand Down
2 changes: 1 addition & 1 deletion catapult-sdk/src/plugins/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const constants = { sizes };
const transferPlugin = {
registerSchema: builder => {
builder.addTransactionSupport(EntityType.transfer, {
recipientAddress: ModelType.binary,
recipientAddress: ModelType.encodedAddress,
message: ModelType.binary,
mosaics: { type: ModelType.array, schemaName: 'mosaic' }
});
Expand Down
7 changes: 4 additions & 3 deletions catapult-sdk/test/model/ModelFormatterBuilder_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const formattingRules = {
[ModelType.uint64HexIdentifier]: () => 'uint64HexIdentifier',
[ModelType.objectId]: () => 'objectId',
[ModelType.string]: () => 'string',
[ModelType.int]: () => 'int'
[ModelType.int]: () => 'int',
[ModelType.encodedAddress]: () => 'encodedAddress'
};

describe('model formatter builder', () => {
Expand Down Expand Up @@ -171,7 +172,7 @@ describe('model formatter builder', () => {
transactionsHash: 'binary',
receiptsHash: 'binary',
stateHash: 'binary',
beneficiaryAddress: 'binary'
beneficiaryAddress: 'encodedAddress'
}
});
});
Expand Down Expand Up @@ -202,7 +203,7 @@ describe('model formatter builder', () => {
expect(result).to.deep.equal({
id: 'objectId',
account: {
address: 'binary',
address: 'encodedAddress',
addressHeight: 'uint64',
publicKey: 'binary',
publicKeyHeight: 'uint64',
Expand Down
13 changes: 11 additions & 2 deletions catapult-sdk/test/model/ModelSchemaBuilder_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ describe('model schema builder', () => {
'blockHeader.transactionsHash',
'blockHeader.receiptsHash',
'blockHeader.stateHash',
'blockHeader.beneficiaryAddress',
'blockHeader.previousImportanceBlockHash',
'blockHeader.signature',
'blockHeader.signerPublicKey',
Expand All @@ -245,7 +244,6 @@ describe('model schema builder', () => {

'transactionStatus.hash',

'account.address',
'account.publicKey',
'accountLinkPublicKey.publicKey',
'votingPublicKey.publicKey',
Expand Down Expand Up @@ -414,6 +412,17 @@ describe('model schema builder', () => {
]);
});

it('exposes correct encodedAddress properties', () => {
// Act:
const matchingProperties = extractSchemaPropertiesWithType('encodedAddress');

// Assert:
expect(matchingProperties).to.deep.equal([
'blockHeader.beneficiaryAddress',
'account.address'
]);
});

// endregion
});

Expand Down
3 changes: 2 additions & 1 deletion catapult-sdk/test/model/ModelType_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ describe('model type enumeration', () => {
uint64HexIdentifier: 12,
int: 13,
boolean: 14,
max: 14
encodedAddress: 15,
max: 15
});
});
});
5 changes: 3 additions & 2 deletions catapult-sdk/test/plugins/namespace_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ describe('namespace plugin', () => {
[ModelType.uint64HexIdentifier]: () => 'uint64HexIdentifier',
[ModelType.objectId]: () => 'objectId',
[ModelType.string]: () => 'string',
[ModelType.int]: () => 'int'
[ModelType.int]: () => 'int',
[ModelType.encodedAddress]: () => 'encodedAddress'
};
const namespaceDescriptorNamespace = {
registrationType: null,
Expand Down Expand Up @@ -213,7 +214,7 @@ describe('namespace plugin', () => {
expect(formattedAlias).to.contain.all.keys(['type', 'address']);
expect(formattedAlias).deep.equal({
type: 'uint8',
address: 'binary'
address: 'encodedAddress'
});
});

Expand Down
3 changes: 2 additions & 1 deletion catapult-sdk/test/plugins/receipts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ describe('receipts plugin', () => {
[ModelType.uint64HexIdentifier]: () => 'uint64HexIdentifier',
[ModelType.objectId]: () => 'objectId',
[ModelType.string]: () => 'string',
[ModelType.int]: () => 'int'
[ModelType.int]: () => 'int',
[ModelType.encodedAddress]: () => 'encodedAddress'
};
const transactionStatement = {
statement: {
Expand Down
5 changes: 3 additions & 2 deletions rest/src/db/dbFormattingRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with Catapult. If not, see <http://www.gnu.org/licenses/>.
*/

const { longToUint64 } = require('./dbUtils');
const { longToUint64, bufferToUnresolvedAddress } = require('./dbUtils');
const catapult = require('catapult-sdk');
const { Binary } = require('mongodb');

Expand Down Expand Up @@ -49,5 +49,6 @@ module.exports = {
// `uint64HexIdentifier` requires branching accountRestrictions->restrictionAdditions provides uint64 as binary
[ModelType.uint64HexIdentifier]: value => uint64.toHex(value instanceof Binary ? uint64.fromBytes(value.buffer) : longToUint64(value)),
[ModelType.int]: value => value.valueOf(),
[ModelType.boolean]: value => value
[ModelType.boolean]: value => value,
[ModelType.encodedAddress]: value => bufferToUnresolvedAddress(value)
Jaguar0625 marked this conversation as resolved.
Show resolved Hide resolved
};
Loading