├── tests ├── jenkins ├── linters ├── infra ├── version.current.txt ├── package │ ├── libs │ │ └── _dir_needs_to_exists.txt │ ├── runNis.bat │ ├── nix.runNis.sh │ ├── README.txt │ ├── nis │ │ ├── db.properties │ │ └── logalpha.properties │ ├── nix.logalpha.properties │ └── logalpha.properties ├── jenkins │ └── seed-job │ │ └── Jenkinsfile ├── package.pack.sh ├── package.build.sh ├── package.prepare.sh └── package.tomaster.sh ├── .gitlintmodules ├── .github ├── jenkinsfile │ ├── nightlyBuild.groovy │ └── controller.groovy └── buildConfiguration.yaml ├── gocrypto ├── scripts │ └── ci │ │ ├── build.sh │ │ ├── lint.sh │ │ ├── setup_lint.sh │ │ ├── test.sh │ │ └── test_vectors.sh ├── go.mod ├── Jenkinsfile └── go.sum ├── core ├── scripts │ └── ci │ │ ├── build.sh │ │ ├── lint.sh │ │ └── test.sh ├── src │ ├── test │ │ ├── resources │ │ │ └── test.properties │ │ └── java │ │ │ └── org │ │ │ └── nem │ │ │ └── core │ │ │ ├── crypto │ │ │ ├── ed25519 │ │ │ │ ├── Ed25519KeyAnalyzerTest.java │ │ │ │ └── Ed25519CryptoEngineTest.java │ │ │ └── secp256k1 │ │ │ │ ├── SecP256K1CryptoEngineTest.java │ │ │ │ └── SecP256K1BlockCipherTest.java │ │ │ ├── test │ │ │ ├── VerifiableEntityUtils.java │ │ │ └── ParameterizedUtils.java │ │ │ ├── serialization │ │ │ ├── SerializationContextTest.java │ │ │ └── primitive │ │ │ │ ├── JsonSerializationPolicy.java │ │ │ │ ├── BinarySerializationPolicy.java │ │ │ │ ├── JsonPrimitiveTruncationTest.java │ │ │ │ └── BinaryPrimitiveTruncationTest.java │ │ │ ├── model │ │ │ ├── ncc │ │ │ │ ├── NamespaceMetaDataPairTest.java │ │ │ │ ├── MosaicDefinitionMetaDataPairTest.java │ │ │ │ ├── AccountIdBuilderTest.java │ │ │ │ ├── PublicKeyBuilderTest.java │ │ │ │ ├── TransactionMetaDataPairTest.java │ │ │ │ └── UnconfirmedTransactionMetaDataPairTest.java │ │ │ ├── observers │ │ │ │ ├── NamedObserverTest.java │ │ │ │ ├── AccountNotificationTest.java │ │ │ │ └── MosaicDefinitionCreationNotificationTest.java │ │ │ ├── mosaic │ │ │ │ └── MosaicFeeInformationTest.java │ │ │ ├── TransactionExecutionStateTest.java │ │ │ └── primitive │ │ │ │ ├── SupplyTest.java │ │ │ │ ├── NodeIdTest.java │ │ │ │ └── QuantityTest.java │ │ │ └── i18n │ │ │ └── UTF8ResourceBundleControlTest.java │ └── main │ │ ├── resources │ │ ├── nemesis.bin │ │ ├── nemesis-mijinnet.bin │ │ └── nemesis-testnet.bin │ │ └── java │ │ └── org │ │ └── nem │ │ └── core │ │ ├── connect │ │ ├── client │ │ │ ├── AsyncNisConnector.java │ │ │ └── ErrorResponseStrategy.java │ │ ├── HttpPostRequest.java │ │ ├── ContentType.java │ │ ├── HttpVoidResponseStrategy.java │ │ ├── HttpBinaryPostRequest.java │ │ ├── HttpResponseStrategy.java │ │ └── FatalPeerException.java │ │ ├── node │ │ ├── ApiId.java │ │ ├── InvalidNodeEndpointException.java │ │ └── NodeStatus.java │ │ ├── model │ │ ├── NemNodeType.java │ │ ├── BlockTypes.java │ │ ├── MessageTypes.java │ │ ├── observers │ │ │ ├── NamedObserver.java │ │ │ ├── TransactionObserver.java │ │ │ ├── Notification.java │ │ │ ├── AccountNotification.java │ │ │ └── TransactionHashesNotification.java │ │ ├── mosaic │ │ │ ├── MosaicLevyLookup.java │ │ │ ├── MosaicFeeInformationLookup.java │ │ │ └── MosaicTransferFeeCalculator.java │ │ ├── ZeroTransactionFeeCalculator.java │ │ ├── primitive │ │ │ ├── NegativeBalanceException.java │ │ │ ├── NegativeQuantityException.java │ │ │ ├── NodeId.java │ │ │ └── NodeAge.java │ │ ├── ncc │ │ │ ├── AccountIdBuilder.java │ │ │ ├── PublicKeyBuilder.java │ │ │ ├── AccountMetaDataPair.java │ │ │ └── NamespaceMetaDataPair.java │ │ ├── BlockChainConstants.java │ │ └── TransactionFeeCalculator.java │ │ ├── serialization │ │ ├── AddressEncoding.java │ │ ├── SerializableEntity.java │ │ ├── ObjectDeserializer.java │ │ ├── SimpleAccountLookup.java │ │ ├── MissingRequiredPropertyException.java │ │ ├── TypeMismatchException.java │ │ ├── SerializationContext.java │ │ └── AccountLookup.java │ │ ├── crypto │ │ ├── KeyAnalyzer.java │ │ ├── ed25519 │ │ │ ├── Ed25519KeyAnalyzer.java │ │ │ └── arithmetic │ │ │ │ └── CoordinateSystem.java │ │ ├── KeyGenerator.java │ │ ├── Curve.java │ │ ├── BlockCipher.java │ │ ├── secp256k1 │ │ │ └── SecP256K1KeyAnalyzer.java │ │ └── CryptoException.java │ │ ├── time │ │ ├── synchronization │ │ │ └── TimeSynchronizer.java │ │ └── TimeProvider.java │ │ ├── math │ │ └── MatrixNonZeroElementRowIterator.java │ │ ├── function │ │ ├── QuadFunction.java │ │ └── PentaFunction.java │ │ ├── async │ │ ├── SleepFuture.java │ │ ├── AsyncTimerOptions.java │ │ └── UniformDelayStrategy.java │ │ └── utils │ │ └── StringEncoder.java ├── .gitignore ├── Jenkinsfile └── bumpversion.bat ├── nis ├── docs │ ├── image002.png │ └── fonts │ │ ├── Roboto-Black.ttf │ │ ├── Roboto-Bold.ttf │ │ ├── Roboto-Light.ttf │ │ ├── Roboto-Thin.ttf │ │ ├── Roboto-Italic.ttf │ │ ├── Roboto-Medium.ttf │ │ ├── Roboto-Regular.ttf │ │ ├── Roboto-BoldItalic.ttf │ │ ├── Roboto-ThinItalic.ttf │ │ ├── Roboto-BlackItalic.ttf │ │ ├── Roboto-LightItalic.ttf │ │ └── Roboto-MediumItalic.ttf ├── scripts │ └── ci │ │ ├── build.sh │ │ ├── lint.sh │ │ ├── test.sh │ │ ├── setup_build.sh │ │ └── setup_lint.sh ├── src │ ├── test │ │ ├── resources │ │ │ ├── test.properties │ │ │ └── logalpha.properties │ │ └── java │ │ │ └── org │ │ │ └── nem │ │ │ └── nis │ │ │ ├── cache │ │ │ ├── DefaultAccountCacheTest.java │ │ │ ├── DefaultMosaicIdCacheTest.java │ │ │ ├── DefaultExpiredMosaicCacheTest.java │ │ │ ├── DefaultAccountStateCacheTest.java │ │ │ ├── SynchronizedAccountCacheTest.java │ │ │ ├── SynchronizedMosaicIdCacheTest.java │ │ │ ├── SynchronizedExpiredMosaicCacheTest.java │ │ │ ├── SynchronizedAccountStateCacheTest.java │ │ │ ├── DefaultPoxFacadeTest.java │ │ │ ├── SynchronizedPoxFacadeTest.java │ │ │ ├── DefaultNamespaceCacheTest.java │ │ │ ├── SynchronizedHashCacheTest.java │ │ │ ├── SynchronizedNamespaceCacheTest.java │ │ │ └── delta │ │ │ │ └── ImmutableObjectDeltaMapTest.java │ │ │ ├── pox │ │ │ └── poi │ │ │ │ ├── graph │ │ │ │ ├── ScanClusteringStrategyTest.java │ │ │ │ └── FastScanClusteringStrategyTest.java │ │ │ │ └── PoiUtilsTest.java │ │ │ ├── test │ │ │ ├── ValidationStates.java │ │ │ ├── PageRankScorer.java │ │ │ ├── MockImportanceCalculator.java │ │ │ ├── BlockChain │ │ │ │ └── TestOptions.java │ │ │ └── DebitPredicates.java │ │ │ ├── validators │ │ │ ├── NamedValidatorTest.java │ │ │ ├── integration │ │ │ │ └── SingleBlockBlockChainValidatorTransactionValidationTest.java │ │ │ └── transaction │ │ │ │ └── TSingleTransactionValidatorTest.java │ │ │ ├── controller │ │ │ └── requests │ │ │ │ ├── NamespaceIdBuilderTest.java │ │ │ │ ├── DefaultPageBuilderTest.java │ │ │ │ ├── HashBuilderTest.java │ │ │ │ └── MosaicIdBuilderTest.java │ │ │ ├── FeeForkTest.java │ │ │ ├── mappers │ │ │ └── NisMapperFactoryTest.java │ │ │ ├── harvesting │ │ │ └── GeneratedBlockTest.java │ │ │ ├── secret │ │ │ └── BlockNotificationContextTest.java │ │ │ └── dbmodel │ │ │ └── DbBlockExtensionsTest.java │ └── main │ │ ├── resources │ │ ├── db │ │ │ └── h2 │ │ │ │ ├── V1.0.2__increase_message_size.sql │ │ │ │ ├── V1.0.5__add_accounts_index.sql │ │ │ │ ├── V1.0.6__increase_message_size.sql │ │ │ │ ├── V1.0.7__increase_message_size.sql │ │ │ │ └── V1.0.1__min_cosignatories.sql │ │ ├── db.properties │ │ └── logalpha.properties │ │ └── java │ │ └── org │ │ └── nem │ │ ├── nis │ │ ├── dao │ │ │ ├── TransferDao.java │ │ │ ├── mappers │ │ │ │ ├── AccountRawToDbModelMapping.java │ │ │ │ ├── MosaicRawToDbModelMapping.java │ │ │ │ ├── MosaicPropertyRawToDbModelMapping.java │ │ │ │ └── MultisigSignatureRawToDbModelMapping.java │ │ │ ├── AccountDao.java │ │ │ ├── BlockDao.java │ │ │ └── HibernateUtils.java │ │ ├── dbmodel │ │ │ ├── DbMultisigSend.java │ │ │ ├── DbMultisigReceive.java │ │ │ ├── DbMultisigSignatureTransaction.java │ │ │ ├── DbMosaicId.java │ │ │ ├── DbMultisigMinCosignatoriesModification.java │ │ │ └── DbBlockExtensions.java │ │ ├── cache │ │ │ ├── CommittableCache.java │ │ │ ├── delta │ │ │ │ ├── Copyable.java │ │ │ │ └── CopyableDeltaMap.java │ │ │ ├── ExtendedAccountCache.java │ │ │ ├── ExtendedNamespaceCache.java │ │ │ ├── ExtendedAccountStateCache.java │ │ │ ├── DeepCopyableCache.java │ │ │ ├── CopyableCache.java │ │ │ ├── ReadOnlyAccountCache.java │ │ │ ├── PoxFacade.java │ │ │ ├── ReadOnlyPoxFacade.java │ │ │ ├── AccountCache.java │ │ │ └── ReadOnlyExpiredMosaicCache.java │ │ ├── controller │ │ │ ├── annotations │ │ │ │ ├── P2PApi.java │ │ │ │ ├── AuthenticatedApi.java │ │ │ │ ├── ClientApi.java │ │ │ │ ├── TrustedApi.java │ │ │ │ └── PublicApi.java │ │ │ ├── interceptors │ │ │ │ └── UnauthorizedAccessException.java │ │ │ └── requests │ │ │ │ ├── HashBuilder.java │ │ │ │ ├── MosaicIdBuilder.java │ │ │ │ ├── NamespaceIdBuilder.java │ │ │ │ ├── DefaultPageBuilder.java │ │ │ │ ├── BlockHeightBuilder.java │ │ │ │ ├── AccountNamespaceBuilder.java │ │ │ │ ├── AccountTransactionsIdBuilder.java │ │ │ │ └── AccountTransactionsId.java │ │ ├── sync │ │ │ ├── UpdateChainResult.java │ │ │ ├── BlockChainScoreManager.java │ │ │ └── DefaultComparisonContext.java │ │ ├── secret │ │ │ ├── NotificationTrigger.java │ │ │ ├── BlockTransactionObserver.java │ │ │ ├── ObserverOption.java │ │ │ └── pruning │ │ │ │ └── TransactionHashCachePruningObserver.java │ │ ├── validators │ │ │ ├── NamedValidator.java │ │ │ ├── BlockValidator.java │ │ │ ├── block │ │ │ │ ├── BlockNetworkValidator.java │ │ │ │ ├── VersionBlockValidator.java │ │ │ │ ├── TransactionDeadlineBlockValidator.java │ │ │ │ ├── MaxTransactionsBlockValidator.java │ │ │ │ └── BlockNonFutureEntityValidator.java │ │ │ ├── transaction │ │ │ │ ├── TransactionNetworkValidator.java │ │ │ │ └── TransactionNonFutureEntityValidator.java │ │ │ ├── SingleTransactionValidator.java │ │ │ ├── BatchTransactionValidator.java │ │ │ ├── DebitPredicate.java │ │ │ └── NetworkValidator.java │ │ ├── visitors │ │ │ ├── BlockVisitor.java │ │ │ ├── AggregateBlockVisitor.java │ │ │ └── UndoBlockVisitor.java │ │ ├── service │ │ │ ├── BlockIo.java │ │ │ └── TransactionIo.java │ │ ├── chain │ │ │ └── BlockProcessor.java │ │ ├── pox │ │ │ ├── poi │ │ │ │ ├── graph │ │ │ │ │ ├── GraphClusteringStrategy.java │ │ │ │ │ ├── SimilarityStrategy.java │ │ │ │ │ ├── NeighborhoodRepository.java │ │ │ │ │ └── OutlierScan.java │ │ │ │ ├── ImportanceScorer.java │ │ │ │ └── ImportanceScorerContext.java │ │ │ └── ImportanceCalculator.java │ │ ├── mappers │ │ │ ├── AccountDaoLookup.java │ │ │ ├── IMapping.java │ │ │ ├── IMapper.java │ │ │ ├── MosaicPropertyDbModelToModelMapping.java │ │ │ ├── MosaicPropertyModelToDbModelMapping.java │ │ │ ├── MapperFactory.java │ │ │ ├── NisModelToDbModelMapper.java │ │ │ ├── AccountModelToDbModelMapping.java │ │ │ ├── MosaicDbModelToModelMapping.java │ │ │ ├── MultisigSignatureModelToDbModelMapping.java │ │ │ └── MosaicModelToDbModelMapping.java │ │ ├── boot │ │ │ └── NetworkHostBootstrapper.java │ │ ├── state │ │ │ ├── ReadOnlyNamespaceEntry.java │ │ │ ├── WeightedBalanceDecayConstants.java │ │ │ ├── ExpiredMosaicType.java │ │ │ ├── ReadOnlyMosaicEntry.java │ │ │ ├── ReadOnlyWeightedBalances.java │ │ │ └── ReadOnlyHistoricalImportances.java │ │ ├── websocket │ │ │ ├── BlockListener.java │ │ │ └── UnconfirmedTransactionListener.java │ │ ├── FatalConfigException.java │ │ ├── time │ │ │ └── synchronization │ │ │ │ ├── TimeSynchronizationConnector.java │ │ │ │ ├── filter │ │ │ │ ├── SynchronizationFilter.java │ │ │ │ ├── ResponseDelayDetectionFilter.java │ │ │ │ └── AlphaTrimmedMeanFilter.java │ │ │ │ ├── TimeSynchronizationException.java │ │ │ │ └── TimeSynchronizationStrategy.java │ │ └── harvesting │ │ │ ├── NewBlockTransactionsProvider.java │ │ │ ├── UnlockResult.java │ │ │ └── GeneratedBlock.java │ │ └── specific │ │ └── deploy │ │ └── IpDetectionMode.java ├── Jenkinsfile ├── .gitignore └── bumpversion.bat ├── peer ├── scripts │ └── ci │ │ ├── build.sh │ │ ├── lint.sh │ │ ├── test.sh │ │ └── setup_build.sh ├── .gitignore ├── Jenkinsfile ├── src │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── nem │ │ │ └── peer │ │ │ ├── trust │ │ │ ├── score │ │ │ │ ├── CredibilityScores.java │ │ │ │ ├── TrustScore.java │ │ │ │ ├── CredibilityScore.java │ │ │ │ ├── Score.java │ │ │ │ ├── RealDouble.java │ │ │ │ ├── PositiveLong.java │ │ │ │ └── TrustScores.java │ │ │ ├── TrustProvider.java │ │ │ └── NodeSelector.java │ │ │ ├── connect │ │ │ ├── CommunicationMode.java │ │ │ ├── SyncConnectorPool.java │ │ │ └── Communicator.java │ │ │ ├── node │ │ │ ├── NodeCompatibilityChecker.java │ │ │ └── NodeChallengeFactory.java │ │ │ ├── BlockSynchronizer.java │ │ │ ├── PeerNetworkNodeSelectorFactory.java │ │ │ └── services │ │ │ └── InactiveNodePruner.java │ └── test │ │ └── java │ │ └── org │ │ └── nem │ │ └── peer │ │ ├── test │ │ ├── MockScore.java │ │ ├── MockScores.java │ │ └── MockTrustProvider.java │ │ └── trust │ │ ├── score │ │ ├── TrustScoreTest.java │ │ ├── CredibilityScoreTest.java │ │ └── ScoreTest.java │ │ └── BasicNodeSelectorTest.java └── bumpversion.bat ├── deploy ├── scripts │ └── ci │ │ ├── build.sh │ │ ├── lint.sh │ │ ├── test.sh │ │ └── setup_build.sh ├── .gitignore ├── Jenkinsfile ├── bumpversion.bat └── src │ ├── test │ ├── resources │ │ └── logalpha.properties │ └── java │ │ └── org │ │ └── nem │ │ └── deploy │ │ └── test │ │ └── MockHttpOutputMessage.java │ └── main │ └── java │ └── org │ └── nem │ └── deploy │ ├── NemFormatter.java │ └── SerializationPolicy.java ├── .gitmodules ├── init.sh └── .gitignore /tests: -------------------------------------------------------------------------------- 1 | _symbol/tests -------------------------------------------------------------------------------- /jenkins: -------------------------------------------------------------------------------- 1 | _symbol/jenkins -------------------------------------------------------------------------------- /linters: -------------------------------------------------------------------------------- 1 | _symbol/linters -------------------------------------------------------------------------------- /infra/version.current.txt: -------------------------------------------------------------------------------- 1 | 0.6.102 2 | -------------------------------------------------------------------------------- /infra/package/libs/_dir_needs_to_exists.txt: -------------------------------------------------------------------------------- 1 | "" 2 | -------------------------------------------------------------------------------- /.gitlintmodules: -------------------------------------------------------------------------------- 1 | core|deploy|gocrypto|infra|nis|peer 2 | -------------------------------------------------------------------------------- /.github/jenkinsfile/nightlyBuild.groovy: -------------------------------------------------------------------------------- 1 | nightlyBuildPipeline {} 2 | -------------------------------------------------------------------------------- /gocrypto/scripts/ci/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | go build -v ./... 6 | -------------------------------------------------------------------------------- /gocrypto/scripts/ci/lint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | golangci-lint run 6 | -------------------------------------------------------------------------------- /gocrypto/scripts/ci/setup_lint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | go get . 6 | -------------------------------------------------------------------------------- /core/scripts/ci/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | mvn clean compile -B 6 | 7 | -------------------------------------------------------------------------------- /core/scripts/ci/lint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | mvn spotless:check -B 6 | 7 | -------------------------------------------------------------------------------- /nis/docs/image002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/image002.png -------------------------------------------------------------------------------- /nis/scripts/ci/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | mvn clean compile -B 6 | 7 | -------------------------------------------------------------------------------- /nis/scripts/ci/lint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | mvn spotless:check -B 6 | 7 | -------------------------------------------------------------------------------- /peer/scripts/ci/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | mvn clean compile -B 6 | 7 | -------------------------------------------------------------------------------- /peer/scripts/ci/lint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | mvn spotless:check -B 6 | 7 | -------------------------------------------------------------------------------- /deploy/scripts/ci/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | mvn clean compile -B 6 | 7 | -------------------------------------------------------------------------------- /deploy/scripts/ci/lint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | mvn spotless:check -B 6 | 7 | -------------------------------------------------------------------------------- /nis/src/test/resources/test.properties: -------------------------------------------------------------------------------- 1 | Ascii=something simple 2 | Utf8=something with german umlaut: äöü 3 | -------------------------------------------------------------------------------- /core/src/test/resources/test.properties: -------------------------------------------------------------------------------- 1 | Ascii=something simple 2 | Utf8=something with german umlaut: äöü 3 | -------------------------------------------------------------------------------- /nis/docs/fonts/Roboto-Black.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/fonts/Roboto-Black.ttf -------------------------------------------------------------------------------- /nis/docs/fonts/Roboto-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/fonts/Roboto-Bold.ttf -------------------------------------------------------------------------------- /nis/docs/fonts/Roboto-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/fonts/Roboto-Light.ttf -------------------------------------------------------------------------------- /nis/docs/fonts/Roboto-Thin.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/fonts/Roboto-Thin.ttf -------------------------------------------------------------------------------- /nis/docs/fonts/Roboto-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/fonts/Roboto-Italic.ttf -------------------------------------------------------------------------------- /nis/docs/fonts/Roboto-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/fonts/Roboto-Medium.ttf -------------------------------------------------------------------------------- /nis/docs/fonts/Roboto-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/fonts/Roboto-Regular.ttf -------------------------------------------------------------------------------- /nis/scripts/ci/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | mvn test -B 6 | mvn failsafe:integration-test -B 7 | 8 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "_symbol"] 2 | path = _symbol 3 | url = https://github.com/symbol/symbol 4 | branch = dev 5 | -------------------------------------------------------------------------------- /core/scripts/ci/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | mvn test -B 6 | mvn failsafe:integration-test -B 7 | 8 | -------------------------------------------------------------------------------- /core/src/main/resources/nemesis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/core/src/main/resources/nemesis.bin -------------------------------------------------------------------------------- /deploy/scripts/ci/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | mvn test -B 6 | mvn failsafe:integration-test -B 7 | 8 | -------------------------------------------------------------------------------- /nis/docs/fonts/Roboto-BoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/fonts/Roboto-BoldItalic.ttf -------------------------------------------------------------------------------- /nis/docs/fonts/Roboto-ThinItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/fonts/Roboto-ThinItalic.ttf -------------------------------------------------------------------------------- /peer/scripts/ci/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | mvn test -B 6 | mvn failsafe:integration-test -B 7 | 8 | -------------------------------------------------------------------------------- /infra/package/runNis.bat: -------------------------------------------------------------------------------- 1 | pushd nis 2 | java -Xms4G -Xmx6G -cp ".;./*;../libs/*" org.nem.deploy.CommonStarter 3 | popd 4 | -------------------------------------------------------------------------------- /nis/docs/fonts/Roboto-BlackItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/fonts/Roboto-BlackItalic.ttf -------------------------------------------------------------------------------- /nis/docs/fonts/Roboto-LightItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/fonts/Roboto-LightItalic.ttf -------------------------------------------------------------------------------- /nis/docs/fonts/Roboto-MediumItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/nis/docs/fonts/Roboto-MediumItalic.ttf -------------------------------------------------------------------------------- /.github/jenkinsfile/controller.groovy: -------------------------------------------------------------------------------- 1 | monorepoControllerPipeline { 2 | operatingSystem = ['ubuntu'] 3 | instanceSize = 'small' 4 | } 5 | -------------------------------------------------------------------------------- /core/src/main/resources/nemesis-mijinnet.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/core/src/main/resources/nemesis-mijinnet.bin -------------------------------------------------------------------------------- /core/src/main/resources/nemesis-testnet.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NemProject/nem/HEAD/core/src/main/resources/nemesis-testnet.bin -------------------------------------------------------------------------------- /infra/package/nix.runNis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd nis 4 | java -Xms4G -Xmx6G -cp ".:./*:../libs/*" org.nem.deploy.CommonStarter 5 | cd - 6 | -------------------------------------------------------------------------------- /nis/src/main/resources/db/h2/V1.0.2__increase_message_size.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE public.transfers ALTER COLUMN messagePayload VARBINARY(162); 2 | -------------------------------------------------------------------------------- /nis/src/main/resources/db/h2/V1.0.5__add_accounts_index.sql: -------------------------------------------------------------------------------- 1 | CREATE UNIQUE INDEX IDX_ACCOUNTS_PRINTABLEKEY ON `accounts` (printableKey); 2 | -------------------------------------------------------------------------------- /nis/src/main/resources/db/h2/V1.0.6__increase_message_size.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE public.transfers ALTER COLUMN messagePayload VARBINARY(322); 2 | -------------------------------------------------------------------------------- /nis/src/main/resources/db/h2/V1.0.7__increase_message_size.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE public.transfers ALTER COLUMN messagePayload VARBINARY(1026); 2 | -------------------------------------------------------------------------------- /peer/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | *~ 3 | *.orig 4 | *.bak 5 | *.iml 6 | .idea 7 | .settings 8 | out 9 | .classpath 10 | .project -------------------------------------------------------------------------------- /core/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | *~ 3 | *.orig 4 | *.bak 5 | *.iml 6 | .idea 7 | .DS_Store 8 | .classpath 9 | .project 10 | .settings/ 11 | -------------------------------------------------------------------------------- /deploy/scripts/ci/setup_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | # build core 6 | pushd ../core 7 | mvn install -DskipTests=true -B 8 | popd 9 | -------------------------------------------------------------------------------- /peer/scripts/ci/setup_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | # build core 6 | pushd ../core 7 | mvn install -DskipTests=true -B 8 | popd 9 | -------------------------------------------------------------------------------- /deploy/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | *~ 3 | *.orig 4 | *.bak 5 | *.iml 6 | .idea 7 | .settings/ 8 | .vscode/ 9 | .classpath 10 | .project 11 | bin/ -------------------------------------------------------------------------------- /infra/jenkins/seed-job/Jenkinsfile: -------------------------------------------------------------------------------- 1 | monorepoSeedPipeline { 2 | platform = ['ubuntu'] 3 | organizationName = 'Nem' 4 | gitHubId = 'Nem-Github-app' 5 | } 6 | -------------------------------------------------------------------------------- /nis/scripts/ci/setup_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | # build deps 6 | for folder in core deploy peer 7 | do 8 | pushd "../${folder}" 9 | mvn install -DskipTests=true -B 10 | popd 11 | done 12 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dao/TransferDao.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dao; 2 | 3 | /** 4 | * DAO for accessing db transfer objects. 5 | */ 6 | public interface TransferDao extends ReadOnlyTransferDao { 7 | } 8 | -------------------------------------------------------------------------------- /nis/scripts/ci/setup_lint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | echo $(mvn -f $(git rev-parse --show-toplevel) -Dexec.executable='echo' -Dexec.args='${project.version}' --non-recursive exec:exec -q) > version.txt 6 | -------------------------------------------------------------------------------- /gocrypto/go.mod: -------------------------------------------------------------------------------- 1 | module NemProject/gocrypto 2 | 3 | go 1.22.5 4 | 5 | require ( 6 | filippo.io/edwards25519 v1.1.0 7 | golang.org/x/crypto v0.31.0 8 | ) 9 | 10 | require golang.org/x/sys v0.28.0 // indirect 11 | -------------------------------------------------------------------------------- /infra/package.pack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | packageName="nis-$(ls package/nis/nem-infra* | sed 's/.*-\(.*\)\jar*/\1/')" 4 | 5 | echo " [+] CREATING tgz" 6 | tar -czpf $packageName.tgz package 7 | sha256sum $packageName.tgz 8 | -------------------------------------------------------------------------------- /core/Jenkinsfile: -------------------------------------------------------------------------------- 1 | defaultCiPipeline { 2 | operatingSystem = ['ubuntu'] 3 | instanceSize = 'medium' 4 | 5 | ciBuildDockerfile = 'java.Dockerfile' 6 | 7 | packageId = 'nem-core' 8 | 9 | codeCoverageTool = 'jacoco' 10 | } 11 | 12 | -------------------------------------------------------------------------------- /peer/Jenkinsfile: -------------------------------------------------------------------------------- 1 | defaultCiPipeline { 2 | operatingSystem = ['ubuntu'] 3 | instanceSize = 'medium' 4 | 5 | ciBuildDockerfile = 'java.Dockerfile' 6 | 7 | packageId = 'nem-peer' 8 | 9 | codeCoverageTool = 'jacoco' 10 | } 11 | 12 | -------------------------------------------------------------------------------- /deploy/Jenkinsfile: -------------------------------------------------------------------------------- 1 | defaultCiPipeline { 2 | operatingSystem = ['ubuntu'] 3 | instanceSize = 'medium' 4 | 5 | ciBuildDockerfile = 'java.Dockerfile' 6 | 7 | packageId = 'nem-deploy' 8 | 9 | codeCoverageTool = 'jacoco' 10 | } 11 | 12 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dbmodel/DbMultisigSend.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dbmodel; 2 | 3 | import javax.persistence.*; 4 | 5 | @Entity 6 | @Table(name = "multisigsends") 7 | public class DbMultisigSend extends DbMultisigAccountAction { 8 | } 9 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dbmodel/DbMultisigReceive.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dbmodel; 2 | 3 | import javax.persistence.*; 4 | 5 | @Entity 6 | @Table(name = "multisigreceives") 7 | public class DbMultisigReceive extends DbMultisigAccountAction { 8 | } 9 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/connect/client/AsyncNisConnector.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.connect.client; 2 | 3 | /** 4 | * An asynchronous NIS connector. 5 | */ 6 | @SuppressWarnings("unused") 7 | public interface AsyncNisConnector extends AsyncNemConnector { 8 | } 9 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/CommittableCache.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | /** 4 | * A cache that can be committed. 5 | */ 6 | public interface CommittableCache { 7 | /** 8 | * Commits all changes to the "real" cache. 9 | */ 10 | void commit(); 11 | } 12 | -------------------------------------------------------------------------------- /gocrypto/Jenkinsfile: -------------------------------------------------------------------------------- 1 | defaultCiPipeline { 2 | // First OS is the default for CI 3 | operatingSystem = ['ubuntu'] 4 | instanceSize = 'medium' 5 | 6 | environment = 'golang' 7 | 8 | packageId = 'gocrypto' 9 | 10 | codeCoverageTool = 'golang' 11 | minimumCodeCoverage = 86 12 | } 13 | -------------------------------------------------------------------------------- /infra/package/README.txt: -------------------------------------------------------------------------------- 1 | Default cache size for db in standalone, has been set to 128M, 2 | if you need to lower that, you'll need to edit nis/db.properties 3 | 4 | For NIS we've also added initial and max memory that java process can get. 5 | You can modify this using the switches: 6 | -Xms4G 7 | -Xmx6G 8 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/DefaultAccountCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | public class DefaultAccountCacheTest extends AccountCacheTest { 4 | 5 | @Override 6 | protected DefaultAccountCache createAccountCache() { 7 | return new DefaultAccountCache(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/DefaultMosaicIdCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | public class DefaultMosaicIdCacheTest extends MosaicIdCacheTest { 4 | 5 | @Override 6 | protected DefaultMosaicIdCache createCache() { 7 | return new DefaultMosaicIdCache(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /gocrypto/scripts/ci/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | TEST_RUNNER="go test -v -skip TestVectors" 6 | if [ "$1" = "code-coverage" ]; then 7 | TEST_RUNNER+=" -race -cover -covermode=atomic -args -test.gocoverdir=.coverage" 8 | export CGO_ENABLED=1 9 | mkdir -p .coverage 10 | fi 11 | 12 | ${TEST_RUNNER} 13 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/node/ApiId.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.node; 2 | 3 | /** 4 | * Interface that all api ids must implement. 5 | */ 6 | public interface ApiId { 7 | 8 | /** 9 | * Gets the string representation of the api id. 10 | * 11 | * @return The string representation. 12 | */ 13 | String toString(); 14 | } 15 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/delta/Copyable.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache.delta; 2 | 3 | /** 4 | * An object that supports creating a deep copy of itself. 5 | */ 6 | public interface Copyable { 7 | /** 8 | * Creates a copy of this object. 9 | * 10 | * @return A copy of this object. 11 | */ 12 | T copy(); 13 | } 14 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/DefaultExpiredMosaicCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | public class DefaultExpiredMosaicCacheTest extends ExpiredMosaicCacheTest { 4 | @Override 5 | protected DefaultExpiredMosaicCache createImmutableCache() { 6 | return new DefaultExpiredMosaicCache(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/pox/poi/graph/ScanClusteringStrategyTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.pox.poi.graph; 2 | 3 | public class ScanClusteringStrategyTest extends ScanGraphClusteringTest { 4 | 5 | @Override 6 | protected GraphClusteringStrategy createClusteringStrategy() { 7 | return new ScanClusteringStrategy(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/NemNodeType.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model; 2 | 3 | /** 4 | * Types of NEM nodes. 5 | */ 6 | public enum NemNodeType { 7 | 8 | /** 9 | * A NIS node. 10 | */ 11 | NIS, 12 | 13 | /** 14 | * A NCC node. 15 | */ 16 | NCC, 17 | 18 | /** 19 | * A Servant node. 20 | */ 21 | Servant 22 | } 23 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/crypto/ed25519/Ed25519KeyAnalyzerTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.crypto.ed25519; 2 | 3 | import org.nem.core.crypto.*; 4 | 5 | public class Ed25519KeyAnalyzerTest extends KeyAnalyzerTest { 6 | 7 | @Override 8 | protected CryptoEngine getCryptoEngine() { 9 | return CryptoEngines.ed25519Engine(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/ExtendedAccountCache.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | /** 4 | * All the interfaces that the DefaultAccountCache is expected to implement. 5 | */ 6 | @SuppressWarnings("rawtypes") 7 | public interface ExtendedAccountCache extends AccountCache, CopyableCache, CommittableCache { 8 | } 9 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/annotations/P2PApi.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Marks controller handlers used for peer-to-peer communication 7 | */ 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface P2PApi { 11 | } 12 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/pox/poi/graph/FastScanClusteringStrategyTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.pox.poi.graph; 2 | 3 | public class FastScanClusteringStrategyTest extends ScanGraphClusteringTest { 4 | 5 | @Override 6 | protected GraphClusteringStrategy createClusteringStrategy() { 7 | return new FastScanClusteringStrategy(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/crypto/ed25519/Ed25519CryptoEngineTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.crypto.ed25519; 2 | 3 | import org.nem.core.crypto.*; 4 | 5 | public class Ed25519CryptoEngineTest extends CryptoEngineTest { 6 | 7 | @Override 8 | protected CryptoEngine getCryptoEngine() { 9 | return CryptoEngines.ed25519Engine(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /nis/Jenkinsfile: -------------------------------------------------------------------------------- 1 | defaultCiPipeline { 2 | operatingSystem = ['ubuntu'] 3 | instanceSize = 'medium' 4 | 5 | ciBuildDockerfile = 'java.Dockerfile' 6 | 7 | publisher = 'docker' 8 | dockerImageName = 'nemofficial/nis-client' 9 | dockerBuildArgs = "-f ./Dockerfile .." 10 | 11 | packageId = 'nem-nis' 12 | 13 | codeCoverageTool = 'jacoco' 14 | } 15 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/ExtendedNamespaceCache.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | /** 4 | * All the interfaces that the DefaultNamespaceCache is expected to implement. 5 | */ 6 | @SuppressWarnings("rawtypes") 7 | public interface ExtendedNamespaceCache extends NamespaceCache, CopyableCache, CommittableCache { 8 | } 9 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/annotations/AuthenticatedApi.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Marks controller handlers that are authenticated. 7 | */ 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface AuthenticatedApi { 11 | } 12 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/annotations/ClientApi.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Marks controller handlers that can be used by client application. 7 | */ 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface ClientApi { 11 | } 12 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/annotations/TrustedApi.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Marks controller handlers that require a fully trusted server. 7 | */ 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface TrustedApi { 11 | } 12 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/DefaultAccountStateCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | public class DefaultAccountStateCacheTest extends AccountStateCacheTest { 4 | 5 | @Override 6 | protected DefaultAccountStateCache createCacheWithoutAutoCache() { 7 | return new DefaultAccountStateCache(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/crypto/secp256k1/SecP256K1CryptoEngineTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.crypto.secp256k1; 2 | 3 | import org.nem.core.crypto.*; 4 | 5 | public class SecP256K1CryptoEngineTest extends CryptoEngineTest { 6 | 7 | @Override 8 | protected CryptoEngine getCryptoEngine() { 9 | return CryptoEngines.secp256k1Engine(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/trust/score/CredibilityScores.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust.score; 2 | 3 | /** 4 | * A collection of CredibilityScore objects. 5 | */ 6 | public class CredibilityScores extends Scores { 7 | 8 | @Override 9 | protected CredibilityScore createScore() { 10 | return new CredibilityScore(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/ExtendedAccountStateCache.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | /** 4 | * All the interfaces that the DefaultAccountStateCache is expected to implement. 5 | */ 6 | @SuppressWarnings("rawtypes") 7 | public interface ExtendedAccountStateCache extends AccountStateCache, CopyableCache, CommittableCache { 8 | } 9 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/sync/UpdateChainResult.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.sync; 2 | 3 | import org.nem.core.model.ValidationResult; 4 | import org.nem.core.model.primitive.BlockChainScore; 5 | 6 | public class UpdateChainResult { 7 | public ValidationResult validationResult; 8 | public BlockChainScore ourScore; 9 | public BlockChainScore peerScore; 10 | } 11 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/SynchronizedAccountCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | public class SynchronizedAccountCacheTest extends AccountCacheTest { 4 | 5 | @Override 6 | protected SynchronizedAccountCache createAccountCache() { 7 | return new SynchronizedAccountCache(new DefaultAccountCache()); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/SynchronizedMosaicIdCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | public class SynchronizedMosaicIdCacheTest extends MosaicIdCacheTest { 4 | 5 | @Override 6 | protected SynchronizedMosaicIdCache createCache() { 7 | return new SynchronizedMosaicIdCache(new DefaultMosaicIdCache()); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | git submodule update --init 6 | git -C _symbol config core.sparseCheckout true 7 | echo 'jenkins/*' >> .git/modules/_symbol/info/sparse-checkout 8 | echo 'linters/*' >> .git/modules/_symbol/info/sparse-checkout 9 | echo 'tests/*' >> .git/modules/_symbol/info/sparse-checkout 10 | git submodule update --force --checkout _symbol 11 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/connect/CommunicationMode.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.connect; 2 | 3 | /** 4 | * Possible communication modes. 5 | */ 6 | public enum CommunicationMode { 7 | 8 | /** 9 | * All communication should use JSON payloads. 10 | */ 11 | JSON, 12 | 13 | /** 14 | * All communication should use binary payloads. 15 | */ 16 | BINARY 17 | } 18 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/trust/score/TrustScore.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust.score; 2 | 3 | /** 4 | * Represents the trust one node has with another node. The default score is 0.0 (no trust). 5 | */ 6 | public class TrustScore extends Score { 7 | 8 | /** 9 | * Creates a new trust score. 10 | */ 11 | public TrustScore() { 12 | super(0.0); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/BlockTypes.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model; 2 | 3 | /** 4 | * Static class containing block type constants. 5 | */ 6 | public class BlockTypes { 7 | 8 | /** 9 | * Nemesis block type. 10 | */ 11 | public static final int NEMESIS = -1; 12 | 13 | /** 14 | * Regular block type. 15 | */ 16 | public static final int REGULAR = 1; 17 | } 18 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/serialization/AddressEncoding.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization; 2 | 3 | /** 4 | * Address encoding modes. 5 | */ 6 | public enum AddressEncoding { 7 | /** 8 | * Encodes the address as a compressed string (the default). 9 | */ 10 | COMPRESSED, 11 | 12 | /** 13 | * Encodes the address as a public key. 14 | */ 15 | PUBLIC_KEY 16 | } 17 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/MessageTypes.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model; 2 | 3 | /** 4 | * Static class containing message type constants. 5 | */ 6 | public class MessageTypes { 7 | 8 | /** 9 | * A plain message. 10 | */ 11 | public static final int PLAIN = 0x0001; 12 | 13 | /** 14 | * A secure message. 15 | */ 16 | public static final int SECURE = 0x0002; 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/secret/NotificationTrigger.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.secret; 2 | 3 | /** 4 | * Actions that can trigger notifications. 5 | */ 6 | public enum NotificationTrigger { 7 | 8 | /** 9 | * The notification was triggered by an execute action. 10 | */ 11 | Execute, 12 | 13 | /** 14 | * The notification was triggered by an undo action. 15 | */ 16 | Undo 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/SynchronizedExpiredMosaicCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | public class SynchronizedExpiredMosaicCacheTest extends ExpiredMosaicCacheTest { 4 | @Override 5 | protected SynchronizedExpiredMosaicCache createImmutableCache() { 6 | return new SynchronizedExpiredMosaicCache(new DefaultExpiredMosaicCache()); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/NamedValidator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators; 2 | 3 | /** 4 | * Interface for validators that have a name. 5 | */ 6 | public interface NamedValidator { 7 | 8 | /** 9 | * Gets the name of the validator. 10 | * 11 | * @return The name of the validator. 12 | */ 13 | default String getName() { 14 | return this.getClass().getSimpleName(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/SynchronizedAccountStateCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | public class SynchronizedAccountStateCacheTest extends AccountStateCacheTest { 4 | 5 | @Override 6 | protected SynchronizedAccountStateCache createCacheWithoutAutoCache() { 7 | return new SynchronizedAccountStateCache(new DefaultAccountStateCache()); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/trust/score/CredibilityScore.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust.score; 2 | 3 | /** 4 | * Represents the credibility one node has with another node. The default score is 1.0 (full credibility). 5 | */ 6 | public class CredibilityScore extends Score { 7 | 8 | /** 9 | * Creates a new credibility score. 10 | */ 11 | public CredibilityScore() { 12 | super(1.0); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/DefaultPoxFacadeTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | import org.nem.nis.pox.ImportanceCalculator; 4 | 5 | public class DefaultPoxFacadeTest extends PoxFacadeTest { 6 | 7 | @Override 8 | protected DefaultPoxFacade createPoxFacade(final ImportanceCalculator importanceCalculator) { 9 | return new DefaultPoxFacade(importanceCalculator); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /core/bumpversion.bat: -------------------------------------------------------------------------------- 1 | rem batch files have funny escaping 2 | rem 3 | 4 | awk "{ if (match($0, /(.*\.)([0-9]+)(-BETA.*)/, arr)) { printf \"%%s%%d%%s\n\", arr[1], arr[2]+1, arr[3] } else { print } }" < pom.xml > pom.out 5 | tr --delete "\r" < pom.out > pom.xml 6 | rm pom.out 7 | 8 | git add pom.xml 9 | sed -n "/BETA/{ s/.*\([0-9]\+.[0-9]\+.[0-9]\+-BETA\).*/bump version to \1/; p }" pom.xml | xargs -iXX git commit -m XX 10 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/observers/NamedObserver.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.observers; 2 | 3 | /** 4 | * Interface for observers that have a name. 5 | */ 6 | public interface NamedObserver { 7 | 8 | /** 9 | * Gets the name of the observer. 10 | * 11 | * @return The name of the observer. 12 | */ 13 | default String getName() { 14 | return this.getClass().getSimpleName(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /deploy/bumpversion.bat: -------------------------------------------------------------------------------- 1 | rem batch files have funny escaping 2 | rem 3 | 4 | awk "{ if (match($0, /(.*\.)([0-9]+)(-BETA.*)/, arr)) { printf \"%%s%%d%%s\n\", arr[1], arr[2]+1, arr[3] } else { print } }" < pom.xml > pom.out 5 | tr --delete "\r" < pom.out > pom.xml 6 | rm pom.out 7 | 8 | git add pom.xml 9 | sed -n "/BETA/{ s/.*\([0-9]\+.[0-9]\+.[0-9]\+-BETA\).*/bump version to \1/; p }" pom.xml | xargs -iXX git commit -m XX 10 | -------------------------------------------------------------------------------- /nis/.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | target/ 3 | superlog.txt 4 | *~ 5 | *.eml 6 | *.pyc 7 | *.db 8 | my.*.sh 9 | *.jar 10 | .DS_Store 11 | /site 12 | nis-*.log* 13 | /dependency-reduced-pom.xml 14 | /nis.temp.settings 15 | /data/ 16 | /logs/ 17 | *.iml 18 | poiAnalysisData 19 | .ipynb_checkpoints 20 | /kaiseki/*.csv 21 | /node_modules/ 22 | nickel/dist/ 23 | nickel/build/ 24 | node_modules/ 25 | .classpath 26 | .project 27 | .settings -------------------------------------------------------------------------------- /peer/bumpversion.bat: -------------------------------------------------------------------------------- 1 | rem batch files have funny escaping 2 | rem 3 | 4 | awk "{ if (match($0, /(.*\.)([0-9]+)(-BETA.*)/, arr)) { printf \"%%s%%d%%s\n\", arr[1], arr[2]+1, arr[3] } else { print } }" < pom.xml > pom.out 5 | tr --delete "\r" < pom.out > pom.xml 6 | rm pom.out 7 | 8 | git add pom.xml 9 | sed -n "/BETA/{ s/.*\([0-9]\+.[0-9]\+.[0-9]\+-BETA\).*/bump version to \1/; p }" pom.xml | xargs -iXX git commit -m XX 10 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/serialization/SerializableEntity.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization; 2 | 3 | /** 4 | * An interface that should be implemented by classes that support serialization. 5 | */ 6 | public interface SerializableEntity { 7 | 8 | /** 9 | * Serializes this entity. 10 | * 11 | * @param serializer The serializer to use. 12 | */ 13 | void serialize(final Serializer serializer); 14 | } 15 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/DeepCopyableCache.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | /** 4 | * A cache that can be deep copied. 5 | */ 6 | @SuppressWarnings("rawtypes") 7 | public interface DeepCopyableCache extends CopyableCache { 8 | 9 | /** 10 | * Creates a deep copy of this cache. 11 | * 12 | * @return A deep copy of this cache. 13 | */ 14 | TDerived deepCopy(); 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | # Editors 26 | .vscode/ 27 | .idea/ 28 | *.iml 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/serialization/ObjectDeserializer.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization; 2 | 3 | /** 4 | * An interface for activating an object. 5 | */ 6 | public interface ObjectDeserializer { 7 | 8 | /** 9 | * Deserializes and creates an object of type T. 10 | * 11 | * @param deserializer The deserializer. 12 | * @return The activated object. 13 | */ 14 | T deserialize(final Deserializer deserializer); 15 | } 16 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/annotations/PublicApi.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Marks controller handlers that are publicly available (must take arguments as @RequestParam and should be GET-based) Any PublicApi is 7 | * also ClientApi 8 | */ 9 | @Target(ElementType.METHOD) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | public @interface PublicApi { 12 | } 13 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/visitors/BlockVisitor.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.visitors; 2 | 3 | import org.nem.core.model.Block; 4 | 5 | /** 6 | * Visitor that visits blocks. 7 | */ 8 | public interface BlockVisitor { 9 | 10 | /** 11 | * Visits a block. 12 | * 13 | * @param parentBlock The parent block, that is earlier in the chain. 14 | * @param block The block. 15 | */ 16 | void visit(final Block parentBlock, final Block block); 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/test/ValidationStates.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.test; 2 | 3 | import org.nem.nis.validators.ValidationState; 4 | 5 | /** 6 | * Validation states used for testing. 7 | */ 8 | public class ValidationStates { 9 | 10 | /** 11 | * A validation state that throws when called. 12 | */ 13 | public static final ValidationState Throw = new ValidationState(DebitPredicates.XemThrow, DebitPredicates.MosaicThrow, null); 14 | } 15 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/trust/TrustProvider.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust; 2 | 3 | /** 4 | * A trust provider that includes functionality for calculating trust values. 5 | */ 6 | public interface TrustProvider { 7 | 8 | /** 9 | * Calculates a trust vector given a trust context. 10 | * 11 | * @param context The trust context. 12 | * @return The trust result. 13 | */ 14 | TrustResult computeTrust(final TrustContext context); 15 | } 16 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/crypto/KeyAnalyzer.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.crypto; 2 | 3 | /** 4 | * Interface to analyze keys. 5 | */ 6 | public interface KeyAnalyzer { 7 | 8 | /** 9 | * Gets a value indicating whether or not the public key is compressed. 10 | * 11 | * @param publicKey The public key. 12 | * @return true if the public key is compressed, false otherwise. 13 | */ 14 | boolean isKeyCompressed(final PublicKey publicKey); 15 | } 16 | -------------------------------------------------------------------------------- /infra/package/nis/db.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName=org.h2.Driver 2 | # 3 | #${nem.folder} will be replaced by the setting from nem.folder 4 | # 5 | jdbc.url=jdbc:h2:${nem.folder}/nis/data/nis5_${nem.network};DB_CLOSE_DELAY=-1 6 | jdbc.username= 7 | jdbc.password= 8 | 9 | hibernate.dialect=org.hibernate.dialect.H2Dialect 10 | hibernate.show_sql=false 11 | hibernate.use_sql_comments=false 12 | hibernate.jdbc.batch_size=20 13 | 14 | flyway.locations=db/h2 15 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/service/BlockIo.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.service; 2 | 3 | import org.nem.core.model.Block; 4 | import org.nem.core.model.primitive.BlockHeight; 5 | 6 | public interface BlockIo { 7 | 8 | /** 9 | * Requests information about the block at the specified height. 10 | * 11 | * @param blockHeight The block height. 12 | * @return The block at specified height. 13 | */ 14 | Block getBlockAt(BlockHeight blockHeight); 15 | } 16 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/observers/TransactionObserver.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.observers; 2 | 3 | /** 4 | * An observer that notifies listeners when transactions are made. 5 | */ 6 | public interface TransactionObserver extends NamedObserver { 7 | 8 | /** 9 | * A notification event has been raised. 10 | * 11 | * @param notification The notification event arguments. 12 | */ 13 | void notify(final Notification notification); 14 | } 15 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/time/synchronization/TimeSynchronizer.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.time.synchronization; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | 5 | /** 6 | * Synchronizes the network time with other nodes. 7 | */ 8 | public interface TimeSynchronizer { 9 | 10 | /** 11 | * Synchronizes the network time with other nodes. 12 | * 13 | * @return The future. 14 | */ 15 | CompletableFuture synchronizeTime(); 16 | } 17 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/test/VerifiableEntityUtils.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.test; 2 | 3 | /** 4 | * Test utilities for testing verifiable entities. 5 | */ 6 | public class VerifiableEntityUtils { 7 | 8 | /** 9 | * The version corresponding to 1. 10 | */ 11 | public static final int VERSION_ONE = 0x98000000 | 1; 12 | 13 | /** 14 | * The version corresponding to 2. 15 | */ 16 | public static final int VERSION_TWO = 0x98000000 | 2; 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/SynchronizedPoxFacadeTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | import org.nem.nis.pox.ImportanceCalculator; 4 | 5 | public class SynchronizedPoxFacadeTest extends PoxFacadeTest { 6 | 7 | @Override 8 | protected SynchronizedPoxFacade createPoxFacade(final ImportanceCalculator importanceCalculator) { 9 | return new SynchronizedPoxFacade(new DefaultPoxFacade(importanceCalculator)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /gocrypto/scripts/ci/test_vectors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | TEST_RUNNER="go test -v -run TestVectors" 6 | if [ "$1" = "code-coverage" ]; then 7 | TEST_RUNNER+=" -race -cover -covermode=atomic -args -test.gocoverdir=.coverage" 8 | export CGO_ENABLED=1 9 | fi 10 | 11 | ${TEST_RUNNER} 12 | 13 | # merge the coverage files 14 | if [ "$1" = "code-coverage" ]; then 15 | go tool covdata textfmt -i=.coverage -o=coverage.out 16 | rm -rf .coverage 17 | fi 18 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/BlockValidator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators; 2 | 3 | import org.nem.core.model.*; 4 | 5 | /** 6 | * Interface for validating a block. 7 | */ 8 | public interface BlockValidator extends NamedValidator { 9 | 10 | /** 11 | * Checks the validity of the specified block. 12 | * 13 | * @param block The block. 14 | * @return The validation result. 15 | */ 16 | ValidationResult validate(final Block block); 17 | } 18 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/connect/HttpPostRequest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.connect; 2 | 3 | /** 4 | * An interface specifying information about an HttpPost request. 5 | */ 6 | public interface HttpPostRequest { 7 | 8 | /** 9 | * Gets the payload. 10 | * 11 | * @return The payload. 12 | */ 13 | byte[] getPayload(); 14 | 15 | /** 16 | * Gets the content type. 17 | * 18 | * @return The content type. 19 | */ 20 | String getContentType(); 21 | } 22 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/serialization/SimpleAccountLookup.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization; 2 | 3 | import org.nem.core.model.*; 4 | 5 | /** 6 | * A simpler interface for looking up accounts. 7 | */ 8 | public interface SimpleAccountLookup { 9 | 10 | /** 11 | * Looks up an account by its id. 12 | * 13 | * @param id The account id. 14 | * @return The account with the specified id. 15 | */ 16 | Account findByAddress(final Address id); 17 | } 18 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/mosaic/MosaicLevyLookup.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.mosaic; 2 | 3 | /** 4 | * An interface for looking up mosaic levy information. 5 | */ 6 | @FunctionalInterface 7 | public interface MosaicLevyLookup { 8 | 9 | /** 10 | * Looks up mosaic levy information by mosaic id. 11 | * 12 | * @param id The mosaic id. 13 | * @return The mosaic levy associated with the mosaic. 14 | */ 15 | MosaicLevy findById(final MosaicId id); 16 | } 17 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/chain/BlockProcessor.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.chain; 2 | 3 | import org.nem.core.model.Transaction; 4 | 5 | /** 6 | * An interface for processing a block. 7 | */ 8 | public interface BlockProcessor { 9 | 10 | /** 11 | * Processes the block. 12 | */ 13 | void process(); 14 | 15 | /** 16 | * Processes a transaction. 17 | * 18 | * @param transaction The transaction. 19 | */ 20 | void process(final Transaction transaction); 21 | } 22 | -------------------------------------------------------------------------------- /peer/src/test/java/org/nem/peer/test/MockScore.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.test; 2 | 3 | import org.nem.peer.trust.score.Score; 4 | 5 | /** 6 | * A mock Score implementation. 7 | */ 8 | public class MockScore extends Score { 9 | 10 | /** 11 | * The initial raw value of a MockScore. 12 | */ 13 | public static final double INITIAL_SCORE = 1.4; 14 | 15 | /** 16 | * Creates a new mock Score. 17 | */ 18 | public MockScore() { 19 | super(INITIAL_SCORE); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /deploy/src/test/resources/logalpha.properties: -------------------------------------------------------------------------------- 1 | # suppress inspection "UnusedProperty" for whole file 2 | handlers = java.util.logging.ConsoleHandler 3 | 4 | java.util.logging.ConsoleHandler.formatter = org.nem.deploy.ColorConsoleFormatter 5 | java.util.logging.ConsoleHandler.level = INFO 6 | 7 | java.util.logging.FileHandler.pattern = ${nem.folder}/nis/logs/nis-%g.log 8 | 9 | java.util.logging.SimpleFormatter.format = %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$s %5$s%6$s (%2$s)%n 10 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/pox/poi/graph/GraphClusteringStrategy.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.pox.poi.graph; 2 | 3 | /** 4 | * Interface for graph clustering strategies. 5 | */ 6 | public interface GraphClusteringStrategy { 7 | 8 | /** 9 | * Clusters a neighborhood of nodes in a graph. 10 | * 11 | * @param neighborhood The neighborhood. 12 | * @return The result of the clustering operation. 13 | */ 14 | ClusteringResult cluster(final Neighborhood neighborhood); 15 | } 16 | -------------------------------------------------------------------------------- /nis/src/test/resources/logalpha.properties: -------------------------------------------------------------------------------- 1 | # suppress inspection "UnusedProperty" for whole file 2 | handlers = java.util.logging.ConsoleHandler 3 | 4 | java.util.logging.ConsoleHandler.formatter = org.nem.deploy.ColorConsoleFormatter 5 | java.util.logging.ConsoleHandler.level = INFO 6 | 7 | java.util.logging.FileHandler.pattern = ${nem.folder}/nis/logs/nis-%g.log 8 | 9 | java.util.logging.SimpleFormatter.format = %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$s %5$s%6$s (%2$s)%n 10 | -------------------------------------------------------------------------------- /peer/src/test/java/org/nem/peer/trust/score/TrustScoreTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust.score; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | 7 | public class TrustScoreTest { 8 | 9 | @Test 10 | public void scoreHasCorrectInitialValue() { 11 | // Arrange: 12 | final Score score = new TrustScore(); 13 | 14 | // Assert: 15 | MatcherAssert.assertThat(score.score().get(), IsEqual.equalTo(0.0)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /gocrypto/go.sum: -------------------------------------------------------------------------------- 1 | filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= 2 | filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= 3 | golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= 4 | golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= 5 | golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= 6 | golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 7 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dao/mappers/AccountRawToDbModelMapping.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dao.mappers; 2 | 3 | import org.nem.nis.dbmodel.DbAccount; 4 | import org.nem.nis.mappers.IMapping; 5 | 6 | /** 7 | * A mapping that is able to map an account id to a db account. 8 | */ 9 | public class AccountRawToDbModelMapping implements IMapping { 10 | 11 | @Override 12 | public DbAccount map(final Long id) { 13 | return null == id ? null : new DbAccount(id); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/mappers/AccountDaoLookup.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.mappers; 2 | 3 | import org.nem.core.model.Address; 4 | import org.nem.nis.dbmodel.DbAccount; 5 | 6 | /** 7 | * An interface for looking up dao accounts. 8 | */ 9 | public interface AccountDaoLookup { 10 | 11 | /** 12 | * Looks up an account by its id. 13 | * 14 | * @param id The account id. 15 | * @return The account with the specified id. 16 | */ 17 | DbAccount findByAddress(final Address id); 18 | } 19 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/trust/NodeSelector.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust; 2 | 3 | import java.util.List; 4 | import org.nem.core.node.Node; 5 | 6 | /** 7 | * Interface for selecting a node. 8 | */ 9 | public interface NodeSelector { 10 | 11 | /** 12 | * Selects a single node. 13 | * 14 | * @return The node. 15 | */ 16 | Node selectNode(); 17 | 18 | /** 19 | * Selects multiple nodes. 20 | * 21 | * @return The nodes. 22 | */ 23 | List selectNodes(); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/crypto/ed25519/Ed25519KeyAnalyzer.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.crypto.ed25519; 2 | 3 | import org.nem.core.crypto.*; 4 | 5 | /** 6 | * Implementation of the key analyzer for Ed25519. 7 | */ 8 | public class Ed25519KeyAnalyzer implements KeyAnalyzer { 9 | private static final int COMPRESSED_KEY_SIZE = 32; 10 | 11 | @Override 12 | public boolean isKeyCompressed(final PublicKey publicKey) { 13 | return COMPRESSED_KEY_SIZE == publicKey.getRaw().length; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/mosaic/MosaicFeeInformationLookup.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.mosaic; 2 | 3 | /** 4 | * An interface for looking up mosaic fee information. 5 | */ 6 | @FunctionalInterface 7 | public interface MosaicFeeInformationLookup { 8 | 9 | /** 10 | * Looks up fee information by its id. 11 | * 12 | * @param id The mosaic id. 13 | * @return The fee information associated with the mosaic. 14 | */ 15 | MosaicFeeInformation findById(final MosaicId id); 16 | } 17 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/mosaic/MosaicTransferFeeCalculator.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.mosaic; 2 | 3 | /** 4 | * Interface for calculating mosaic transfer fees. 5 | */ 6 | @FunctionalInterface 7 | public interface MosaicTransferFeeCalculator { 8 | 9 | /** 10 | * Calculates the absolute levy for the specified mosaic transfer. 11 | * 12 | * @param mosaic The mosaic. 13 | * @return The absolute levy. 14 | */ 15 | MosaicLevy calculateAbsoluteLevy(final Mosaic mosaic); 16 | } 17 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/boot/NetworkHostBootstrapper.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.boot; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | import org.nem.core.node.Node; 5 | 6 | /** 7 | * Interface that exposes a function for booting a network. 8 | */ 9 | public interface NetworkHostBootstrapper { 10 | 11 | /** 12 | * Boots the network. 13 | * 14 | * @param localNode The local node. 15 | * @return Void future. 16 | */ 17 | CompletableFuture boot(Node localNode); 18 | } 19 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/connect/SyncConnectorPool.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.connect; 2 | 3 | import org.nem.core.serialization.AccountLookup; 4 | 5 | /** 6 | * Sync connector pool. 7 | */ 8 | public interface SyncConnectorPool { 9 | 10 | /** 11 | * Gets a SyncConnector instance. 12 | * 13 | * @param accountLookup The account lookup to associate with the connector. 14 | * @return The connector. 15 | */ 16 | SyncConnector getSyncConnector(final AccountLookup accountLookup); 17 | } 18 | -------------------------------------------------------------------------------- /peer/src/test/java/org/nem/peer/trust/score/CredibilityScoreTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust.score; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | 7 | public class CredibilityScoreTest { 8 | 9 | @Test 10 | public void scoreHasCorrectInitialValue() { 11 | // Arrange: 12 | final Score score = new CredibilityScore(); 13 | 14 | // Assert: 15 | MatcherAssert.assertThat(score.score().get(), IsEqual.equalTo(1.0)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/block/BlockNetworkValidator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators.block; 2 | 3 | import org.nem.core.model.*; 4 | import org.nem.nis.validators.*; 5 | 6 | /** 7 | * Block validator that validates entities match the default network 8 | */ 9 | public class BlockNetworkValidator extends NetworkValidator implements BlockValidator { 10 | 11 | @Override 12 | public ValidationResult validate(final Block block) { 13 | return this.validateNetwork(block); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/specific/deploy/IpDetectionMode.java: -------------------------------------------------------------------------------- 1 | package org.nem.specific.deploy; 2 | 3 | /** 4 | * Possible IP detection modes. 5 | */ 6 | public enum IpDetectionMode { 7 | 8 | /** 9 | * IP detection is automatic and is required for a node to boot. 10 | */ 11 | AutoRequired, 12 | 13 | /** 14 | * IP detection is automatic but is not required for a node to boot. 15 | */ 16 | AutoOptional, 17 | 18 | /** 19 | * Automatic IP detection is disabled. 20 | */ 21 | Disabled 22 | } 23 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/DefaultNamespaceCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | import org.nem.nis.ForkConfiguration; 4 | 5 | public class DefaultNamespaceCacheTest extends NamespaceCacheTest { 6 | 7 | @Override 8 | protected DefaultNamespaceCache createImmutableCache() { 9 | final ForkConfiguration forkConfiguration = new ForkConfiguration.Builder().build(); 10 | return new DefaultNamespaceCache(forkConfiguration.getMosaicRedefinitionForkHeight()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dao/AccountDao.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dao; 2 | 3 | import org.nem.nis.dbmodel.DbAccount; 4 | 5 | /** 6 | * DAO for accessing DbAccount objects 7 | */ 8 | public interface AccountDao { 9 | 10 | /** 11 | * Retrieves DbAccount from db given its printable (encoded) address. 12 | * 13 | * @param printableAddress NEM address 14 | * @return DbAccount associated with given printableAddress or null. 15 | */ 16 | DbAccount getAccountByPrintableAddress(String printableAddress); 17 | } 18 | -------------------------------------------------------------------------------- /infra/package.build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | logfile=$1 5 | 6 | pushd "$(git rev-parse --show-toplevel)" 7 | echo " [+] STARTING BUILD (this might take some time) ${logfile}" 8 | rm -rf core/src/main/resources/nemesis-mijin* 9 | rm -rf core/target/classes/nemesis-mijin* 10 | rm -rf nis/src/main/resources/*mijin* 11 | rm -rf nis/target/classes/*mijin* 12 | 13 | mvn clean install -DskipTests=true | tee -a $logfile 14 | pushd core 15 | echo " [+] CREATING DOCS" 16 | mvn javadoc:javadoc >>$logfile 17 | popd 18 | popd 19 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/crypto/KeyGenerator.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.crypto; 2 | 3 | /** 4 | * Interface for generating keys. 5 | */ 6 | public interface KeyGenerator { 7 | 8 | /** 9 | * Creates a random key pair. 10 | * 11 | * @return The key pair. 12 | */ 13 | KeyPair generateKeyPair(); 14 | 15 | /** 16 | * Derives a public key from a private key. 17 | * 18 | * @param privateKey the private key. 19 | * @return The public key. 20 | */ 21 | PublicKey derivePublicKey(final PrivateKey privateKey); 22 | } 23 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/mappers/IMapping.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.mappers; 2 | 3 | /** 4 | * Interface for mapping from a source type to a target type. 5 | * 6 | * @param The source type. 7 | * @param The target type. 8 | */ 9 | @FunctionalInterface 10 | public interface IMapping { 11 | 12 | /** 13 | * Maps source to the desired target type. 14 | * 15 | * @param source The source object. 16 | * @return The target object. 17 | */ 18 | TTarget map(final TSource source); 19 | } 20 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/state/ReadOnlyNamespaceEntry.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.state; 2 | 3 | import org.nem.core.model.namespace.Namespace; 4 | 5 | /** 6 | * A read-only namespace entry. 7 | */ 8 | public interface ReadOnlyNamespaceEntry { 9 | 10 | /** 11 | * Gets the namespace. 12 | * 13 | * @return The namespace. 14 | */ 15 | Namespace getNamespace(); 16 | 17 | /** 18 | * Gets the mosaics associated with the namespace. 19 | * 20 | * @return The mosaics. 21 | */ 22 | ReadOnlyMosaics getMosaics(); 23 | } 24 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/websocket/BlockListener.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.websocket; 2 | 3 | import java.util.Collection; 4 | import org.nem.core.model.Block; 5 | import org.nem.core.model.primitive.BlockChainScore; 6 | 7 | public interface BlockListener { 8 | /** 9 | * Publishes blocks added to the chain to BlockListener. 10 | * 11 | * @param peerChain Collection of blocks added. 12 | * @param peerScore Score of a chain. 13 | */ 14 | void pushBlocks(final Collection peerChain, final BlockChainScore peerScore); 15 | } 16 | -------------------------------------------------------------------------------- /infra/package.prepare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -gt 0 ]; then 4 | mode=mainnet 5 | fi 6 | 7 | echo -n " [+] CREATING >>" 8 | echo -n $mode | tr '[:lower:]' '[:upper:]' 9 | echo "<< PACKAGE" 10 | 11 | rm -rf package/libs/*.jar package/nis/*.jar 12 | 13 | cp -r ../nis/target/libs/*.jar package/libs 14 | rm package/libs/nem-* 15 | cp -r ../nis/target/libs/nem-*.jar package/nis 16 | cp -r ../nis/target/nem-*.jar package/nis 17 | 18 | cd package/nis 19 | sed -i "s/nem.network = .*/nem.network = $mode\r/" config.properties 20 | cd ../.. 21 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/CopyableCache.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | /** 4 | * A cache that can be copied. 5 | */ 6 | @SuppressWarnings("rawtypes") 7 | public interface CopyableCache { 8 | 9 | /** 10 | * Shallow copies this cache to another cache. 11 | * 12 | * @param rhs The other cache. 13 | */ 14 | void shallowCopyTo(final TDerived rhs); 15 | 16 | /** 17 | * Creates a copy of this cache. 18 | * 19 | * @return A copy of this cache. 20 | */ 21 | TDerived copy(); 22 | } 23 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/connect/client/ErrorResponseStrategy.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.connect.client; 2 | 3 | import org.nem.core.connect.ErrorResponse; 4 | 5 | /** 6 | * Strategy for dealing with client connection errors. 7 | */ 8 | @FunctionalInterface 9 | public interface ErrorResponseStrategy { 10 | 11 | /** 12 | * Maps an ErrorResponse to a runtime exception. 13 | * 14 | * @param response The response. 15 | * @return The runtime exception. 16 | */ 17 | RuntimeException mapToException(final ErrorResponse response); 18 | } 19 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/pox/poi/ImportanceScorer.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.pox.poi; 2 | 3 | import org.nem.core.math.ColumnVector; 4 | 5 | /** 6 | * Interface for the calculating the final importance score. 7 | */ 8 | public interface ImportanceScorer { 9 | 10 | /** 11 | * Calculates the final score for all accounts given all POI sub-scores. 12 | * 13 | * @param context The importance scorer context. 14 | * @return The final score vector. 15 | */ 16 | ColumnVector calculateFinalScore(final ImportanceScorerContext context); 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/interceptors/UnauthorizedAccessException.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.interceptors; 2 | 3 | /** 4 | * Exception that is thrown when an unauthorized request is made. 5 | */ 6 | @SuppressWarnings("serial") 7 | public class UnauthorizedAccessException extends RuntimeException { 8 | 9 | /** 10 | * Creates a new unauthorized access exception. 11 | * 12 | * @param message The exception message. 13 | */ 14 | public UnauthorizedAccessException(final String message) { 15 | super(message); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/main/resources/db/h2/V1.0.1__min_cosignatories.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS `mincosignatoriesmodifications` ( 2 | `id` BIGINT NOT NULL AUTO_INCREMENT, 3 | `relativeChange` INT NOT NULL, -- the relative change of min cosignatories 4 | 5 | PRIMARY KEY(`id`) 6 | ); 7 | 8 | ALTER TABLE public.multisigsignermodifications ADD 9 | `mincosignatoriesmodificationId` BIGINT; 10 | 11 | ALTER TABLE public.multisigsignermodifications ADD 12 | FOREIGN KEY (mincosignatoriesmodificationId) 13 | REFERENCES public.mincosignatoriesmodifications(id); 14 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/crypto/secp256k1/SecP256K1BlockCipherTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.crypto.secp256k1; 2 | 3 | import org.nem.core.crypto.*; 4 | 5 | public class SecP256K1BlockCipherTest extends BlockCipherTest { 6 | 7 | @Override 8 | protected BlockCipher getBlockCipher(final KeyPair senderKeyPair, final KeyPair recipientKeyPair) { 9 | return new SecP256K1BlockCipher(senderKeyPair, recipientKeyPair); 10 | } 11 | 12 | @Override 13 | protected CryptoEngine getCryptoEngine() { 14 | return CryptoEngines.secp256k1Engine(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nis/src/main/resources/db.properties: -------------------------------------------------------------------------------- 1 | # suppress inspection "UnusedProperty" for whole file 2 | jdbc.driverClassName=org.h2.Driver 3 | # 4 | #${nem.folder} will be replaced by the setting from nem.folder 5 | # 6 | jdbc.url=jdbc:h2:${nem.folder}/nis/data/nis5_${nem.network};DB_CLOSE_DELAY=-1 7 | jdbc.username= 8 | jdbc.password= 9 | 10 | hibernate.dialect=org.hibernate.dialect.H2Dialect 11 | hibernate.show_sql=false 12 | hibernate.use_sql_comments=false 13 | hibernate.jdbc.batch_size=20 14 | hibernate.query.startup_check=false 15 | 16 | flyway.locations=db/h2 17 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/SynchronizedHashCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | public class SynchronizedHashCacheTest extends HashCacheTest { 4 | 5 | @Override 6 | protected SynchronizedHashCache createWritableCache() { 7 | return new SynchronizedHashCache(new DefaultHashCache().copy()); 8 | } 9 | 10 | @Override 11 | protected SynchronizedHashCache createReadOnlyCacheWithRetentionTime(final int retentionTime) { 12 | return new SynchronizedHashCache(new DefaultHashCache(50, retentionTime)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /peer/src/test/java/org/nem/peer/trust/BasicNodeSelectorTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust; 2 | 3 | import java.util.Random; 4 | import org.nem.core.math.ColumnVector; 5 | 6 | public class BasicNodeSelectorTest extends NodeSelectorTest { 7 | 8 | /** 9 | * Creates the node selector to test. 10 | */ 11 | protected NodeSelector createSelector(final int maxNodes, final ColumnVector trustVector, final TrustContext context, 12 | final Random random) { 13 | return new BasicNodeSelector(maxNodes, trustVector, context.getNodes(), random); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/SynchronizedNamespaceCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | import org.nem.nis.ForkConfiguration; 4 | 5 | public class SynchronizedNamespaceCacheTest extends NamespaceCacheTest { 6 | 7 | @Override 8 | protected SynchronizedNamespaceCache createImmutableCache() { 9 | final ForkConfiguration forkConfiguration = new ForkConfiguration.Builder().build(); 10 | return new SynchronizedNamespaceCache(new DefaultNamespaceCache(forkConfiguration.getMosaicRedefinitionForkHeight())); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/ZeroTransactionFeeCalculator.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model; 2 | 3 | import org.nem.core.model.primitive.*; 4 | 5 | /** 6 | * Fee calculator that always returns zero fees and accepts any fee. 7 | */ 8 | public class ZeroTransactionFeeCalculator implements TransactionFeeCalculator { 9 | @Override 10 | public Amount calculateMinimumFee(Transaction transaction) { 11 | return Amount.ZERO; 12 | } 13 | 14 | @Override 15 | public boolean isFeeValid(Transaction transaction, BlockHeight blockHeight) { 16 | return true; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/mappers/IMapper.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.mappers; 2 | 3 | /** 4 | * An interface for mapping a source type to a target type. 5 | */ 6 | public interface IMapper { 7 | 8 | /** 9 | * Maps a source type to a target type. 10 | * 11 | * @param source The source object. 12 | * @param targetClass The target class. 13 | * @param The source type. 14 | * @param The target type. 15 | * @return The target object. 16 | */ 17 | TTarget map(final TSource source, final Class targetClass); 18 | } 19 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/test/PageRankScorer.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.test; 2 | 3 | import org.nem.core.math.ColumnVector; 4 | import org.nem.nis.pox.poi.*; 5 | 6 | /** 7 | * Importance scorer implementation that only uses page rank. 8 | */ 9 | public class PageRankScorer implements ImportanceScorer { 10 | 11 | @Override 12 | public ColumnVector calculateFinalScore(final ImportanceScorerContext context) { 13 | final ColumnVector importanceVector = context.getImportanceVector(); 14 | importanceVector.normalize(); 15 | return importanceVector; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/pox/poi/graph/SimilarityStrategy.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.pox.poi.graph; 2 | 3 | import org.nem.core.model.primitive.NodeId; 4 | 5 | /** 6 | * Strategy for calculating the similarity between two nodes. 7 | */ 8 | @FunctionalInterface 9 | public interface SimilarityStrategy { 10 | 11 | /** 12 | * Calculates structural similarity between two nodes. 13 | * 14 | * @param lhs One node id. 15 | * @param rhs The other node id. 16 | * @return The similarity score. 17 | */ 18 | double calculateSimilarity(final NodeId lhs, final NodeId rhs); 19 | } 20 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/secret/BlockTransactionObserver.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.secret; 2 | 3 | import org.nem.core.model.observers.*; 4 | 5 | /** 6 | * An observer that notifies listeners when transactions are made. 7 | */ 8 | public interface BlockTransactionObserver extends NamedObserver { 9 | 10 | /** 11 | * A notification event has been raised. 12 | * 13 | * @param notification The notification event arguments. 14 | * @param context The notification context. 15 | */ 16 | void notify(final Notification notification, final BlockNotificationContext context); 17 | } 18 | -------------------------------------------------------------------------------- /infra/package/nix.logalpha.properties: -------------------------------------------------------------------------------- 1 | handlers = org.nem.deploy.ColorConsoleHandler, java.util.logging.FileHandler 2 | .level = INFO 3 | 4 | java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter 5 | java.util.logging.ConsoleHandler.level = INFO 6 | 7 | java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter 8 | java.util.logging.FileHandler.limit = 100000000 9 | java.util.logging.FileHandler.count = 1000 10 | java.util.logging.FileHandler.pattern = nem.log 11 | 12 | java.util.logging.SimpleFormatter.format = %1$tH:%1$tM:%1$tS %4$s %5$s%6$s (%2$s)%n 13 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/ReadOnlyAccountCache.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | import org.nem.core.model.Account; 4 | import org.nem.core.serialization.AccountLookup; 5 | 6 | /** 7 | * A read only account cache. 8 | */ 9 | public interface ReadOnlyAccountCache extends AccountLookup { 10 | 11 | /** 12 | * Gets the number of accounts. 13 | * 14 | * @return The number of accounts. 15 | */ 16 | int size(); 17 | 18 | /** 19 | * Gets the contents of this cache. 20 | * 21 | * @return The cache contents. 22 | */ 23 | CacheContents contents(); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/primitive/NegativeBalanceException.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.primitive; 2 | 3 | /** 4 | * An exception that is thrown when an Amount is attempted to be created around a negative amount. 5 | */ 6 | @SuppressWarnings("serial") 7 | public class NegativeBalanceException extends IllegalArgumentException { 8 | 9 | /** 10 | * Creates a new exception. 11 | * 12 | * @param amount The negative amount. 13 | */ 14 | public NegativeBalanceException(final long amount) { 15 | super(String.format("amount (%d) must be non-negative", amount)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/mappers/MosaicPropertyDbModelToModelMapping.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.mappers; 2 | 3 | import org.nem.core.model.NemProperty; 4 | import org.nem.nis.dbmodel.DbMosaicProperty; 5 | 6 | /** 7 | * A mapping that is able to map a db mosaic property to a model nem property. 8 | */ 9 | public class MosaicPropertyDbModelToModelMapping implements IMapping { 10 | 11 | @Override 12 | public NemProperty map(final DbMosaicProperty dbMosaicProperty) { 13 | return new NemProperty(dbMosaicProperty.getName(), dbMosaicProperty.getValue()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/transaction/TransactionNetworkValidator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators.transaction; 2 | 3 | import org.nem.core.model.*; 4 | import org.nem.nis.validators.*; 5 | 6 | /** 7 | * Single transaction validator that validates entities match the default network 8 | */ 9 | public class TransactionNetworkValidator extends NetworkValidator implements SingleTransactionValidator { 10 | 11 | @Override 12 | public ValidationResult validate(final Transaction transaction, final ValidationContext context) { 13 | return this.validateNetwork(transaction); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/trust/score/Score.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust.score; 2 | 3 | /** 4 | * Represents a basic score. 5 | */ 6 | public abstract class Score { 7 | 8 | private final RealDouble score; 9 | 10 | /** 11 | * Creates a new score 12 | * 13 | * @param initialScore The initial score value. 14 | */ 15 | protected Score(final double initialScore) { 16 | this.score = new RealDouble(initialScore); 17 | } 18 | 19 | /** 20 | * Gets the raw score. 21 | * 22 | * @return The raw score. 23 | */ 24 | public RealDouble score() { 25 | return this.score; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/observers/Notification.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.observers; 2 | 3 | /** 4 | * A notification. 5 | */ 6 | public abstract class Notification { 7 | private final NotificationType type; 8 | 9 | /** 10 | * Creates a notification. 11 | * 12 | * @param type The notification type. 13 | */ 14 | public Notification(final NotificationType type) { 15 | this.type = type; 16 | } 17 | 18 | /** 19 | * Gets the notification type. 20 | * 21 | * @return The notification type. 22 | */ 23 | public NotificationType getType() { 24 | return this.type; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/primitive/NegativeQuantityException.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.primitive; 2 | 3 | /** 4 | * An exception that is thrown when a Quantity is attempted to be created around a negative quantity. 5 | */ 6 | @SuppressWarnings("serial") 7 | public class NegativeQuantityException extends IllegalArgumentException { 8 | 9 | /** 10 | * Creates a new exception. 11 | * 12 | * @param quantity The negative quantity. 13 | */ 14 | public NegativeQuantityException(final long quantity) { 15 | super(String.format("quantity (%d) must be non-negative", quantity)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /infra/package/logalpha.properties: -------------------------------------------------------------------------------- 1 | handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler 2 | .level = INFO 3 | 4 | java.util.logging.ConsoleHandler.formatter = org.nem.deploy.ColorConsoleFormatter 5 | java.util.logging.ConsoleHandler.level = INFO 6 | 7 | java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter 8 | java.util.logging.FileHandler.limit = 100000000 9 | java.util.logging.FileHandler.count = 1000 10 | java.util.logging.FileHandler.pattern = ${nemFolder}/nem/nis/logs/nis-%g.log 11 | 12 | java.util.logging.SimpleFormatter.format = %1$tH:%1$tM:%1$tS %4$s %5$s%6$s (%2$s)%n -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/SingleTransactionValidator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators; 2 | 3 | import org.nem.core.model.*; 4 | 5 | /** 6 | * Interface for validating a single transaction. 7 | */ 8 | public interface SingleTransactionValidator extends NamedValidator { 9 | 10 | /** 11 | * Checks the validity of the specified transaction. 12 | * 13 | * @param transaction The transaction. 14 | * @param context The validation context. 15 | * @return The validation result. 16 | */ 17 | ValidationResult validate(final Transaction transaction, final ValidationContext context); 18 | } 19 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/connect/ContentType.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.connect; 2 | 3 | /** 4 | * Static class containing content type constants. 5 | */ 6 | public class ContentType { 7 | 8 | /** 9 | * The content type used for binary requests and responses. 10 | */ 11 | public static final String BINARY = "application/binary"; 12 | 13 | /** 14 | * The content type used for json requests and responses. 15 | */ 16 | public static final String JSON = "application/json"; 17 | 18 | /** 19 | * The content type used for void responses. 20 | */ 21 | public static final String VOID = null; 22 | } 23 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/node/InvalidNodeEndpointException.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.node; 2 | 3 | /** 4 | * Exception that is used when an invalid NodeEndpoint is attempted to be created. 5 | */ 6 | @SuppressWarnings("serial") 7 | public class InvalidNodeEndpointException extends RuntimeException { 8 | 9 | /** 10 | * Creates a new invalid node endpoint exception. 11 | * 12 | * @param message The exception message. 13 | * @param cause The original exception. 14 | */ 15 | public InvalidNodeEndpointException(final String message, final Throwable cause) { 16 | super(message, cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/BatchTransactionValidator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators; 2 | 3 | import java.util.List; 4 | import org.nem.core.model.ValidationResult; 5 | 6 | /** 7 | * Interface for validating batches of transactions. 8 | */ 9 | public interface BatchTransactionValidator extends NamedValidator { 10 | 11 | /** 12 | * Checks the validity of the specified transactions. 13 | * 14 | * @param groupedTransactions The grouped transactions. 15 | * @return The validation result. 16 | */ 17 | ValidationResult validate(final List groupedTransactions); 18 | } 19 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/DebitPredicate.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators; 2 | 3 | import org.nem.core.model.Account; 4 | 5 | /** 6 | * Predicate that can be used to determine if an asset can be debited from an account. 7 | */ 8 | @FunctionalInterface 9 | public interface DebitPredicate { 10 | 11 | /** 12 | * Determines if the specified asset can be debited from the specified account. 13 | * 14 | * @param account The account. 15 | * @param asset The asset. 16 | * @return true if the amount can be debited. 17 | */ 18 | boolean canDebit(final Account account, final T asset); 19 | } 20 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/block/VersionBlockValidator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators.block; 2 | 3 | import org.nem.core.model.*; 4 | import org.nem.nis.validators.BlockValidator; 5 | 6 | /** 7 | * A BlockValidator implementation that validates that higher versioned blocks do not appear before the respective fork heights 8 | */ 9 | public class VersionBlockValidator implements BlockValidator { 10 | 11 | @Override 12 | public ValidationResult validate(final Block block) { 13 | return 1 == block.getEntityVersion() ? ValidationResult.SUCCESS : ValidationResult.FAILURE_ENTITY_INVALID_VERSION; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/node/NodeCompatibilityChecker.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.node; 2 | 3 | import org.nem.core.node.NodeMetaData; 4 | 5 | /** 6 | * An interface for checking the compatibility of two nodes using their metadata. 7 | */ 8 | @FunctionalInterface 9 | public interface NodeCompatibilityChecker { 10 | 11 | /** 12 | * Checks the local and remote nodes for compatibility. 13 | * 14 | * @param local The local metadata 15 | * @param remote The remote metadata. 16 | * @return true if the nodes are compatible. 17 | */ 18 | boolean check(final NodeMetaData local, final NodeMetaData remote); 19 | } 20 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/crypto/Curve.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.crypto; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * Interface for getting information for a curve. 7 | */ 8 | public interface Curve { 9 | 10 | /** 11 | * Gets the name of the curve. 12 | * 13 | * @return The name of the curve. 14 | */ 15 | String getName(); 16 | 17 | /** 18 | * Gets the group order. 19 | * 20 | * @return The group order. 21 | */ 22 | BigInteger getGroupOrder(); 23 | 24 | /** 25 | * Gets the group order / 2. 26 | * 27 | * @return The group order / 2. 28 | */ 29 | BigInteger getHalfGroupOrder(); 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/ncc/AccountIdBuilder.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.ncc; 2 | 3 | /** 4 | * Builder that is used by Spring to create an AccountId from a GET request. 5 | */ 6 | public class AccountIdBuilder { 7 | private String address; 8 | 9 | /** 10 | * Sets the address. 11 | * 12 | * @param address The address. 13 | */ 14 | public void setAddress(final String address) { 15 | this.address = address; 16 | } 17 | 18 | /** 19 | * Creates an AccountId. 20 | * 21 | * @return The account id. 22 | */ 23 | public AccountId build() { 24 | return new AccountId(this.address); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/requests/HashBuilder.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.requests; 2 | 3 | import org.nem.core.crypto.Hash; 4 | 5 | /** 6 | * Builder that is used by Spring to create a hash from a GET request. 7 | */ 8 | public class HashBuilder { 9 | private String hash; 10 | 11 | /** 12 | * Sets the hash. 13 | * 14 | * @param hash The hash. 15 | */ 16 | public void setHash(final String hash) { 17 | this.hash = hash; 18 | } 19 | 20 | /** 21 | * Creates a hash. 22 | * 23 | * @return The hash. 24 | */ 25 | public Hash build() { 26 | return Hash.fromHexString(this.hash); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/state/WeightedBalanceDecayConstants.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.state; 2 | 3 | /** 4 | * Constants related to weighted balance decays. 5 | */ 6 | public class WeightedBalanceDecayConstants { 7 | 8 | /** 9 | * The weighted balance decay numerator. 10 | */ 11 | public static final long DECAY_NUMERATOR = 9; 12 | 13 | /** 14 | * The weighted balance decay denominator. 15 | */ 16 | public static final long DECAY_DENOMINATOR = 10; 17 | 18 | /** 19 | * The weighted balance decay rate. 20 | */ 21 | public static final double DECAY_BASE = (double) DECAY_NUMERATOR / (double) DECAY_DENOMINATOR; 22 | } 23 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/crypto/BlockCipher.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.crypto; 2 | 3 | /** 4 | * Interface for encryption and decryption of data. 5 | */ 6 | public interface BlockCipher { 7 | 8 | /** 9 | * Encrypts an arbitrarily-sized message. 10 | * 11 | * @param input The message to encrypt. 12 | * @return The encrypted message. 13 | */ 14 | byte[] encrypt(final byte[] input); 15 | 16 | /** 17 | * Decrypts an arbitrarily-sized message. 18 | * 19 | * @param input The message to decrypt. 20 | * @return The decrypted message or null if decryption failed. 21 | */ 22 | byte[] decrypt(final byte[] input); 23 | } 24 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/cache/delta/ImmutableObjectDeltaMapTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache.delta; 2 | 3 | import java.util.Map; 4 | 5 | public class ImmutableObjectDeltaMapTest extends DeltaMapTest> { 6 | 7 | @Override 8 | protected ImmutableObjectDeltaMap createMapWithCapacity(final int capacity) { 9 | return new ImmutableObjectDeltaMap<>(capacity); 10 | } 11 | 12 | @Override 13 | protected ImmutableObjectDeltaMap createMapWithValues(final Map initialValues) { 14 | return new ImmutableObjectDeltaMap<>(initialValues); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/node/NodeStatus.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.node; 2 | 3 | /** 4 | * Possible statuses of a NEM node. 5 | */ 6 | public enum NodeStatus { 7 | /** 8 | * The node is active and the last request succeeded. 9 | */ 10 | ACTIVE, 11 | 12 | /** 13 | * The node is active but the last request failed due to a busy signal. 14 | */ 15 | BUSY, 16 | 17 | /** 18 | * The node is offline. 19 | */ 20 | INACTIVE, 21 | 22 | /** 23 | * The node is active but the last request failed due to a server error. 24 | */ 25 | FAILURE, 26 | 27 | /** 28 | * The node is in an unknown state. 29 | */ 30 | UNKNOWN 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/serialization/MissingRequiredPropertyException.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization; 2 | 3 | /** 4 | * Exception that is thrown to indicate a serialization failure caused by a missing required property. 5 | */ 6 | @SuppressWarnings("serial") 7 | public class MissingRequiredPropertyException extends InvalidPropertyException { 8 | 9 | /** 10 | * Creates a new exception. 11 | * 12 | * @param propertyName The missing property name. 13 | */ 14 | public MissingRequiredPropertyException(final String propertyName) { 15 | super("expected value for property %s, but none was found", propertyName); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/serialization/TypeMismatchException.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization; 2 | 3 | /** 4 | * Exception that is thrown to indicate a serialization failure caused by a property value having an incompatible type. 5 | */ 6 | @SuppressWarnings("serial") 7 | public class TypeMismatchException extends InvalidPropertyException { 8 | 9 | /** 10 | * Creates a new exception. 11 | * 12 | * @param propertyName The name of the property with the incompatible value. 13 | */ 14 | public TypeMismatchException(final String propertyName) { 15 | super("property %s has an incompatible value", propertyName); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/serialization/SerializationContextTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | 7 | public class SerializationContextTest { 8 | 9 | @Test 10 | public void contextConstantsAreInitializedCorrectly() { 11 | // Arrange: 12 | final SerializationContext context = new SerializationContext(); 13 | 14 | // Assert: 15 | MatcherAssert.assertThat(context.getDefaultMaxBytesLimit(), IsEqual.equalTo(2048)); 16 | MatcherAssert.assertThat(context.getDefaultMaxCharsLimit(), IsEqual.equalTo(128)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /infra/package/nis/logalpha.properties: -------------------------------------------------------------------------------- 1 | handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler 2 | .level = INFO 3 | 4 | java.util.logging.ConsoleHandler.formatter = org.nem.deploy.ColorConsoleFormatter 5 | java.util.logging.ConsoleHandler.level = INFO 6 | 7 | java.util.logging.FileHandler.formatter = org.nem.deploy.NemFormatter 8 | java.util.logging.FileHandler.limit = 100000000 9 | java.util.logging.FileHandler.count = 100 10 | java.util.logging.FileHandler.pattern = ${nem.folder}/nis/logs/nis-%g.log 11 | 12 | java.util.logging.SimpleFormatter.format = %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$s %5$s%6$s (%2$s)%n 13 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/pox/poi/PoiUtilsTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.pox.poi; 2 | 3 | import java.util.Arrays; 4 | import org.hamcrest.MatcherAssert; 5 | import org.hamcrest.core.IsEqual; 6 | import org.junit.*; 7 | import org.nem.core.math.ColumnVector; 8 | 9 | public class PoiUtilsTest { 10 | 11 | @Test 12 | public void dangleSumIsCalculatedCorrectly() { 13 | // Act: 14 | final double dangleSum = PoiUtils.calculateDangleSum(Arrays.asList(1, 3), 0.4, new ColumnVector(0.1, 0.8, 0.2, 0.5, 0.6, 0.3)); 15 | 16 | // Assert: sum(0.8, 0.5) * 0.4 / 6 17 | MatcherAssert.assertThat(dangleSum, IsEqual.equalTo(1.3 * 0.4 / 6)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/node/NodeChallengeFactory.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.node; 2 | 3 | import java.security.SecureRandom; 4 | 5 | /** 6 | * Factory for creating NodeChallenge. 7 | */ 8 | public class NodeChallengeFactory { 9 | 10 | private static final int CHALLENGE_SIZE = 64; 11 | private final SecureRandom secureRandom = new SecureRandom(); 12 | 13 | /** 14 | * Gets the next node challenge. 15 | * 16 | * @return A node challenge. 17 | */ 18 | public NodeChallenge next() { 19 | final byte[] bytes = new byte[CHALLENGE_SIZE]; 20 | this.secureRandom.nextBytes(bytes); 21 | return new NodeChallenge(bytes); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /nis/bumpversion.bat: -------------------------------------------------------------------------------- 1 | rem batch files have funny escaping 2 | rem 3 | 4 | awk "{ if (match($0, /(.*\.)([0-9]+)(-BETA.*)/, arr)) { printf \"%%s%%d%%s\n\", arr[1], arr[2]+1, arr[3] } else { print } }" < pom.xml > pom.out 5 | tr --delete "\r" < pom.out > pom.xml 6 | 7 | awk "{ if (match($0, /(.*\.)([0-9]+)(-BETA.*)/, arr)) { printf \"%%s%%d%%s\n\", arr[1], arr[2]+1, arr[3] } else { print } }" < pom-mariadb.xml > pom.out 8 | tr --delete "\r" < pom.out > pom-mariadb.xml 9 | rm pom.out 10 | 11 | git add pom.xml 12 | git add pom-mariadb.xml 13 | sed -n "/BETA/{ s/.*\([0-9]\+.[0-9]\+.[0-9]\+-BETA\).*/bump version to \1/; p }" pom.xml | xargs -iXX git commit -m XX 14 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/BlockSynchronizer.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer; 2 | 3 | import org.nem.core.node.Node; 4 | import org.nem.peer.connect.SyncConnectorPool; 5 | 6 | /** 7 | * Synchronizes the running node's block chain with the another node's block chain. 8 | */ 9 | public interface BlockSynchronizer { 10 | 11 | /** 12 | * Synchronizes the running node's block chain with node's block chains. 13 | * 14 | * @param connector The connector pool. 15 | * @param node The other node. 16 | * @return The synchronize node result. 17 | */ 18 | NodeInteractionResult synchronizeNode(final SyncConnectorPool connector, final Node node); 19 | } 20 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/serialization/primitive/JsonSerializationPolicy.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization.primitive; 2 | 3 | import org.nem.core.serialization.*; 4 | 5 | public class JsonSerializationPolicy extends SerializationPolicy { 6 | 7 | @Override 8 | public JsonSerializer createSerializer(final SerializationContext context) { 9 | return new JsonSerializer(context); 10 | } 11 | 12 | @Override 13 | public JsonDeserializer createDeserializer(final JsonSerializer serializer, final DeserializationContext context) { 14 | return new JsonDeserializer(serializer.getObject(), context); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/PoxFacade.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | import java.util.Collection; 4 | import org.nem.core.model.primitive.BlockHeight; 5 | import org.nem.nis.state.AccountState; 6 | 7 | /** 8 | * A mutable facade on top of pox. 9 | */ 10 | public interface PoxFacade extends ReadOnlyPoxFacade { 11 | 12 | /** 13 | * Recalculates the importance of all accounts at the specified block height. 14 | * 15 | * @param blockHeight The block height. 16 | * @param accountStates The account states. 17 | */ 18 | void recalculateImportances(final BlockHeight blockHeight, final Collection accountStates); 19 | } 20 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/state/ExpiredMosaicType.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.state; 2 | 3 | /** 4 | * Enum containing types of expired mosaics. 5 | */ 6 | public enum ExpiredMosaicType { 7 | 8 | /** 9 | * Mosaic has expired. 10 | */ 11 | Expired(1), 12 | 13 | /** 14 | * Mosaic has been restored. 15 | */ 16 | Restored(2); 17 | 18 | private final int value; 19 | 20 | ExpiredMosaicType(final int value) { 21 | this.value = value; 22 | } 23 | 24 | /** 25 | * Gets the underlying integer representation of the type. 26 | * 27 | * @return The underlying value. 28 | */ 29 | public int value() { 30 | return this.value; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.github/buildConfiguration.yaml: -------------------------------------------------------------------------------- 1 | builds: 2 | - name: Go Crypto 3 | path: gocrypto 4 | 5 | - name: NEM Core 6 | path: core 7 | 8 | - name: NEM Deploy 9 | path: deploy 10 | dependsOn: 11 | - core 12 | 13 | - name: NEM Peer 14 | path: peer 15 | dependsOn: 16 | - core 17 | 18 | - name: NEM Infrastructure Server 19 | path: nis 20 | dependsOn: 21 | - core 22 | - deploy 23 | - peer 24 | 25 | customBuilds: 26 | - name: Nightly Job 27 | jobName: nightlyJob 28 | scriptPath: .github/jenkinsfile/nightlyBuild.groovy 29 | triggers: 30 | - type: cron 31 | schedule: '@midnight' 32 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/math/MatrixNonZeroElementRowIterator.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.math; 2 | 3 | /** 4 | * Interface for iterating through the nonzero elements of a matrix row. 5 | */ 6 | public interface MatrixNonZeroElementRowIterator { 7 | 8 | /** 9 | * Gets a value indicating whether or not the matrix row has more non-zero elements. 10 | * 11 | * @return true if the matrix row has more non-zero elements, false otherwise. 12 | */ 13 | boolean hasNext(); 14 | 15 | /** 16 | * Gets the next non-zero matrix row element. 17 | * 18 | * @return The next non-zero matrix element of the row. 19 | */ 20 | MatrixElement next(); 21 | } 22 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/ncc/NamespaceMetaDataPairTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.ncc; 2 | 3 | import org.nem.core.model.namespace.*; 4 | import org.nem.core.model.primitive.BlockHeight; 5 | 6 | public class NamespaceMetaDataPairTest extends AbstractMetaDataPairTest { 7 | 8 | public NamespaceMetaDataPairTest() { 9 | super(account -> new Namespace(new NamespaceId("foo"), account, new BlockHeight(17)), id -> new DefaultMetaData((long) id), 10 | NamespaceMetaDataPair::new, NamespaceMetaDataPair::new, namespace -> namespace.getOwner().getAddress(), 11 | metaData -> metaData.getId().intValue()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/validators/NamedValidatorTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | 7 | public class NamedValidatorTest { 8 | 9 | @Test 10 | public void defaultGetNameReturnsTypeName() { 11 | // Arrange: 12 | final NamedValidator validator = new CrazyNameValidator(); 13 | 14 | // Act: 15 | final String name = validator.getName(); 16 | 17 | // Assert: 18 | MatcherAssert.assertThat(name, IsEqual.equalTo("CrazyNameValidator")); 19 | } 20 | 21 | private static class CrazyNameValidator implements NamedValidator { 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/ncc/MosaicDefinitionMetaDataPairTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.ncc; 2 | 3 | import org.nem.core.model.mosaic.MosaicDefinition; 4 | import org.nem.core.test.Utils; 5 | 6 | public class MosaicDefinitionMetaDataPairTest extends AbstractMetaDataPairTest { 7 | 8 | public MosaicDefinitionMetaDataPairTest() { 9 | super(Utils::createMosaicDefinition, id -> new DefaultMetaData((long) id), MosaicDefinitionMetaDataPair::new, 10 | MosaicDefinitionMetaDataPair::new, mosaicDefinition -> mosaicDefinition.getCreator().getAddress(), 11 | metaData -> metaData.getId().intValue()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/observers/NamedObserverTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.observers; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | 7 | public class NamedObserverTest { 8 | 9 | @Test 10 | public void defaultGetNameReturnsTypeName() { 11 | // Arrange: 12 | final NamedObserver observer = new CrazyNameObserver(); 13 | 14 | // Act: 15 | final String name = observer.getName(); 16 | 17 | // Assert: 18 | MatcherAssert.assertThat(name, IsEqual.equalTo("CrazyNameObserver")); 19 | } 20 | 21 | private static class CrazyNameObserver implements NamedObserver { 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/serialization/primitive/BinarySerializationPolicy.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization.primitive; 2 | 3 | import org.nem.core.serialization.*; 4 | 5 | public class BinarySerializationPolicy extends SerializationPolicy { 6 | 7 | @Override 8 | public BinarySerializer createSerializer(final SerializationContext context) { 9 | return new BinarySerializer(context); 10 | } 11 | 12 | @Override 13 | public BinaryDeserializer createDeserializer(final BinarySerializer serializer, final DeserializationContext context) { 14 | return new BinaryDeserializer(serializer.getBytes(), context); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/crypto/secp256k1/SecP256K1KeyAnalyzer.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.crypto.secp256k1; 2 | 3 | import org.nem.core.crypto.*; 4 | 5 | /** 6 | * Implementation of the key analyzer for SECP256K1. 7 | */ 8 | public class SecP256K1KeyAnalyzer implements KeyAnalyzer { 9 | 10 | private static final int COMPRESSED_KEY_SIZE = 33; 11 | 12 | @Override 13 | public boolean isKeyCompressed(final PublicKey publicKey) { 14 | if (COMPRESSED_KEY_SIZE != publicKey.getRaw().length) { 15 | return false; 16 | } 17 | 18 | switch (publicKey.getRaw()[0]) { 19 | case 0x02: 20 | case 0x03: 21 | return true; 22 | } 23 | 24 | return false; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/test/MockImportanceCalculator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.test; 2 | 3 | import java.util.Collection; 4 | import org.nem.core.model.primitive.BlockHeight; 5 | import org.nem.nis.pox.ImportanceCalculator; 6 | import org.nem.nis.state.AccountState; 7 | 8 | /** 9 | * A mock ImportanceCalculator implementation. 10 | */ 11 | public class MockImportanceCalculator implements ImportanceCalculator { 12 | 13 | @Override 14 | public void recalculate(final BlockHeight blockHeight, final Collection accountStates) { 15 | accountStates.stream().forEach(a -> a.getImportanceInfo().setImportance(blockHeight, 1.0 / accountStates.size())); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/ReadOnlyPoxFacade.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | import org.nem.core.model.primitive.BlockHeight; 4 | 5 | /** 6 | * A read only facade on top of pox. 7 | */ 8 | public interface ReadOnlyPoxFacade { 9 | 10 | /** 11 | * Gets the size of the last pox vector (needed for time synchronization). 12 | * 13 | * @return The size of the last pox vector. 14 | */ 15 | int getLastVectorSize(); 16 | 17 | /** 18 | * Gets the height at which the last recalculation was (needed for time synchronization). 19 | * 20 | * @return The the height at which the last recalculation was. 21 | */ 22 | BlockHeight getLastRecalculationHeight(); 23 | } 24 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/pox/ImportanceCalculator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.pox; 2 | 3 | import java.util.Collection; 4 | import org.nem.core.model.primitive.BlockHeight; 5 | import org.nem.nis.state.AccountState; 6 | 7 | /** 8 | * Interface for calculating the importance of a collection of accounts at a specific block height. 9 | */ 10 | public interface ImportanceCalculator { 11 | 12 | /** 13 | * Recalculates the importance scores for the specified accounts. 14 | * 15 | * @param blockHeight The block height. 16 | * @param accountStates The account states. 17 | */ 18 | void recalculate(final BlockHeight blockHeight, final Collection accountStates); 19 | } 20 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dbmodel/DbMultisigSignatureTransaction.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dbmodel; 2 | 3 | import javax.persistence.*; 4 | 5 | @Entity 6 | @Table(name = "multisigsignatures") 7 | public class DbMultisigSignatureTransaction extends AbstractTransfer { 8 | @ManyToOne(fetch = FetchType.LAZY) 9 | @JoinColumn(name = "multisigTransactionId") 10 | private DbMultisigTransaction multisigTransaction; 11 | 12 | public DbMultisigTransaction getMultisigTransaction() { 13 | return this.multisigTransaction; 14 | } 15 | 16 | public void setMultisigTransaction(final DbMultisigTransaction multisigTransaction) { 17 | this.multisigTransaction = multisigTransaction; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/service/TransactionIo.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.service; 2 | 3 | import org.nem.core.crypto.Hash; 4 | import org.nem.core.model.ncc.TransactionMetaDataPair; 5 | import org.nem.core.model.primitive.BlockHeight; 6 | 7 | public interface TransactionIo { 8 | 9 | /** 10 | * Requests information about the transaction the specified hash. 11 | * 12 | * @param blockHeight The height of the block in which the transaction is stored. 13 | * @param hash The transaction hash. 14 | * @return The transaction with the specified hash associated with its meta data. 15 | */ 16 | TransactionMetaDataPair getTransactionUsingHash(Hash hash, BlockHeight blockHeight); 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/websocket/UnconfirmedTransactionListener.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.websocket; 2 | 3 | import org.nem.core.model.Transaction; 4 | import org.nem.core.model.ValidationResult; 5 | 6 | public interface UnconfirmedTransactionListener { 7 | /** 8 | * Publishes newly obtained transaction to UnconfirmedTransactionListener. 9 | * 10 | * @param transaction Unconfirmed transaction. 11 | * @param validationResult Result of a validation, only successful transactions are published, so this should always be 12 | * ValidationResult.SUCCESS. 13 | */ 14 | void pushTransaction(final Transaction transaction, final ValidationResult validationResult); 15 | } 16 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/mosaic/MosaicFeeInformationTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.mosaic; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | import org.nem.core.model.primitive.Supply; 7 | 8 | public class MosaicFeeInformationTest { 9 | 10 | @Test 11 | public void canCreateMosaicFeeInformation() { 12 | // Act: 13 | final MosaicFeeInformation information = new MosaicFeeInformation(new Supply(575), 3); 14 | 15 | // Assert: 16 | MatcherAssert.assertThat(information.getSupply(), IsEqual.equalTo(new Supply(575))); 17 | MatcherAssert.assertThat(information.getDivisibility(), IsEqual.equalTo(3)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/secret/ObserverOption.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.secret; 2 | 3 | /** 4 | * Options to customize the observers created by the BlockTransactionObserverFactory. 5 | */ 6 | public enum ObserverOption { 7 | /** 8 | * The default options. 9 | */ 10 | @SuppressWarnings("unused") 11 | Default, 12 | 13 | /** 14 | * Excludes the incremental poi observer. 15 | */ 16 | NoIncrementalPoi, 17 | 18 | /** 19 | * No pruning of historical data. 20 | */ 21 | NoHistoricalDataPruning, 22 | 23 | /** 24 | * No observation of outlinks. 25 | */ 26 | NoOutlinkObserver, 27 | 28 | /** 29 | * No expired mosaic tracking. 30 | */ 31 | NoExpiredMosaicTracking 32 | } 33 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/controller/requests/NamespaceIdBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.requests; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | import org.nem.core.model.namespace.NamespaceId; 7 | 8 | public class NamespaceIdBuilderTest { 9 | 10 | @Test 11 | public void namespaceIdCanBeBuilt() { 12 | // Arrange: 13 | final NamespaceIdBuilder builder = new NamespaceIdBuilder(); 14 | 15 | // Act: 16 | builder.setNamespace("a.b.c"); 17 | final NamespaceId namespaceId = builder.build(); 18 | 19 | // Assert: 20 | MatcherAssert.assertThat(namespaceId.toString(), IsEqual.equalTo("a.b.c")); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /nis/src/main/resources/logalpha.properties: -------------------------------------------------------------------------------- 1 | # suppress inspection "UnusedProperty" for whole file 2 | handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler 3 | .level = INFO 4 | 5 | java.util.logging.ConsoleHandler.formatter = org.nem.deploy.ColorConsoleFormatter 6 | java.util.logging.ConsoleHandler.level = INFO 7 | 8 | java.util.logging.FileHandler.formatter = org.nem.deploy.NemFormatter 9 | java.util.logging.FileHandler.limit = 100000000 10 | java.util.logging.FileHandler.count = 100 11 | java.util.logging.FileHandler.pattern = ${nem.folder}/nis/logs/nis-%g.log 12 | 13 | java.util.logging.SimpleFormatter.format = %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$s %5$s%6$s (%2$s)%n 14 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/serialization/SerializationContext.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization; 2 | 3 | /** 4 | * Class that contains external state necessary for serialization of some objects. 5 | */ 6 | public class SerializationContext { 7 | 8 | /** 9 | * Gets the maximum number of bytes that can be serialized. 10 | * 11 | * @return The maximum number of bytes. 12 | */ 13 | public int getDefaultMaxBytesLimit() { 14 | return 2048; 15 | } 16 | 17 | /** 18 | * Gets the default maximum number of characters that can be serialized. 19 | * 20 | * @return The maximum number of characters. 21 | */ 22 | public int getDefaultMaxCharsLimit() { 23 | return 128; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/TransactionExecutionStateTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.*; 5 | import org.junit.*; 6 | import org.nem.core.model.mosaic.MosaicTransferFeeCalculator; 7 | 8 | public class TransactionExecutionStateTest { 9 | 10 | @Test 11 | public void canCreateState() { 12 | // Arrange: 13 | final MosaicTransferFeeCalculator calculator = mosaic -> null; 14 | 15 | // Act: 16 | final TransactionExecutionState state = new TransactionExecutionState(calculator); 17 | 18 | // Assert: 19 | MatcherAssert.assertThat(state.getMosaicTransferFeeCalculator(), IsSame.sameInstance(calculator)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/requests/MosaicIdBuilder.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.requests; 2 | 3 | import org.nem.core.model.mosaic.MosaicId; 4 | 5 | /** 6 | * Builder that is used by Spring to create a MosaicId from a GET request. 7 | */ 8 | public class MosaicIdBuilder { 9 | private String mosaicId; 10 | 11 | /** 12 | * Sets the mosaic id. 13 | * 14 | * @param mosaicId The mosaic id. 15 | */ 16 | public void setMosaicId(final String mosaicId) { 17 | this.mosaicId = mosaicId; 18 | } 19 | 20 | /** 21 | * Creates a MosaicId. 22 | * 23 | * @return The mosaic id. 24 | */ 25 | public MosaicId build() { 26 | return MosaicId.parse(this.mosaicId); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dao/mappers/MosaicRawToDbModelMapping.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dao.mappers; 2 | 3 | import org.nem.nis.dbmodel.DbMosaic; 4 | import org.nem.nis.mappers.IMapping; 5 | 6 | /** 7 | * A mapping that is able to map raw mosaic data to a db mosaic. 8 | */ 9 | public class MosaicRawToDbModelMapping implements IMapping { 10 | @Override 11 | public DbMosaic map(final Object[] source) { 12 | final DbMosaic dbMosaic = new DbMosaic(); 13 | dbMosaic.setId(RawMapperUtils.castToLong(source[0])); 14 | dbMosaic.setDbMosaicId(RawMapperUtils.castToLong(source[1])); 15 | dbMosaic.setQuantity(RawMapperUtils.castToLong(source[2])); 16 | return dbMosaic; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/ncc/PublicKeyBuilder.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.ncc; 2 | 3 | import org.nem.core.crypto.PublicKey; 4 | 5 | /** 6 | * Builder that is used by Spring to create a PublicKey from a GET request. 7 | */ 8 | public class PublicKeyBuilder { 9 | private String publicKey; 10 | 11 | /** 12 | * Sets the public key. 13 | * 14 | * @param publicKey The public key. 15 | */ 16 | public void setPublicKey(final String publicKey) { 17 | this.publicKey = publicKey; 18 | } 19 | 20 | /** 21 | * Creates an public key. 22 | * 23 | * @return The public key. 24 | */ 25 | public PublicKey build() { 26 | return PublicKey.fromHexString(this.publicKey); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/mappers/MosaicPropertyModelToDbModelMapping.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.mappers; 2 | 3 | import org.nem.core.model.NemProperty; 4 | import org.nem.nis.dbmodel.DbMosaicProperty; 5 | 6 | /** 7 | * A mapping that is able to map a model nem property to a db mosaic property. 8 | */ 9 | public class MosaicPropertyModelToDbModelMapping implements IMapping { 10 | 11 | @Override 12 | public DbMosaicProperty map(final NemProperty property) { 13 | final DbMosaicProperty dbMosaicProperty = new DbMosaicProperty(); 14 | dbMosaicProperty.setName(property.getName()); 15 | dbMosaicProperty.setValue(property.getValue()); 16 | return dbMosaicProperty; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/test/BlockChain/TestOptions.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.test.BlockChain; 2 | 3 | public class TestOptions { 4 | private final int numAccounts; 5 | private final int numNodes; 6 | private final int commonChainHeight; 7 | 8 | public TestOptions(final int numAccounts, final int numNodes, final int commonChainHeight) { 9 | this.numAccounts = numAccounts; 10 | this.numNodes = numNodes; 11 | this.commonChainHeight = commonChainHeight; 12 | } 13 | 14 | public int numAccounts() { 15 | return this.numAccounts; 16 | } 17 | 18 | public int numNodes() { 19 | return this.numNodes; 20 | } 21 | 22 | public int commonChainHeight() { 23 | return this.commonChainHeight; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/primitive/NodeId.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.primitive; 2 | 3 | /** 4 | * Represents a node's id used in POI graph clustering. 5 | */ 6 | public class NodeId extends AbstractPrimitive { 7 | 8 | /** 9 | * Creates a node id. 10 | * 11 | * @param nodeId The node id. 12 | */ 13 | public NodeId(final int nodeId) { 14 | super(nodeId, NodeId.class); 15 | 16 | if (this.getRaw() < 0) { 17 | throw new IllegalArgumentException("node id must be non-negative"); 18 | } 19 | } 20 | 21 | /** 22 | * Returns the underlying id. 23 | * 24 | * @return The underlying id. 25 | */ 26 | public int getRaw() { 27 | return this.getValue(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/pox/poi/graph/NeighborhoodRepository.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.pox.poi.graph; 2 | 3 | import org.nem.core.model.primitive.NodeId; 4 | 5 | /** 6 | * A repository for retrieving a node's neighbors. 7 | */ 8 | public interface NeighborhoodRepository { 9 | 10 | /** 11 | * Gets the node ids of the neighbors of the specified node. 12 | * 13 | * @param nodeId The node id. 14 | * @return The node's neighbors. 15 | */ 16 | NodeNeighbors getNeighbors(final NodeId nodeId); 17 | 18 | /** 19 | * Gets the logical size of the map (the actual size might be smaller if the map is very sparse). 20 | * 21 | * @return The logical size of the map. 22 | */ 23 | int getLogicalSize(); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/test/ParameterizedUtils.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.test; 2 | 3 | import java.util.Collection; 4 | import java.util.stream.Collectors; 5 | 6 | /** 7 | * Static helper class for writing parameterized tests. 8 | */ 9 | public class ParameterizedUtils { 10 | 11 | /** 12 | * Wraps a collection of integers into a collection of object arrays that can be used in parameterized tests. 13 | * 14 | * @param values The collection of integers. 15 | * @return The collection of object arrays. 16 | */ 17 | public static Collection wrap(final Collection values) { 18 | return values.stream().map(v -> new Object[]{ 19 | v 20 | }).collect(Collectors.toList()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/FatalConfigException.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis; 2 | 3 | /** 4 | * A fatal configuration exception. 5 | */ 6 | @SuppressWarnings("serial") 7 | public class FatalConfigException extends RuntimeException { 8 | 9 | /** 10 | * Creates a new config exception. 11 | * 12 | * @param message The exception message. 13 | */ 14 | public FatalConfigException(final String message) { 15 | super(message); 16 | } 17 | 18 | /** 19 | * Creates a new config exception. 20 | * 21 | * @param message The exception message. 22 | * @param cause The original exception. 23 | */ 24 | public FatalConfigException(final String message, final Throwable cause) { 25 | super(message, cause); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/AccountCache.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | import org.nem.core.model.*; 4 | 5 | /** 6 | * An account cache that maps addresses to public keys. 7 | */ 8 | public interface AccountCache extends ReadOnlyAccountCache { 9 | 10 | /** 11 | * Adds an account to the cache if it is not already in the cache 12 | * 13 | * @param address The address of the account to add. 14 | * @return The account. 15 | */ 16 | Account addAccountToCache(final Address address); 17 | 18 | /** 19 | * Removes an account from the cache if it is in the cache. 20 | * 21 | * @param address The address of the account to remove. 22 | */ 23 | void removeFromCache(final Address address); 24 | } 25 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/state/ReadOnlyMosaicEntry.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.state; 2 | 3 | import org.nem.core.model.mosaic.MosaicDefinition; 4 | import org.nem.core.model.primitive.Supply; 5 | 6 | /** 7 | * A read-only mosaic entry. 8 | */ 9 | public interface ReadOnlyMosaicEntry { 10 | 11 | /** 12 | * Gets the mosaic definition. 13 | * 14 | * @return The mosaic definition. 15 | */ 16 | MosaicDefinition getMosaicDefinition(); 17 | 18 | /** 19 | * Get the overall supply of the mosaic. 20 | * 21 | * @return The supply. 22 | */ 23 | Supply getSupply(); 24 | 25 | /** 26 | * Gets the mosaic balances. 27 | * 28 | * @return The balances. 29 | */ 30 | ReadOnlyMosaicBalances getBalances(); 31 | } 32 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/controller/requests/DefaultPageBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.requests; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | 7 | public class DefaultPageBuilderTest { 8 | 9 | @Test 10 | public void defaultPageCanBeBuilt() { 11 | // Arrange: 12 | final DefaultPageBuilder builder = new DefaultPageBuilder(); 13 | 14 | // Act: 15 | builder.setId("12345"); 16 | builder.setPageSize("73"); 17 | final DefaultPage page = builder.build(); 18 | 19 | // Assert: 20 | MatcherAssert.assertThat(page.getId(), IsEqual.equalTo(12345L)); 21 | MatcherAssert.assertThat(page.getPageSize(), IsEqual.equalTo(73)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/connect/HttpVoidResponseStrategy.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.connect; 2 | 3 | import org.nem.core.serialization.Deserializer; 4 | 5 | /** 6 | * Strategy for coercing an HTTP response into a null Deserializer. 7 | */ 8 | public class HttpVoidResponseStrategy extends HttpDeserializerResponseStrategy { 9 | 10 | @Override 11 | protected Deserializer coerce(final byte[] responseBytes) { 12 | if (0 == responseBytes.length) { 13 | return null; 14 | } 15 | 16 | throw new FatalPeerException(String.format("Peer returned unexpected data (length %d)", responseBytes.length)); 17 | } 18 | 19 | @Override 20 | public String getSupportedContentType() { 21 | return ContentType.VOID; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/time/synchronization/TimeSynchronizationConnector.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.time.synchronization; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | import org.nem.core.node.Node; 5 | import org.nem.core.time.synchronization.CommunicationTimeStamps; 6 | 7 | /** 8 | * Interface that is used to request network time stamps from other nodes. 9 | */ 10 | public interface TimeSynchronizationConnector { 11 | 12 | /** 13 | * Requests network time stamps from another node. 14 | * 15 | * @param node The node to request the time stamps from. 16 | * @return The communication time stamps. 17 | */ 18 | CompletableFuture getCommunicationTimeStamps(final Node node); 19 | } 20 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/controller/requests/HashBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.requests; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | import org.nem.core.crypto.Hash; 7 | import org.nem.core.test.Utils; 8 | 9 | public class HashBuilderTest { 10 | 11 | @Test 12 | public void hashCanBeBuilt() { 13 | // Arrange: 14 | final Hash originalHash = Utils.generateRandomHash(); 15 | final HashBuilder builder = new HashBuilder(); 16 | 17 | // Act: 18 | builder.setHash(originalHash.toString()); 19 | final Hash hash = builder.build(); 20 | 21 | // Assert: 22 | MatcherAssert.assertThat(hash, IsEqual.equalTo(originalHash)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/validators/integration/SingleBlockBlockChainValidatorTransactionValidationTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators.integration; 2 | 3 | import java.util.List; 4 | import org.nem.core.model.*; 5 | import org.nem.nis.test.NisUtils; 6 | 7 | public class SingleBlockBlockChainValidatorTransactionValidationTest extends AbstractBlockChainValidatorTransactionValidationTest { 8 | 9 | @Override 10 | protected List getBlocks(final Block parentBlock, final List transactions) { 11 | // put all the transactions in a single block 12 | final List blocks = NisUtils.createBlockList(parentBlock, 1); 13 | blocks.get(0).addTransactions(transactions); 14 | return blocks; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/requests/NamespaceIdBuilder.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.requests; 2 | 3 | import org.nem.core.model.namespace.NamespaceId; 4 | 5 | /** 6 | * Builder that is used by Spring to create a NamespaceId from a GET request. 7 | */ 8 | public class NamespaceIdBuilder { 9 | private String namespace; 10 | 11 | /** 12 | * Sets the namespace. 13 | * 14 | * @param namespace The namespace. 15 | */ 16 | public void setNamespace(final String namespace) { 17 | this.namespace = namespace; 18 | } 19 | 20 | /** 21 | * Creates a NamespaceId. 22 | * 23 | * @return The namespace id. 24 | */ 25 | public NamespaceId build() { 26 | return new NamespaceId(this.namespace); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/state/ReadOnlyWeightedBalances.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.state; 2 | 3 | import org.nem.core.model.primitive.*; 4 | 5 | public interface ReadOnlyWeightedBalances { 6 | 7 | /** 8 | * Gets the size of the weighted balances. 9 | * 10 | * @return The size. 11 | */ 12 | int size(); 13 | 14 | /** 15 | * Gets the vested amount at the specified height. 16 | * 17 | * @param height The height. 18 | * @return The vested amount. 19 | */ 20 | Amount getVested(BlockHeight height); 21 | 22 | /** 23 | * Gets the unvested amount at the specified height. 24 | * 25 | * @param height The height. 26 | * @return The unvested amount. 27 | */ 28 | Amount getUnvested(BlockHeight height); 29 | } 30 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/sync/BlockChainScoreManager.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.sync; 2 | 3 | import org.nem.core.model.Block; 4 | import org.nem.core.model.primitive.BlockChainScore; 5 | 6 | /** 7 | * Interface for managing block chain scores. 8 | */ 9 | public interface BlockChainScoreManager { 10 | 11 | /** 12 | * Returns the overall score for the chain. 13 | * 14 | * @return the score. 15 | */ 16 | BlockChainScore getScore(); 17 | 18 | /** 19 | * Updates the score of this chain by adding the score derived from the specified block and parent block. 20 | * 21 | * @param parentBlock The parent block. 22 | * @param block The block. 23 | */ 24 | void updateScore(final Block parentBlock, final Block block); 25 | } 26 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/NetworkValidator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators; 2 | 3 | import org.nem.core.model.*; 4 | 5 | /** 6 | * Base class for validators that validates entities match the default network 7 | */ 8 | public abstract class NetworkValidator { 9 | 10 | /** 11 | * Validates the specified verifiable entity. 12 | * 13 | * @param entity The entity. 14 | * @return The validation result. 15 | */ 16 | protected ValidationResult validateNetwork(final VerifiableEntity entity) { 17 | final byte version = (byte) ((entity.getVersion() & 0xFF000000) >> 24); 18 | return version == NetworkInfos.getDefault().getVersion() ? ValidationResult.SUCCESS : ValidationResult.FAILURE_WRONG_NETWORK; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/block/TransactionDeadlineBlockValidator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators.block; 2 | 3 | import org.nem.core.model.*; 4 | import org.nem.nis.validators.BlockValidator; 5 | 6 | /** 7 | * A block transaction validator that ensures all transactions have a valid deadline. 8 | */ 9 | public class TransactionDeadlineBlockValidator implements BlockValidator { 10 | 11 | @Override 12 | public ValidationResult validate(final Block block) { 13 | return ValidationResult.aggregate(block.getTransactions().stream() 14 | .map(t -> t.getDeadline().compareTo(block.getTimeStamp()) >= 0 15 | ? ValidationResult.SUCCESS 16 | : ValidationResult.FAILURE_PAST_DEADLINE) 17 | .iterator()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/FeeForkTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.*; 5 | import org.junit.*; 6 | import org.nem.core.model.primitive.BlockHeight; 7 | 8 | public class FeeForkTest { 9 | 10 | @Test 11 | public void canCreateObject() { 12 | // Arrange: 13 | final BlockHeight firstHeight = new BlockHeight(1); 14 | final BlockHeight secondHeight = new BlockHeight(2); 15 | 16 | // Act: 17 | final FeeFork feeFork = new FeeFork(firstHeight, secondHeight); 18 | 19 | // Assert: 20 | MatcherAssert.assertThat(feeFork.getFirstHeight(), IsSame.sameInstance(firstHeight)); 21 | MatcherAssert.assertThat(feeFork.getSecondHeight(), IsSame.sameInstance(secondHeight)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/connect/HttpBinaryPostRequest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.connect; 2 | 3 | import org.nem.core.serialization.*; 4 | 5 | /** 6 | * Creates a new binary HTTP POST request. 7 | */ 8 | public class HttpBinaryPostRequest implements HttpPostRequest { 9 | private final byte[] entityBytes; 10 | 11 | /** 12 | * Creates a new request. 13 | * 14 | * @param entity The entity. 15 | */ 16 | public HttpBinaryPostRequest(final SerializableEntity entity) { 17 | this.entityBytes = BinarySerializer.serializeToBytes(entity); 18 | } 19 | 20 | @Override 21 | public byte[] getPayload() { 22 | return this.entityBytes; 23 | } 24 | 25 | @Override 26 | public String getContentType() { 27 | return ContentType.BINARY; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/ncc/AccountIdBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.ncc; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | import org.nem.core.model.Address; 7 | import org.nem.core.test.Utils; 8 | 9 | public class AccountIdBuilderTest { 10 | 11 | @Test 12 | public void accountIdCanBeBuilt() { 13 | // Arrange: 14 | final Address address = Utils.generateRandomAddress(); 15 | final AccountIdBuilder builder = new AccountIdBuilder(); 16 | 17 | // Act: 18 | builder.setAddress(address.getEncoded()); 19 | final AccountId accountId = builder.build(); 20 | 21 | // Assert: 22 | MatcherAssert.assertThat(accountId.getAddress(), IsEqual.equalTo(address)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/ncc/PublicKeyBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.ncc; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | import org.nem.core.crypto.PublicKey; 7 | import org.nem.core.test.Utils; 8 | 9 | public class PublicKeyBuilderTest { 10 | 11 | @Test 12 | public void publicKeyCanBeBuilt() { 13 | // Arrange: 14 | final PublicKey original = Utils.generateRandomPublicKey(); 15 | final PublicKeyBuilder builder = new PublicKeyBuilder(); 16 | 17 | // Act: 18 | builder.setPublicKey(original.toString()); 19 | final PublicKey publicKey = builder.build(); 20 | 21 | // Assert: 22 | MatcherAssert.assertThat(publicKey, IsEqual.equalTo(original)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/pox/poi/graph/OutlierScan.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.pox.poi.graph; 2 | 3 | import java.util.ArrayList; 4 | import org.nem.core.model.primitive.NodeId; 5 | 6 | /** 7 | * Trivial clustering: Do not scan at all but build one outlier cluster for each node. 8 | */ 9 | public class OutlierScan implements GraphClusteringStrategy { 10 | 11 | @Override 12 | public ClusteringResult cluster(final Neighborhood neighborhood) { 13 | final ArrayList clusters = new ArrayList<>(); 14 | for (int i = 0; i < neighborhood.size(); ++i) { 15 | final Cluster cluster = new Cluster(new NodeId(i)); 16 | clusters.add(cluster); 17 | } 18 | 19 | return new ClusteringResult(new ArrayList<>(), new ArrayList<>(), clusters); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/mappers/NisMapperFactoryTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.mappers; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsNull; 5 | import org.junit.*; 6 | import org.mockito.Mockito; 7 | import org.nem.core.serialization.AccountLookup; 8 | import org.nem.nis.test.MapperUtils; 9 | 10 | public class NisMapperFactoryTest { 11 | 12 | @Test 13 | public void canCreateDbModelToModelNisMapper() { 14 | // Act: 15 | final NisMapperFactory factory = new NisMapperFactory(MapperUtils.createMapperFactory()); 16 | final NisDbModelToModelMapper mapper = factory.createDbModelToModelNisMapper(Mockito.mock(AccountLookup.class)); 17 | 18 | // Assert: 19 | MatcherAssert.assertThat(mapper, IsNull.notNullValue()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /infra/package.tomaster.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ver=$(cat version.current.txt) 4 | 5 | echo " [+] RESETING REPOSITORIES and SETTING MASTER" 6 | git submodule foreach git reset --hard 7 | git reset --hard 8 | 9 | git submodule foreach git checkout main 10 | git submodule foreach git pull 11 | 12 | git submodule foreach git merge --no-ff --no-commit dev 13 | git submodule foreach git commit --author="nembuildbot " 14 | git submodule foreach git push origin 15 | git submodule foreach git tag --force "v${ver}" 16 | git submodule foreach git push --tags 17 | git submodule foreach git checkout dev 18 | 19 | # reset dev branch on top of main 20 | git submodule foreach git checkout -B dev origin/main 21 | git submodule foreach git push origin dev 22 | 23 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/time/synchronization/filter/SynchronizationFilter.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.time.synchronization.filter; 2 | 3 | import java.util.List; 4 | import org.nem.core.model.primitive.NodeAge; 5 | import org.nem.core.time.synchronization.TimeSynchronizationSample; 6 | 7 | /** 8 | * Filters out synchronization samples that do not fulfill a predefined requirement. 9 | */ 10 | public interface SynchronizationFilter { 11 | 12 | /** 13 | * Filters a list of synchronization samples. 14 | * 15 | * @param samples The list of samples. 16 | * @param age The age of the node. 17 | * @return The filtered list of samples. 18 | */ 19 | List filter(final List samples, final NodeAge age); 20 | } 21 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/observers/AccountNotificationTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.observers; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | import org.nem.core.model.Account; 7 | import org.nem.core.test.Utils; 8 | 9 | public class AccountNotificationTest { 10 | 11 | @Test 12 | public void canCreateNotification() { 13 | // Act: 14 | final Account account = Utils.generateRandomAccount(); 15 | final AccountNotification notification = new AccountNotification(account); 16 | 17 | // Assert: 18 | MatcherAssert.assertThat(notification.getType(), IsEqual.equalTo(NotificationType.Account)); 19 | MatcherAssert.assertThat(notification.getAccount(), IsEqual.equalTo(account)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dao/mappers/MosaicPropertyRawToDbModelMapping.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dao.mappers; 2 | 3 | import org.nem.nis.dbmodel.DbMosaicProperty; 4 | import org.nem.nis.mappers.IMapping; 5 | 6 | /** 7 | * A mapping that is able to map raw mosaic property data to a db mosaic property. 8 | */ 9 | public class MosaicPropertyRawToDbModelMapping implements IMapping { 10 | @Override 11 | public DbMosaicProperty map(final Object[] source) { 12 | final DbMosaicProperty dbMosaicProperty = new DbMosaicProperty(); 13 | dbMosaicProperty.setId(RawMapperUtils.castToLong(source[1])); 14 | dbMosaicProperty.setName((String) source[2]); 15 | dbMosaicProperty.setValue((String) source[3]); 16 | return dbMosaicProperty; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/mappers/MapperFactory.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.mappers; 2 | 3 | import org.nem.core.serialization.AccountLookup; 4 | 5 | /** 6 | * Factory for creating a mapper. 7 | */ 8 | public interface MapperFactory { 9 | 10 | /** 11 | * Creates a mapper that can map model types to db model types. 12 | * 13 | * @param accountDaoLookup The account dao lookup object. 14 | * @return The mapper. 15 | */ 16 | IMapper createModelToDbModelMapper(final AccountDaoLookup accountDaoLookup); 17 | 18 | /** 19 | * Creates a mapper that can map db model types to model types. 20 | * 21 | * @param accountLookup The account lookup object. 22 | * @return The mapper. 23 | */ 24 | IMapper createDbModelToModelMapper(final AccountLookup accountLookup); 25 | } 26 | -------------------------------------------------------------------------------- /deploy/src/main/java/org/nem/deploy/NemFormatter.java: -------------------------------------------------------------------------------- 1 | package org.nem.deploy; 2 | 3 | import java.time.Instant; 4 | import java.util.TimeZone; 5 | import java.util.logging.*; 6 | import org.nem.core.time.*; 7 | 8 | /** 9 | * Formatter adds network time to logs. 10 | */ 11 | public class NemFormatter extends SimpleFormatter { 12 | private static final TimeProvider TIME_PROVIDER = new SystemTimeProvider(); 13 | private static final int TIME_ZONE_OFFSET = TimeZone.getDefault().getRawOffset(); 14 | 15 | @Override 16 | public synchronized String format(final LogRecord record) { 17 | record.setInstant( 18 | Instant.ofEpochMilli(TIME_PROVIDER.getNetworkTime().getRaw() + SystemTimeProvider.getEpochTimeMillis() - TIME_ZONE_OFFSET)); 19 | return super.format(record); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/visitors/AggregateBlockVisitor.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.visitors; 2 | 3 | import java.util.List; 4 | import org.nem.core.model.Block; 5 | 6 | /** 7 | * Aggregate block visitor. 8 | */ 9 | public class AggregateBlockVisitor implements BlockVisitor { 10 | 11 | private final List visitors; 12 | 13 | /** 14 | * Creates a new aggregate block visitor. 15 | * 16 | * @param visitors The aggregated visitors. 17 | */ 18 | public AggregateBlockVisitor(final List visitors) { 19 | this.visitors = visitors; 20 | } 21 | 22 | @Override 23 | public void visit(final Block parentBlock, final Block block) { 24 | for (final BlockVisitor visitor : this.visitors) { 25 | visitor.visit(parentBlock, block); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/harvesting/GeneratedBlockTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.harvesting; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | import org.nem.core.model.Block; 7 | import org.nem.nis.test.NisUtils; 8 | 9 | public class GeneratedBlockTest { 10 | 11 | @Test 12 | public void canCreateGeneratedBlock() { 13 | // Arrange: 14 | final Block block = NisUtils.createRandomBlock(); 15 | final long score = 18245L; 16 | 17 | // Act: 18 | final GeneratedBlock generatedBlock = new GeneratedBlock(block, score); 19 | 20 | // Assert: 21 | MatcherAssert.assertThat(generatedBlock.getBlock(), IsEqual.equalTo(block)); 22 | MatcherAssert.assertThat(generatedBlock.getScore(), IsEqual.equalTo(score)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/BlockChainConstants.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model; 2 | 3 | /** 4 | * Common place to have BlockChain-related constants accessible from all modules. 5 | */ 6 | public class BlockChainConstants { 7 | 8 | /** 9 | * The maximum number of seconds in the future that an entity's timestamp can be without the entity being rejected. 10 | */ 11 | public static final int MAX_ALLOWED_SECONDS_AHEAD_OF_TIME = 10; 12 | 13 | /** 14 | * The maximum number of cosignatories that a multisig account can have. 15 | */ 16 | public static final int MAX_ALLOWED_COSIGNATORIES_PER_ACCOUNT = 32; 17 | 18 | /** 19 | * The maximum number of mosaics allowed in a transfer transaction. 20 | */ 21 | public static final int MAX_ALLOWED_MOSAICS_PER_TRANSFER = 10; 22 | } 23 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/observers/AccountNotification.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.observers; 2 | 3 | import org.nem.core.model.Account; 4 | 5 | /** 6 | * A notification that represents the announcement of a potentially new account. 7 | */ 8 | public class AccountNotification extends Notification { 9 | private final Account account; 10 | 11 | /** 12 | * Creates a new account notification. 13 | * 14 | * @param account The account. 15 | */ 16 | public AccountNotification(final Account account) { 17 | super(NotificationType.Account); 18 | this.account = account; 19 | } 20 | 21 | /** 22 | * Gets the potentially new account. 23 | * 24 | * @return The potentially new account. 25 | */ 26 | public Account getAccount() { 27 | return this.account; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/harvesting/NewBlockTransactionsProvider.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.harvesting; 2 | 3 | import java.util.List; 4 | import org.nem.core.model.*; 5 | import org.nem.core.model.primitive.BlockHeight; 6 | import org.nem.core.time.TimeInstant; 7 | 8 | /** 9 | * Provider of transactions for a new block. 10 | */ 11 | public interface NewBlockTransactionsProvider { 12 | 13 | /** 14 | * Gets block transactions for the specified harvester and block parameters. 15 | * 16 | * @param harvesterAddress The harvester address. 17 | * @param blockTime The block time. 18 | * @param blockHeight The block height. 19 | * @return The transactions. 20 | */ 21 | List getBlockTransactions(Address harvesterAddress, TimeInstant blockTime, BlockHeight blockHeight); 22 | } 23 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/PeerNetworkNodeSelectorFactory.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer; 2 | 3 | import org.nem.peer.trust.NodeSelector; 4 | 5 | /** 6 | * Interface for selected nodes used by the peer network. 7 | */ 8 | public interface PeerNetworkNodeSelectorFactory { 9 | 10 | /** 11 | * Creates a node selector for refresh operations. 12 | * 13 | * @return The node selector. 14 | */ 15 | NodeSelector createRefreshNodeSelector(); 16 | 17 | /** 18 | * Creates a node selector for update operations. 19 | * 20 | * @return The node selector. 21 | */ 22 | NodeSelector createUpdateNodeSelector(); 23 | 24 | /** 25 | * Creates a node selector for time sync operations. 26 | * 27 | * @return The node selector. 28 | */ 29 | NodeSelector createTimeSyncNodeSelector(); 30 | } 31 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/serialization/primitive/JsonPrimitiveTruncationTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization.primitive; 2 | 3 | import org.junit.experimental.runners.Enclosed; 4 | import org.junit.runner.RunWith; 5 | import org.nem.core.serialization.*; 6 | 7 | @RunWith(Enclosed.class) 8 | public class JsonPrimitiveTruncationTest { 9 | 10 | public static class BytesTruncationTest extends AbstractBytesTruncationTest { 11 | 12 | public BytesTruncationTest() { 13 | super(new JsonSerializationPolicy()); 14 | } 15 | } 16 | 17 | public static class StringTruncationTest extends AbstractStringTruncationTest { 18 | 19 | public StringTruncationTest() { 20 | super(new JsonSerializationPolicy()); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/mappers/NisModelToDbModelMapper.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.mappers; 2 | 3 | import org.nem.core.model.Block; 4 | import org.nem.nis.dbmodel.DbBlock; 5 | 6 | /** 7 | * A NIS mapper facade for mapping model types to db model types. 8 | */ 9 | public class NisModelToDbModelMapper { 10 | private final IMapper mapper; 11 | 12 | /** 13 | * Creates a mapper facade. 14 | * 15 | * @param mapper The mapper. 16 | */ 17 | public NisModelToDbModelMapper(final IMapper mapper) { 18 | this.mapper = mapper; 19 | } 20 | 21 | /** 22 | * Maps a model block to a db model block. 23 | * 24 | * @param block The model block. 25 | * @return The db model block. 26 | */ 27 | public DbBlock map(final Block block) { 28 | return this.mapper.map(block, DbBlock.class); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/time/synchronization/TimeSynchronizationException.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.time.synchronization; 2 | 3 | /** 4 | * A synchronization exception. 5 | */ 6 | @SuppressWarnings("serial") 7 | public class TimeSynchronizationException extends RuntimeException { 8 | 9 | /** 10 | * Creates a new synchronization exception. 11 | * 12 | * @param message The exception message. 13 | */ 14 | public TimeSynchronizationException(final String message) { 15 | super(message); 16 | } 17 | 18 | /** 19 | * Creates a new synchronization exception. 20 | * 21 | * @param message The exception message. 22 | * @param cause The original exception. 23 | */ 24 | public TimeSynchronizationException(final String message, final Throwable cause) { 25 | super(message, cause); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /peer/src/test/java/org/nem/peer/trust/score/ScoreTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust.score; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | import org.nem.peer.test.MockScore; 7 | 8 | public class ScoreTest { 9 | 10 | @Test 11 | public void derivedScoreProvidesInitialValue() { 12 | // Arrange: 13 | final Score score = new MockScore(); 14 | 15 | // Assert: 16 | MatcherAssert.assertThat(score.score().get(), IsEqual.equalTo(MockScore.INITIAL_SCORE)); 17 | } 18 | 19 | @Test 20 | public void rawScoreCanBeChanged() { 21 | // Arrange: 22 | final Score score = new MockScore(); 23 | 24 | // Act: 25 | score.score().set(5.2); 26 | 27 | // Assert: 28 | MatcherAssert.assertThat(score.score().get(), IsEqual.equalTo(5.2)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/serialization/primitive/BinaryPrimitiveTruncationTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization.primitive; 2 | 3 | import org.junit.experimental.runners.Enclosed; 4 | import org.junit.runner.RunWith; 5 | import org.nem.core.serialization.*; 6 | 7 | @RunWith(Enclosed.class) 8 | public class BinaryPrimitiveTruncationTest { 9 | 10 | public static class BytesTruncationTest extends AbstractBytesTruncationTest { 11 | 12 | public BytesTruncationTest() { 13 | super(new BinarySerializationPolicy()); 14 | } 15 | } 16 | 17 | public static class StringTruncationTest extends AbstractStringTruncationTest { 18 | 19 | public StringTruncationTest() { 20 | super(new BinarySerializationPolicy()); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/block/MaxTransactionsBlockValidator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators.block; 2 | 3 | import org.nem.core.model.*; 4 | import org.nem.nis.validators.BlockValidator; 5 | 6 | /** 7 | * A block validator that ensures a block does not have more than the maximum number of transactions. 8 | */ 9 | public class MaxTransactionsBlockValidator implements BlockValidator { 10 | 11 | @Override 12 | public ValidationResult validate(final Block block) { 13 | final long numTransactions = BlockExtensions.streamDefault(block).count(); 14 | final int maxTransactionsPerBlock = NemGlobals.getBlockChainConfiguration().getMaxTransactionsPerBlock(); 15 | return numTransactions <= maxTransactionsPerBlock ? ValidationResult.SUCCESS : ValidationResult.FAILURE_TOO_MANY_TRANSACTIONS; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/block/BlockNonFutureEntityValidator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators.block; 2 | 3 | import org.nem.core.model.*; 4 | import org.nem.core.time.TimeProvider; 5 | import org.nem.nis.validators.*; 6 | 7 | /** 8 | * Block validator that validates the block time stamp is not too far in the future. 9 | */ 10 | public class BlockNonFutureEntityValidator extends NonFutureEntityValidator implements BlockValidator { 11 | 12 | /** 13 | * Creates a new validator. 14 | * 15 | * @param timeProvider The time provider. 16 | */ 17 | public BlockNonFutureEntityValidator(final TimeProvider timeProvider) { 18 | super(timeProvider); 19 | } 20 | 21 | @Override 22 | public ValidationResult validate(final Block block) { 23 | return this.validateTimeStamp(block.getTimeStamp()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/serialization/AccountLookup.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.serialization; 2 | 3 | import java.util.function.Predicate; 4 | import org.nem.core.model.*; 5 | 6 | /** 7 | * An interface for looking up accounts. 8 | */ 9 | public interface AccountLookup extends SimpleAccountLookup { 10 | 11 | /** 12 | * Looks up an account by its id. 13 | * 14 | * @param id The account id. 15 | * @param validator The validator for validating the address. 16 | * @return The account with the specified id. 17 | */ 18 | Account findByAddress(final Address id, Predicate
validator); 19 | 20 | /** 21 | * Checks if an account is known. 22 | * 23 | * @param id The account id. 24 | * @return true if the account is known, false if unknown. 25 | */ 26 | boolean isKnownAddress(final Address id); 27 | } 28 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/harvesting/UnlockResult.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.harvesting; 2 | 3 | /** 4 | * Possible unlock results. 5 | */ 6 | public enum UnlockResult { 7 | /** 8 | * The account was successfully unlocked (it might have already been unlocked). 9 | */ 10 | SUCCESS, 11 | 12 | /** 13 | * The account could not be unlocked because it is unknown. 14 | */ 15 | FAILURE_UNKNOWN_ACCOUNT, 16 | 17 | /** 18 | * The account could not be unlocked because it is ineligible for harvesting. 19 | */ 20 | FAILURE_HARVESTING_INELIGIBLE, 21 | 22 | /** 23 | * The account could not be unlocked because it is blocked from harvesting. 24 | */ 25 | FAILURE_HARVESTING_BLOCKED, 26 | 27 | /** 28 | * The account could not be unlocked because limit on the server has been hit. 29 | */ 30 | FAILURE_SERVER_LIMIT 31 | } 32 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/mappers/AccountModelToDbModelMapping.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.mappers; 2 | 3 | import org.nem.core.model.Account; 4 | import org.nem.nis.dbmodel.DbAccount; 5 | 6 | /** 7 | * A mapping that is able to map a model account to a db account. 8 | */ 9 | public class AccountModelToDbModelMapping implements IMapping { 10 | private final AccountDaoLookup accountDaoLookup; 11 | 12 | /** 13 | * Creates a new mapping. 14 | * 15 | * @param accountDaoLookup The account dao lookup. 16 | */ 17 | public AccountModelToDbModelMapping(final AccountDaoLookup accountDaoLookup) { 18 | this.accountDaoLookup = accountDaoLookup; 19 | } 20 | 21 | @Override 22 | public DbAccount map(final Account account) { 23 | return this.accountDaoLookup.findByAddress(account.getAddress()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/connect/HttpResponseStrategy.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.connect; 2 | 3 | import org.apache.http.HttpResponse; 4 | import org.apache.http.client.methods.HttpRequestBase; 5 | 6 | /** 7 | * Strategy for coercing an HTTP response into a specific type. 8 | * 9 | * @param Type of response. 10 | */ 11 | public interface HttpResponseStrategy { 12 | 13 | /** 14 | * Coerces a result of type T given the specified request and response. 15 | * 16 | * @param request The request 17 | * @param response The response. 18 | * @return The coerced result. 19 | */ 20 | T coerce(final HttpRequestBase request, final HttpResponse response); 21 | 22 | /** 23 | * Gets the supported content type. 24 | * 25 | * @return The supported content type. 26 | */ 27 | String getSupportedContentType(); 28 | } 29 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/time/synchronization/filter/ResponseDelayDetectionFilter.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.time.synchronization.filter; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | import org.nem.core.model.primitive.NodeAge; 6 | import org.nem.core.time.synchronization.TimeSynchronizationSample; 7 | 8 | /** 9 | * A filter that filters samples that indicate an unexpected delay in the response (e.g. due to garbage collection). 10 | */ 11 | public class ResponseDelayDetectionFilter implements SynchronizationFilter { 12 | 13 | @Override 14 | public List filter(final List samples, final NodeAge age) { 15 | return samples.stream().filter(s -> FilterConstants.TOLERATED_DURATION_MAXIMUM >= s.getDuration()).collect(Collectors.toList()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/controller/requests/MosaicIdBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.requests; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | import org.nem.core.model.mosaic.MosaicId; 7 | import org.nem.core.model.namespace.NamespaceId; 8 | 9 | public class MosaicIdBuilderTest { 10 | 11 | @Test 12 | public void mosaicIdCanBeBuilt() { 13 | // Arrange: 14 | final MosaicIdBuilder builder = new MosaicIdBuilder(); 15 | 16 | // Act: 17 | builder.setMosaicId("alice.vouchers:foo"); 18 | final MosaicId mosaicId = builder.build(); 19 | 20 | // Assert: 21 | MatcherAssert.assertThat(mosaicId.getNamespaceId(), IsEqual.equalTo(new NamespaceId("alice.vouchers"))); 22 | MatcherAssert.assertThat(mosaicId.getName(), IsEqual.equalTo("foo")); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/trust/score/RealDouble.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust.score; 2 | 3 | /** 4 | * Simple class that wraps a double and constrains it to a real value. 5 | */ 6 | public class RealDouble { 7 | 8 | private double value; 9 | 10 | /** 11 | * Creates a new real double. 12 | * 13 | * @param value The double value. 14 | */ 15 | public RealDouble(final double value) { 16 | this.set(value); 17 | } 18 | 19 | /** 20 | * Gets the double value. 21 | * 22 | * @return The double value 23 | */ 24 | public double get() { 25 | return this.value; 26 | } 27 | 28 | /** 29 | * Sets the double value. 30 | * 31 | * @param value The double value 32 | */ 33 | public void set(final double value) { 34 | this.value = (Double.isNaN(value) || Double.isInfinite(value)) ? 0.0 : value; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dao/mappers/MultisigSignatureRawToDbModelMapping.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dao.mappers; 2 | 3 | import org.nem.nis.dbmodel.DbMultisigSignatureTransaction; 4 | import org.nem.nis.mappers.IMapper; 5 | 6 | /** 7 | * A mapping that is able to map raw multisig signature transaction data to a db multisig signature. 8 | */ 9 | public class MultisigSignatureRawToDbModelMapping extends AbstractTransferRawToDbModelMapping { 10 | 11 | /** 12 | * Creates a new mapping. 13 | * 14 | * @param mapper The mapper. 15 | */ 16 | public MultisigSignatureRawToDbModelMapping(final IMapper mapper) { 17 | super(mapper); 18 | } 19 | 20 | @Override 21 | protected DbMultisigSignatureTransaction mapImpl(final Object[] source) { 22 | return new DbMultisigSignatureTransaction(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/requests/DefaultPageBuilder.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.requests; 2 | 3 | /** 4 | * Builder that is used by Spring to create a DefaultPage from a GET request. 5 | */ 6 | public class DefaultPageBuilder { 7 | private String id; 8 | private String pageSize; 9 | 10 | /** 11 | * Sets the id. 12 | * 13 | * @param id The id. 14 | */ 15 | public void setId(final String id) { 16 | this.id = id; 17 | } 18 | 19 | /** 20 | * Sets the page size. 21 | * 22 | * @param pageSize The page size. 23 | */ 24 | public void setPageSize(final String pageSize) { 25 | this.pageSize = pageSize; 26 | } 27 | 28 | /** 29 | * Creates a DefaultPage. 30 | * 31 | * @return The page. 32 | */ 33 | public DefaultPage build() { 34 | return new DefaultPage(this.id, this.pageSize); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/crypto/ed25519/arithmetic/CoordinateSystem.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.crypto.ed25519.arithmetic; 2 | 3 | /** 4 | * Available coordinate systems for a group element. 5 | */ 6 | public enum CoordinateSystem { 7 | 8 | /** 9 | * Affine coordinate system (x, y). 10 | */ 11 | AFFINE, 12 | 13 | /** 14 | * Projective coordinate system (X:Y:Z) satisfying x=X/Z, y=Y/Z. 15 | */ 16 | P2, 17 | 18 | /** 19 | * Extended projective coordinate system (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT. 20 | */ 21 | P3, 22 | 23 | /** 24 | * Completed coordinate system ((X:Z), (Y:T)) satisfying x=X/Z, y=Y/T. 25 | */ 26 | P1xP1, 27 | 28 | /** 29 | * Precomputed coordinate system (y+x, y-x, 2dxy). 30 | */ 31 | PRECOMPUTED, 32 | 33 | /** 34 | * Cached coordinate system (Y+X, Y-X, Z, 2dT). 35 | */ 36 | CACHED 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/function/QuadFunction.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.function; 2 | 3 | /** 4 | * Represents a function that accepts four arguments and produces a result. 5 | * 6 | * @param The type of the first argument. 7 | * @param The type of the second argument. 8 | * @param The type of the third argument. 9 | * @param The type of the fourth argument. 10 | * @param The type of the result. 11 | */ 12 | @FunctionalInterface 13 | @SuppressWarnings("unused") 14 | public interface QuadFunction { 15 | 16 | /** 17 | * Applies this function to the given arguments. 18 | * 19 | * @param t The first argument. 20 | * @param u The second argument. 21 | * @param v The third argument. 22 | * @param w The fourth argument. 23 | * @return The result. 24 | */ 25 | R apply(T t, U u, V v, W w); 26 | } 27 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dbmodel/DbMosaicId.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dbmodel; 2 | 3 | /** 4 | * Holds information about the mosaic database id. 5 | */ 6 | public class DbMosaicId { 7 | private final Long id; 8 | 9 | /** 10 | * Creates a new db mosaic id. 11 | * 12 | * @param id The id. 13 | */ 14 | public DbMosaicId(final Long id) { 15 | this.id = id; 16 | } 17 | 18 | /** 19 | * Gets the id. 20 | * 21 | * @return The id. 22 | */ 23 | public Long getId() { 24 | return this.id; 25 | } 26 | 27 | @Override 28 | public int hashCode() { 29 | return this.id.hashCode(); 30 | } 31 | 32 | @Override 33 | public boolean equals(final Object obj) { 34 | if (!(obj instanceof DbMosaicId)) { 35 | return false; 36 | } 37 | 38 | final DbMosaicId rhs = (DbMosaicId) obj; 39 | return this.id.equals(rhs.id); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/state/ReadOnlyHistoricalImportances.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.state; 2 | 3 | import org.nem.core.model.primitive.BlockHeight; 4 | 5 | @SuppressWarnings("unused") 6 | public interface ReadOnlyHistoricalImportances { 7 | 8 | /** 9 | * Gets the (historical) importance at the specified block height. 10 | * 11 | * @param height The block height. 12 | * @return The importance. 13 | */ 14 | double getHistoricalImportance(BlockHeight height); 15 | 16 | /** 17 | * Gets the (historical) page rank at the specified block height. 18 | * 19 | * @param height The block height. 20 | * @return The page rank. 21 | */ 22 | double getHistoricalPageRank(final BlockHeight height); 23 | 24 | /** 25 | * Gets the size of the historical importances. 26 | * 27 | * @return The size. 28 | */ 29 | int size(); 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/async/SleepFuture.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.async; 2 | 3 | import java.util.*; 4 | import java.util.concurrent.*; 5 | 6 | /** 7 | * Static class containing methods for creating a delayed future. 8 | */ 9 | public class SleepFuture { 10 | private static final Timer TIMER = new Timer(true); 11 | 12 | /** 13 | * Creates a new future that fires at the specified time in the future. 14 | * 15 | * @param delay The delay (in milliseconds). 16 | * @param Any type. 17 | * @return The future. 18 | */ 19 | public static CompletableFuture create(final int delay) { 20 | final CompletableFuture future = new CompletableFuture<>(); 21 | TIMER.schedule(new TimerTask() { 22 | @Override 23 | public void run() { 24 | future.complete(null); 25 | } 26 | }, delay); 27 | return future; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/secret/pruning/TransactionHashCachePruningObserver.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.secret.pruning; 2 | 3 | import org.nem.nis.cache.HashCache; 4 | import org.nem.nis.secret.BlockNotificationContext; 5 | 6 | /** 7 | * A block transaction observer that automatically prunes transaction hash-related data once every 360 blocks. 8 | */ 9 | public class TransactionHashCachePruningObserver extends AbstractPruningObserver { 10 | private final HashCache hashCache; 11 | 12 | /** 13 | * Creates a new observer. 14 | * 15 | * @param hashCache The hash cache. 16 | */ 17 | public TransactionHashCachePruningObserver(final HashCache hashCache) { 18 | this.hashCache = hashCache; 19 | } 20 | 21 | @Override 22 | protected void prune(final BlockNotificationContext context) { 23 | this.hashCache.prune(context.getTimeStamp()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/test/DebitPredicates.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.test; 2 | 3 | import org.nem.core.model.mosaic.Mosaic; 4 | import org.nem.core.model.primitive.Amount; 5 | import org.nem.nis.validators.DebitPredicate; 6 | 7 | /** 8 | * Debit predicates used for testing. 9 | */ 10 | public class DebitPredicates { 11 | 12 | /** 13 | * A XEM debit predicate that throws when called. 14 | */ 15 | public static final DebitPredicate XemThrow = (account, amount) -> { 16 | throw new UnsupportedOperationException("a DebitPredicate call was unexpected"); 17 | }; 18 | 19 | /** 20 | * A mosaic debit predicate that throws when called. 21 | */ 22 | public static final DebitPredicate MosaicThrow = (account, mosaic) -> { 23 | throw new UnsupportedOperationException("a DebitPredicate call was unexpected"); 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/ncc/TransactionMetaDataPairTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.ncc; 2 | 3 | import org.nem.core.crypto.Hash; 4 | import org.nem.core.model.Transaction; 5 | import org.nem.core.model.primitive.BlockHeight; 6 | import org.nem.core.test.RandomTransactionFactory; 7 | 8 | public class TransactionMetaDataPairTest extends AbstractMetaDataPairTest { 9 | 10 | public TransactionMetaDataPairTest() { 11 | super(account -> { 12 | final Transaction transfer = RandomTransactionFactory.createTransfer(account); 13 | transfer.sign(); 14 | return transfer; 15 | }, id -> new TransactionMetaData(BlockHeight.ONE, (long) id, Hash.ZERO), TransactionMetaDataPair::new, TransactionMetaDataPair::new, 16 | transaction -> transaction.getSigner().getAddress(), metaData -> metaData.getId().intValue()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/delta/CopyableDeltaMap.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache.delta; 2 | 3 | /** 4 | * A delta map that can be copied. 5 | */ 6 | @SuppressWarnings({ 7 | "unused", "rawtypes" 8 | }) 9 | public interface CopyableDeltaMap { 10 | 11 | /** 12 | * Commits all changes to the underlying map. 13 | */ 14 | void commit(); 15 | 16 | /** 17 | * Shallow copies this map to another map. 18 | * 19 | * @param rhs The other map. 20 | */ 21 | void shallowCopyTo(final TDerived rhs); 22 | 23 | /** 24 | * Creates a rebased copy of this map that is a copy of the current map without any pending changes. 25 | * 26 | * @return The new map. 27 | */ 28 | TDerived rebase(); 29 | 30 | /** 31 | * Creates a deep copy of this map. 32 | * 33 | * @return The new map. 34 | */ 35 | TDerived deepCopy(); 36 | } 37 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/requests/BlockHeightBuilder.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.requests; 2 | 3 | import org.nem.core.model.primitive.BlockHeight; 4 | import org.nem.core.utils.StringUtils; 5 | 6 | /** 7 | * Builder that is used by Spring to create a BlockHeight from a GET request. 8 | */ 9 | public class BlockHeightBuilder { 10 | private String blockHeight; 11 | 12 | /** 13 | * Sets the block height. 14 | * 15 | * @param blockHeight The block height. 16 | */ 17 | public void setHeight(final String blockHeight) { 18 | this.blockHeight = blockHeight; 19 | } 20 | 21 | /** 22 | * Creates a BlockHeight. 23 | * 24 | * @return The block height. 25 | */ 26 | public BlockHeight build() { 27 | return new BlockHeight(StringUtils.isNullOrEmpty(this.blockHeight) ? Long.MAX_VALUE : Long.parseLong(this.blockHeight, 10)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/harvesting/GeneratedBlock.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.harvesting; 2 | 3 | import org.nem.core.model.Block; 4 | 5 | /** 6 | * Represents a generated block. 7 | */ 8 | public class GeneratedBlock { 9 | private final Block block; 10 | private final long score; 11 | 12 | /** 13 | * Creates a new generated block. 14 | * 15 | * @param block The block. 16 | * @param score The block score. 17 | */ 18 | public GeneratedBlock(final Block block, final long score) { 19 | this.block = block; 20 | this.score = score; 21 | } 22 | 23 | /** 24 | * Gets the block. 25 | * 26 | * @return The block. 27 | */ 28 | public Block getBlock() { 29 | return this.block; 30 | } 31 | 32 | /** 33 | * Gets the block score 34 | * 35 | * @return The block score. 36 | */ 37 | public long getScore() { 38 | return this.score; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/cache/ReadOnlyExpiredMosaicCache.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.cache; 2 | 3 | import java.util.*; 4 | import org.nem.core.model.primitive.BlockHeight; 5 | import org.nem.nis.state.*; 6 | 7 | public interface ReadOnlyExpiredMosaicCache { 8 | /** 9 | * Gets the number of heights with mosaic expirations. 10 | * 11 | * @return Number of heights with mosaic expirations. 12 | */ 13 | int size(); 14 | 15 | /** 16 | * Gets the number of mosaic expirations across all heights. 17 | * 18 | * @return Number of mosaic expirations across all heights. 19 | */ 20 | int deepSize(); 21 | 22 | /** 23 | * Finds all mosaic expirations at specified height. 24 | * 25 | * @param height Height of expiration. 26 | * @return All expiring mosaics at height. 27 | */ 28 | Collection findExpirationsAtHeight(BlockHeight height); 29 | } 30 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/connect/Communicator.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.connect; 2 | 3 | import java.net.URL; 4 | import java.util.concurrent.CompletableFuture; 5 | import org.nem.core.serialization.*; 6 | 7 | /** 8 | * Strategy for posting information to a remote url. 9 | */ 10 | public interface Communicator { 11 | /** 12 | * Posts the entity to the url. 13 | * 14 | * @param url The url. 15 | * @param entity the entity. 16 | * @return A deserializer wrapping the response. 17 | */ 18 | CompletableFuture post(final URL url, final SerializableEntity entity); 19 | 20 | /** 21 | * Posts the entity to the url. 22 | * 23 | * @param url The url. 24 | * @param entity the entity. 25 | * @return A deserializer wrapping the (void) response. 26 | */ 27 | CompletableFuture postVoid(final URL url, final SerializableEntity entity); 28 | } 29 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/i18n/UTF8ResourceBundleControlTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.i18n; 2 | 3 | import java.util.ResourceBundle; 4 | import org.hamcrest.MatcherAssert; 5 | import org.hamcrest.core.IsEqual; 6 | import org.junit.*; 7 | 8 | public class UTF8ResourceBundleControlTest { 9 | private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("test", new UTF8ResourceBundleControl()); 10 | 11 | @Test 12 | public void canLoadAsciiResources() { 13 | // Act: 14 | final String str = BUNDLE.getString("Ascii"); 15 | 16 | // Assert: 17 | MatcherAssert.assertThat(str, IsEqual.equalTo("something simple")); 18 | } 19 | 20 | @Test 21 | public void canLoadUtf8Resources() { 22 | // Act: 23 | final String str = BUNDLE.getString("Utf8"); 24 | 25 | // Assert: 26 | MatcherAssert.assertThat(str, IsEqual.equalTo("something with german umlaut: äöü")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/primitive/SupplyTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.primitive; 2 | 3 | import org.nem.core.serialization.*; 4 | 5 | public class SupplyTest extends AbstractQuantityTest { 6 | 7 | @Override 8 | protected Supply getZeroConstant() { 9 | return Supply.ZERO; 10 | } 11 | 12 | @Override 13 | protected Supply fromValue(final long raw) { 14 | return Supply.fromValue(raw); 15 | } 16 | 17 | @Override 18 | protected Supply construct(final long raw) { 19 | return new Supply(raw); 20 | } 21 | 22 | @Override 23 | protected Supply readFrom(final Deserializer deserializer, final String label) { 24 | return Supply.readFrom(deserializer, label); 25 | } 26 | 27 | @Override 28 | protected void writeTo(final Serializer serializer, final String label, final Supply quantity) { 29 | Supply.writeTo(serializer, label, quantity); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/sync/DefaultComparisonContext.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.sync; 2 | 3 | import org.nem.core.model.NemGlobals; 4 | import org.nem.core.model.primitive.BlockHeight; 5 | 6 | /** 7 | * A default comparison context that is populated with block chain constants. 8 | */ 9 | public class DefaultComparisonContext extends ComparisonContext { 10 | 11 | /** 12 | * Creates a default comparison context. 13 | * 14 | * @param height The local block height. 15 | */ 16 | public DefaultComparisonContext(final BlockHeight height) { 17 | super(getAnalyzeLimitAtHeight(height), NemGlobals.getBlockChainConfiguration().getBlockChainRewriteLimit()); 18 | } 19 | 20 | @SuppressWarnings("UnusedParameters") 21 | private static int getAnalyzeLimitAtHeight(final BlockHeight height) { 22 | return NemGlobals.getBlockChainConfiguration().getMaxBlocksPerSyncAttempt(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/secret/BlockNotificationContextTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.secret; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | import org.nem.core.model.primitive.BlockHeight; 7 | import org.nem.core.time.TimeInstant; 8 | 9 | public class BlockNotificationContextTest { 10 | 11 | @Test 12 | public void canCreateContext() { 13 | // Act: 14 | final BlockNotificationContext context = new BlockNotificationContext(new BlockHeight(11), new TimeInstant(123), 15 | NotificationTrigger.Undo); 16 | 17 | // Assert: 18 | MatcherAssert.assertThat(context.getHeight(), IsEqual.equalTo(new BlockHeight(11))); 19 | MatcherAssert.assertThat(context.getTimeStamp(), IsEqual.equalTo(new TimeInstant(123))); 20 | MatcherAssert.assertThat(context.getTrigger(), IsEqual.equalTo(NotificationTrigger.Undo)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/validators/transaction/TSingleTransactionValidatorTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators.transaction; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | import org.nem.nis.ForkConfiguration; 7 | 8 | public class TSingleTransactionValidatorTest { 9 | 10 | @Test 11 | public void defaultGetNameReturnsTypeName() { 12 | // Arrange: 13 | final ForkConfiguration forkConfiguration = new ForkConfiguration.Builder().build(); 14 | final TSingleTransactionValidator validator = new TransferTransactionValidator(forkConfiguration.getRemoteAccountForkHeight(), 15 | forkConfiguration.getMultisigMOfNForkHeight()); 16 | 17 | // Act: 18 | final String name = validator.getName(); 19 | 20 | // Assert: 21 | MatcherAssert.assertThat(name, IsEqual.equalTo("TransferTransactionValidator")); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/TransactionFeeCalculator.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model; 2 | 3 | import org.nem.core.model.primitive.*; 4 | 5 | /** 6 | * Interface for calculating and validating transaction fees. 7 | */ 8 | public interface TransactionFeeCalculator { 9 | 10 | /** 11 | * Calculates the minimum fee for the specified transaction. 12 | * 13 | * @param transaction The transaction. 14 | * @return The minimum fee. 15 | */ 16 | Amount calculateMinimumFee(final Transaction transaction); 17 | 18 | /** 19 | * Determines whether the fee for the transaction at the specified block height is valid. 20 | * 21 | * @param transaction The transaction. 22 | * @param blockHeight The block height. 23 | * @return true if the transaction fee is valid; false otherwise. 24 | */ 25 | boolean isFeeValid(final Transaction transaction, final BlockHeight blockHeight); 26 | } 27 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/ncc/AccountMetaDataPair.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.ncc; 2 | 3 | import org.nem.core.serialization.Deserializer; 4 | 5 | /** 6 | * A pair containing both an account and account meta data. 7 | */ 8 | public class AccountMetaDataPair extends AbstractMetaDataPair { 9 | 10 | /** 11 | * Creates a new pair. 12 | * 13 | * @param account The account. 14 | * @param metaData The meta data. 15 | */ 16 | public AccountMetaDataPair(final AccountInfo account, final AccountMetaData metaData) { 17 | super("account", "meta", account, metaData); 18 | } 19 | 20 | /** 21 | * Deserializes a pair. 22 | * 23 | * @param deserializer The deserializer 24 | */ 25 | public AccountMetaDataPair(final Deserializer deserializer) { 26 | super("account", "meta", AccountInfo::new, AccountMetaData::new, deserializer); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/primitive/NodeIdTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.primitive; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | 7 | public class NodeIdTest { 8 | 9 | // region constructor 10 | 11 | @Test(expected = IllegalArgumentException.class) 12 | public void cannotBeCreatedAroundNegativeId() { 13 | // Act: 14 | new NodeId(-1); 15 | } 16 | 17 | @Test 18 | public void canBeCreatedAroundZeroId() { 19 | // Act: 20 | final NodeId id = new NodeId(0); 21 | 22 | // Assert: 23 | MatcherAssert.assertThat(id.getValue(), IsEqual.equalTo(0)); 24 | } 25 | 26 | @Test 27 | public void canBeCreatedAroundPositiveId() { 28 | // Act: 29 | final NodeId id = new NodeId(1); 30 | 31 | // Assert: 32 | MatcherAssert.assertThat(id.getValue(), IsEqual.equalTo(1)); 33 | } 34 | 35 | // endregion 36 | } 37 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/mappers/MosaicDbModelToModelMapping.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.mappers; 2 | 3 | import org.nem.core.model.mosaic.*; 4 | import org.nem.core.model.primitive.Quantity; 5 | import org.nem.nis.dbmodel.*; 6 | 7 | /** 8 | * A mapping that is able to map a db model mosaic to a model mosaic. 9 | */ 10 | public class MosaicDbModelToModelMapping implements IMapping { 11 | private final IMapper mapper; 12 | 13 | /** 14 | * Creates a new mapping. 15 | * 16 | * @param mapper The mapper. 17 | */ 18 | public MosaicDbModelToModelMapping(final IMapper mapper) { 19 | this.mapper = mapper; 20 | } 21 | 22 | @Override 23 | public Mosaic map(final DbMosaic source) { 24 | final MosaicId mosaicId = this.mapper.map(new DbMosaicId(source.getDbMosaicId()), MosaicId.class); 25 | return new Mosaic(mosaicId, Quantity.fromValue(source.getQuantity())); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/pox/poi/ImportanceScorerContext.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.pox.poi; 2 | 3 | import org.nem.core.math.ColumnVector; 4 | 5 | /** 6 | * Context passed to ImportanceScorer when recalculating importances. 7 | */ 8 | public interface ImportanceScorerContext { 9 | 10 | /** 11 | * Gets the importance vector. 12 | * 13 | * @return The importance vector. 14 | */ 15 | ColumnVector getImportanceVector(); 16 | 17 | /** 18 | * Gets the outlink vector. 19 | * 20 | * @return The outlink vector. 21 | */ 22 | ColumnVector getOutlinkVector(); 23 | 24 | /** 25 | * Gets the vested balances vector. 26 | * 27 | * @return The vested balance vector. 28 | */ 29 | ColumnVector getVestedBalanceVector(); 30 | 31 | /** 32 | * Gets the graph weight vector. 33 | * 34 | * @return The graph weight vector. 35 | */ 36 | ColumnVector getGraphWeightVector(); 37 | } 38 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/time/synchronization/TimeSynchronizationStrategy.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.time.synchronization; 2 | 3 | import java.util.List; 4 | import org.nem.core.model.primitive.*; 5 | import org.nem.core.time.synchronization.TimeSynchronizationSample; 6 | 7 | /** 8 | * Calculates the offset in time between the local computer clock and the the network time base on the list of synchronization samples. 9 | */ 10 | public interface TimeSynchronizationStrategy { 11 | 12 | /** 13 | * Calculates the offset in time between the local computer clock and the the network time based on the list of synchronization samples. 14 | * 15 | * @param samples The list of synchronization samples. 16 | * @param age The age of the node. 17 | * @return The time offset in ms. 18 | */ 19 | TimeOffset calculateTimeOffset(final List samples, final NodeAge age); 20 | } 21 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/utils/StringEncoder.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.utils; 2 | 3 | import java.nio.charset.Charset; 4 | 5 | /** 6 | * Static class that contains utility functions for converting strings to and from UTF-8 bytes. 7 | */ 8 | public class StringEncoder { 9 | 10 | private static final Charset ENCODING_CHARSET = Charset.forName("UTF-8"); 11 | 12 | /** 13 | * Converts a string to a UTF-8 byte array. 14 | * 15 | * @param s The input string. 16 | * @return The output byte array. 17 | */ 18 | public static byte[] getBytes(final String s) { 19 | return s.getBytes(ENCODING_CHARSET); 20 | } 21 | 22 | /** 23 | * Converts a UTF-8 byte array to a string. 24 | * 25 | * @param bytes The input byte array. 26 | * @return The output string. 27 | */ 28 | public static String getString(final byte[] bytes) { 29 | return new String(bytes, ENCODING_CHARSET); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/trust/score/PositiveLong.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust.score; 2 | 3 | /** 4 | * Simple class that wraps a long and constrains it to a positive value. 5 | */ 6 | public class PositiveLong { 7 | 8 | private long value; 9 | 10 | /** 11 | * Creates a new positive long. 12 | * 13 | * @param value The long value. 14 | */ 15 | public PositiveLong(final long value) { 16 | this.set(value); 17 | } 18 | 19 | /** 20 | * Gets the long value. 21 | * 22 | * @return The long value 23 | */ 24 | public long get() { 25 | return this.value; 26 | } 27 | 28 | /** 29 | * Sets the long value. 30 | * 31 | * @param value The long value 32 | */ 33 | public void set(final long value) { 34 | this.value = Math.max(value, 0); 35 | } 36 | 37 | /** 38 | * Increments the long value. 39 | */ 40 | public void increment() { 41 | ++this.value; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/async/AsyncTimerOptions.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.async; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | import java.util.function.Supplier; 5 | 6 | /** 7 | * Async timer options. 8 | */ 9 | public interface AsyncTimerOptions { 10 | 11 | /** 12 | * Gets the recurring future supplier. 13 | * 14 | * @return The recurring future supplier. 15 | */ 16 | Supplier> getRecurringFutureSupplier(); 17 | 18 | /** 19 | * Gets the initial trigger. 20 | * 21 | * @return The initial trigger. 22 | */ 23 | CompletableFuture getInitialTrigger(); 24 | 25 | /** 26 | * Gets the delay strategy. 27 | * 28 | * @return The delay strategy. 29 | */ 30 | AbstractDelayStrategy getDelayStrategy(); 31 | 32 | /** 33 | * Gets the timer visitor. 34 | * 35 | * @return The timer visitor. 36 | */ 37 | AsyncTimerVisitor getVisitor(); 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/async/UniformDelayStrategy.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.async; 2 | 3 | /** 4 | * DelayStrategy that produces a uniform delay. 5 | */ 6 | public class UniformDelayStrategy extends AbstractDelayStrategy { 7 | 8 | private final int delay; 9 | 10 | /** 11 | * Creates a new infinite uniform delay strategy. 12 | * 13 | * @param delay The delay interval. 14 | */ 15 | public UniformDelayStrategy(final int delay) { 16 | this.delay = delay; 17 | } 18 | 19 | /** 20 | * Creates a new finite uniform delay strategy. 21 | * 22 | * @param delay The delay interval. 23 | * @param maxDelays The maximum number of delays. 24 | */ 25 | public UniformDelayStrategy(final int delay, final int maxDelays) { 26 | super(maxDelays); 27 | this.delay = delay; 28 | } 29 | 30 | @Override 31 | protected int nextInternal(final int iteration) { 32 | return this.delay; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/mappers/MultisigSignatureModelToDbModelMapping.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.mappers; 2 | 3 | import org.nem.core.model.MultisigSignatureTransaction; 4 | import org.nem.nis.dbmodel.DbMultisigSignatureTransaction; 5 | 6 | /** 7 | * A mapping that is able to map a db multisig signature to a model multisig signature. 8 | */ 9 | public class MultisigSignatureModelToDbModelMapping 10 | extends 11 | AbstractTransferModelToDbModelMapping { 12 | 13 | /** 14 | * Creates a new mapping. 15 | * 16 | * @param mapper The mapper. 17 | */ 18 | public MultisigSignatureModelToDbModelMapping(final IMapper mapper) { 19 | super(mapper); 20 | } 21 | 22 | @Override 23 | protected DbMultisigSignatureTransaction mapImpl(final MultisigSignatureTransaction source) { 24 | return new DbMultisigSignatureTransaction(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/observers/TransactionHashesNotification.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.observers; 2 | 3 | import java.util.List; 4 | import org.nem.core.model.HashMetaDataPair; 5 | 6 | /** 7 | * A notification that transaction hashes appeared or disappeared from the blockchain. 8 | */ 9 | public class TransactionHashesNotification extends Notification { 10 | private final List pairs; 11 | 12 | /** 13 | * Creates a new transaction hashes notification. 14 | * 15 | * @param pairs The pairs. 16 | */ 17 | public TransactionHashesNotification(final List pairs) { 18 | super(NotificationType.TransactionHashes); 19 | this.pairs = pairs; 20 | } 21 | 22 | /** 23 | * Gets the collection of hashes. 24 | * 25 | * @return The collection of hashes. 26 | */ 27 | public List getPairs() { 28 | return this.pairs; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/primitive/QuantityTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.primitive; 2 | 3 | import org.nem.core.serialization.*; 4 | 5 | public class QuantityTest extends AbstractQuantityTest { 6 | 7 | @Override 8 | protected Quantity getZeroConstant() { 9 | return Quantity.ZERO; 10 | } 11 | 12 | @Override 13 | protected Quantity fromValue(final long raw) { 14 | return Quantity.fromValue(raw); 15 | } 16 | 17 | @Override 18 | protected Quantity construct(final long raw) { 19 | return new Quantity(raw); 20 | } 21 | 22 | @Override 23 | protected Quantity readFrom(final Deserializer deserializer, final String label) { 24 | return Quantity.readFrom(deserializer, label); 25 | } 26 | 27 | @Override 28 | protected void writeTo(final Serializer serializer, final String label, final Quantity quantity) { 29 | Quantity.writeTo(serializer, label, quantity); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/requests/AccountNamespaceBuilder.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.requests; 2 | 3 | /** 4 | * Builder that is used by Spring to create an AccountNamespace from a GET request. 5 | */ 6 | public class AccountNamespaceBuilder { 7 | private String address; 8 | private String parent; 9 | 10 | /** 11 | * Sets the address. 12 | * 13 | * @param address The address. 14 | */ 15 | public void setAddress(final String address) { 16 | this.address = address; 17 | } 18 | 19 | /** 20 | * Sets the parent. 21 | * 22 | * @param parent The parent. 23 | */ 24 | public void setParent(final String parent) { 25 | this.parent = parent; 26 | } 27 | 28 | /** 29 | * Creates an account namespace. 30 | * 31 | * @return The account namespace. 32 | */ 33 | public AccountNamespace build() { 34 | return new AccountNamespace(this.address, this.parent); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/requests/AccountTransactionsIdBuilder.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.requests; 2 | 3 | /** 4 | * Builder that is used by Spring to create an AccountTransactionsId from a GET request. 5 | */ 6 | public class AccountTransactionsIdBuilder { 7 | private String address; 8 | private String hash; 9 | 10 | /** 11 | * Sets the address. 12 | * 13 | * @param address The address. 14 | */ 15 | public void setAddress(final String address) { 16 | this.address = address; 17 | } 18 | 19 | /** 20 | * Sets the hash. 21 | * 22 | * @param hash The hash. 23 | */ 24 | public void setHash(final String hash) { 25 | this.hash = hash; 26 | } 27 | 28 | /** 29 | * Creates an AccountTransactionsId. 30 | * 31 | * @return The id. 32 | */ 33 | public AccountTransactionsId build() { 34 | return new AccountTransactionsId(this.address, this.hash); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dbmodel/DbMultisigMinCosignatoriesModification.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dbmodel; 2 | 3 | import javax.persistence.*; 4 | 5 | /** 6 | * Multisig Min Cosignatories Modification db entity.
7 | * Holds information about single multisig min cosignatories modification. 8 | */ 9 | @Entity 10 | @Table(name = "mincosignatoriesmodifications") 11 | public class DbMultisigMinCosignatoriesModification { 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.IDENTITY) 14 | private Long id; 15 | 16 | private Integer relativeChange; 17 | 18 | public Long getId() { 19 | return this.id; 20 | } 21 | 22 | public void setId(final Long id) { 23 | this.id = id; 24 | } 25 | 26 | public Integer getRelativeChange() { 27 | return this.relativeChange; 28 | } 29 | 30 | public void setRelativeChange(final Integer relativeChange) { 31 | this.relativeChange = relativeChange; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /peer/src/test/java/org/nem/peer/test/MockScores.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.test; 2 | 3 | import org.nem.peer.trust.score.Scores; 4 | 5 | /** 6 | * A mock Scores implementation. 7 | */ 8 | public class MockScores extends Scores { 9 | 10 | private final double defaultScoreValue; 11 | 12 | /** 13 | * Creates a new mock scores collection. 14 | */ 15 | public MockScores() { 16 | this.defaultScoreValue = MockScore.INITIAL_SCORE; 17 | } 18 | 19 | /** 20 | * Creates a new mock scores collection. 21 | * 22 | * @param defaultScoreValue The default initial value of all mock scores. 23 | */ 24 | public MockScores(final double defaultScoreValue) { 25 | this.defaultScoreValue = defaultScoreValue; 26 | } 27 | 28 | @Override 29 | protected MockScore createScore() { 30 | final MockScore score = new MockScore(); 31 | score.score().set(this.defaultScoreValue); 32 | return score; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /deploy/src/main/java/org/nem/deploy/SerializationPolicy.java: -------------------------------------------------------------------------------- 1 | package org.nem.deploy; 2 | 3 | import java.io.InputStream; 4 | import org.nem.core.serialization.*; 5 | import org.springframework.http.MediaType; 6 | 7 | /** 8 | * Represents a serialization policy. 9 | */ 10 | public interface SerializationPolicy { 11 | 12 | /** 13 | * The media type that the serialization policy supports. 14 | * 15 | * @return The supported media type. 16 | */ 17 | MediaType getMediaType(); 18 | 19 | /** 20 | * Converts the specified serializable entity to a byte representation. 21 | * 22 | * @param entity The entity. 23 | * @return The bytes. 24 | */ 25 | byte[] toBytes(final SerializableEntity entity); 26 | 27 | /** 28 | * Creates a deserializer from a stream. 29 | * 30 | * @param stream The input stream. 31 | * @return The deserializer. 32 | */ 33 | Deserializer fromStream(final InputStream stream); 34 | } 35 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/time/synchronization/filter/AlphaTrimmedMeanFilter.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.time.synchronization.filter; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | import org.nem.core.model.primitive.NodeAge; 6 | import org.nem.core.time.synchronization.TimeSynchronizationSample; 7 | 8 | /** 9 | * Filters out a given percentage of samples at the upper and lower bound of time offset. 10 | */ 11 | public class AlphaTrimmedMeanFilter implements SynchronizationFilter { 12 | 13 | @Override 14 | public List filter(final List samples, final NodeAge age) { 15 | final int samplesToDiscardAtBothEnds = (int) (samples.size() * FilterConstants.ALPHA / 2); 16 | return samples.stream().sorted().skip(samplesToDiscardAtBothEnds).limit(samples.size() - 2 * samplesToDiscardAtBothEnds) 17 | .collect(Collectors.toList()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /peer/src/test/java/org/nem/peer/test/MockTrustProvider.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.test; 2 | 3 | import org.nem.core.math.ColumnVector; 4 | import org.nem.peer.trust.*; 5 | 6 | /** 7 | * A mock TrustProvider implementation. 8 | */ 9 | public class MockTrustProvider implements TrustProvider { 10 | private final TrustContext trustContext; 11 | private final ColumnVector trustVector; 12 | 13 | /** 14 | * Creates a new mock trust provider. 15 | * 16 | * @param trustContext The trust context. 17 | * @param trustVector The trust vector that should be returned. 18 | */ 19 | public MockTrustProvider(final TrustContext trustContext, final ColumnVector trustVector) { 20 | this.trustContext = trustContext; 21 | this.trustVector = trustVector; 22 | } 23 | 24 | @Override 25 | public TrustResult computeTrust(final TrustContext context) { 26 | return new TrustResult(this.trustContext, this.trustVector); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/connect/FatalPeerException.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.connect; 2 | 3 | /** 4 | * A fatal (non-recoverable) peer exception. 5 | */ 6 | @SuppressWarnings("serial") 7 | public class FatalPeerException extends RuntimeException { 8 | 9 | /** 10 | * Creates a new exception. 11 | * 12 | * @param message The exception message. 13 | */ 14 | public FatalPeerException(final String message) { 15 | super(message); 16 | } 17 | 18 | /** 19 | * Creates a new exception. 20 | * 21 | * @param cause The exception message. 22 | */ 23 | public FatalPeerException(final Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | /** 28 | * Creates a new exception. 29 | * 30 | * @param message The exception message. 31 | * @param cause The original exception. 32 | */ 33 | public FatalPeerException(final String message, final Throwable cause) { 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/primitive/NodeAge.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.primitive; 2 | 3 | /** 4 | * Represents the age of a node with respect to time synchronization. 5 | */ 6 | public class NodeAge extends AbstractPrimitive { 7 | 8 | /** 9 | * Creates a node age. 10 | * 11 | * @param age The node's age. 12 | */ 13 | public NodeAge(final long age) { 14 | super(age, NodeAge.class); 15 | 16 | if (this.getRaw() < 0) { 17 | throw new IllegalArgumentException("node age cannot be negative"); 18 | } 19 | } 20 | 21 | /** 22 | * Returns the underlying age. 23 | * 24 | * @return The underlying age. 25 | */ 26 | public long getRaw() { 27 | return this.getValue(); 28 | } 29 | 30 | /** 31 | * Increments the node's age. 32 | * 33 | * @return The incremented node age. 34 | */ 35 | public NodeAge increment() { 36 | return new NodeAge(this.getRaw() + 1); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/time/TimeProvider.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.time; 2 | 3 | import org.nem.core.model.primitive.TimeOffset; 4 | 5 | /** 6 | * Interface that provides time-related information. 7 | */ 8 | public interface TimeProvider { 9 | 10 | /** 11 | * Gets the epoch time. 12 | * 13 | * @return The epoch time. 14 | */ 15 | TimeInstant getEpochTime(); 16 | 17 | /** 18 | * Gets the current time. 19 | * 20 | * @return The current time. 21 | */ 22 | TimeInstant getCurrentTime(); 23 | 24 | /** 25 | * Gets the network time in ms. 26 | * 27 | * @return The network time stamp. 28 | */ 29 | NetworkTimeStamp getNetworkTime(); 30 | 31 | /** 32 | * Updates the time offset. 33 | * 34 | * @param offset The calculated time offset to the other nodes. 35 | * @return The time synchronization result. 36 | */ 37 | TimeSynchronizationResult updateTimeOffset(final TimeOffset offset); 38 | } 39 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dao/BlockDao.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dao; 2 | 3 | import java.util.Collection; 4 | import org.nem.core.model.primitive.BlockHeight; 5 | import org.nem.nis.dbmodel.DbBlock; 6 | 7 | /** 8 | * DAO for accessing DbBlock objects. 9 | */ 10 | public interface BlockDao extends ReadOnlyBlockDao { 11 | 12 | /** 13 | * Saves full block in the database, along with associated transactions, signers, etc. 14 | * 15 | * @param block DbBlock to save. 16 | */ 17 | void save(DbBlock block); 18 | 19 | /** 20 | * Saves all blocks in the database, along with associated transactions, signers, etc. 21 | * 22 | * @param blocks Blocks to save. 23 | */ 24 | void save(final Collection blocks); 25 | 26 | /** 27 | * Deletes blocks after given block. 28 | * 29 | * @param height The height of the reference block. 30 | */ 31 | void deleteBlocksAfterHeight(final BlockHeight height); 32 | } 33 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/visitors/UndoBlockVisitor.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.visitors; 2 | 3 | import org.nem.core.model.Block; 4 | import org.nem.nis.chain.BlockExecutor; 5 | import org.nem.nis.secret.BlockTransactionObserver; 6 | 7 | /** 8 | * Block visitor that undoes all blocks. 9 | */ 10 | public class UndoBlockVisitor implements BlockVisitor { 11 | private final BlockTransactionObserver observer; 12 | private final BlockExecutor executor; 13 | 14 | /** 15 | * Creates a new undo block visitor. 16 | * 17 | * @param observer The observer. 18 | * @param executor The executor 19 | */ 20 | public UndoBlockVisitor(final BlockTransactionObserver observer, final BlockExecutor executor) { 21 | this.observer = observer; 22 | this.executor = executor; 23 | } 24 | 25 | @Override 26 | public void visit(final Block parentBlock, final Block block) { 27 | this.executor.undo(block, this.observer); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /nis/src/test/java/org/nem/nis/dbmodel/DbBlockExtensionsTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dbmodel; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.IsEqual; 5 | import org.junit.*; 6 | import org.nem.nis.test.*; 7 | 8 | public class DbBlockExtensionsTest { 9 | 10 | @Test 11 | public void countTransactionsReturnsTotalNumberOfTransactionsInBlock() { 12 | // Arrange; 13 | final DbBlock block = NisUtils.createDbBlockWithTimeStamp(0); 14 | for (int i = 0; i < 5; ++i) { 15 | block.addTransferTransaction(RandomDbTransactionFactory.createTransfer()); 16 | } 17 | 18 | for (int i = 0; i < 3; ++i) { 19 | block.addMultisigTransaction(RandomDbTransactionFactory.createMultisigTransfer()); 20 | } 21 | 22 | // Act: 23 | final int numTransaction = DbBlockExtensions.countTransactions(block); 24 | 25 | // Assert: 26 | MatcherAssert.assertThat(numTransaction, IsEqual.equalTo(5 + 2 * 3)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dbmodel/DbBlockExtensions.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dbmodel; 2 | 3 | import java.util.List; 4 | import org.nem.nis.mappers.TransactionRegistry; 5 | 6 | /** 7 | * Static helper class for dealing with db blocks. 8 | */ 9 | public class DbBlockExtensions { 10 | 11 | /** 12 | * Counts the number of transactions in the block. 13 | * 14 | * @param block The block. 15 | * @return The number of transactions. 16 | */ 17 | @SuppressWarnings("rawtypes") 18 | public static int countTransactions(final DbBlock block) { 19 | int numTransactions = 0; 20 | for (final TransactionRegistry.Entry entry : TransactionRegistry.iterate()) { 21 | final List transactions = entry.getFromBlock.apply(block); 22 | numTransactions += transactions.stream().mapToInt(entry.getTransactionCount::apply).sum(); 23 | } 24 | 25 | return numTransactions; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/services/InactiveNodePruner.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.services; 2 | 3 | import java.util.logging.Logger; 4 | import org.nem.core.node.NodeCollection; 5 | 6 | /** 7 | * Helper class used to implement inactive node pruning. 8 | */ 9 | public class InactiveNodePruner { 10 | private static final Logger LOGGER = Logger.getLogger(InactiveNodePruner.class.getName()); 11 | 12 | /** 13 | * Prunes the nodes in the specified collection. 14 | * 15 | * @param nodes The node collection. 16 | * @return The number of noes that were pruned. 17 | */ 18 | public int prune(final NodeCollection nodes) { 19 | LOGGER.fine("pruning inactive nodes"); 20 | final int numInitialNodes = nodes.size(); 21 | nodes.prune(); 22 | final int numNodesPruned = numInitialNodes - nodes.size(); 23 | LOGGER.info(String.format("%d inactive node(s) were pruned", numNodesPruned)); 24 | return numNodesPruned; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/validators/transaction/TransactionNonFutureEntityValidator.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.validators.transaction; 2 | 3 | import org.nem.core.model.*; 4 | import org.nem.core.time.TimeProvider; 5 | import org.nem.nis.validators.*; 6 | 7 | /** 8 | * Single transaction validator that validates the transaction time stamp is not too far in the future 9 | */ 10 | public class TransactionNonFutureEntityValidator extends NonFutureEntityValidator implements SingleTransactionValidator { 11 | 12 | /** 13 | * Creates a new validator. 14 | * 15 | * @param timeProvider The time provider. 16 | */ 17 | public TransactionNonFutureEntityValidator(final TimeProvider timeProvider) { 18 | super(timeProvider); 19 | } 20 | 21 | @Override 22 | public ValidationResult validate(final Transaction transaction, final ValidationContext context) { 23 | return this.validateTimeStamp(transaction.getTimeStamp()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/crypto/CryptoException.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.crypto; 2 | 3 | /** 4 | * Exception that is used when a cryptographic operation fails. 5 | */ 6 | @SuppressWarnings("serial") 7 | public class CryptoException extends RuntimeException { 8 | 9 | /** 10 | * Creates a new crypto exception. 11 | * 12 | * @param message The exception message. 13 | */ 14 | public CryptoException(final String message) { 15 | super(message); 16 | } 17 | 18 | /** 19 | * Creates a new crypto exception. 20 | * 21 | * @param cause The exception cause. 22 | */ 23 | public CryptoException(final Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | /** 28 | * Creates a new crypto exception. 29 | * 30 | * @param message The exception message. 31 | * @param cause The exception cause. 32 | */ 33 | public CryptoException(final String message, final Throwable cause) { 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/observers/MosaicDefinitionCreationNotificationTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.observers; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.core.*; 5 | import org.junit.*; 6 | import org.nem.core.model.mosaic.MosaicDefinition; 7 | import org.nem.core.test.Utils; 8 | 9 | public class MosaicDefinitionCreationNotificationTest { 10 | 11 | @Test 12 | public void canCreateNotification() { 13 | // Act: 14 | final MosaicDefinition mosaicDefinition = Utils.createMosaicDefinition(Utils.generateRandomAccount()); 15 | final MosaicDefinitionCreationNotification notification = new MosaicDefinitionCreationNotification(mosaicDefinition); 16 | 17 | // Assert: 18 | MatcherAssert.assertThat(notification.getType(), IsEqual.equalTo(NotificationType.MosaicDefinitionCreation)); 19 | MatcherAssert.assertThat(notification.getMosaicDefinition(), IsSame.sameInstance(mosaicDefinition)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /deploy/src/test/java/org/nem/deploy/test/MockHttpOutputMessage.java: -------------------------------------------------------------------------------- 1 | package org.nem.deploy.test; 2 | 3 | import java.io.*; 4 | import org.nem.core.utils.ExceptionUtils; 5 | import org.springframework.http.*; 6 | 7 | /** 8 | * A mock HttpOutputMessage implementation. 9 | */ 10 | public class MockHttpOutputMessage implements HttpOutputMessage { 11 | 12 | private final HttpHeaders headers = new HttpHeaders(); 13 | private final ByteArrayOutputStream bodyStream = new ByteArrayOutputStream(); 14 | 15 | @Override 16 | public HttpHeaders getHeaders() { 17 | return this.headers; 18 | } 19 | 20 | @Override 21 | public OutputStream getBody() throws IOException { 22 | return this.bodyStream; 23 | } 24 | 25 | /** 26 | * Gets the body as a string. 27 | * 28 | * @return The body as a string. 29 | */ 30 | public String getBodyAsString() { 31 | return ExceptionUtils.propagate(() -> this.bodyStream.toString("UTF-8")); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /peer/src/main/java/org/nem/peer/trust/score/TrustScores.java: -------------------------------------------------------------------------------- 1 | package org.nem.peer.trust.score; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | import org.nem.core.node.Node; 6 | 7 | /** 8 | * A collection of TrustScore objects. 9 | */ 10 | public class TrustScores extends Scores { 11 | 12 | private final Map trustScoreSums = new ConcurrentHashMap<>(); 13 | 14 | @Override 15 | protected TrustScore createScore() { 16 | return new TrustScore(); 17 | } 18 | 19 | /** 20 | * Gets the local trust weight for the specified node. 21 | * 22 | * @param node The node. 23 | * @return The local trust weight. 24 | */ 25 | public RealDouble getScoreWeight(final Node node) { 26 | RealDouble sum = this.trustScoreSums.get(node); 27 | if (null == sum) { 28 | sum = new RealDouble(0); 29 | this.trustScoreSums.put(node, sum); 30 | } 31 | 32 | return sum; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/function/PentaFunction.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.function; 2 | 3 | /** 4 | * Represents a function that accepts five arguments and produces a result. 5 | * 6 | * @param The type of the first argument. 7 | * @param The type of the second argument. 8 | * @param The type of the third argument. 9 | * @param The type of the fourth argument. 10 | * @param The type of the fifth argument. 11 | * @param The type of the result. 12 | */ 13 | @FunctionalInterface 14 | @SuppressWarnings("unused") 15 | public interface PentaFunction { 16 | 17 | /** 18 | * Applies this function to the given arguments. 19 | * 20 | * @param t The first argument. 21 | * @param u The second argument. 22 | * @param v The third argument. 23 | * @param w The fourth argument. 24 | * @param x The fifth argument. 25 | * @return The result. 26 | */ 27 | R apply(T t, U u, V v, W w, X x); 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/nem/core/model/ncc/NamespaceMetaDataPair.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.ncc; 2 | 3 | import org.nem.core.model.namespace.Namespace; 4 | import org.nem.core.serialization.Deserializer; 5 | 6 | /** 7 | * Pair containing a namespace and meta data. 8 | */ 9 | public class NamespaceMetaDataPair extends AbstractMetaDataPair { 10 | 11 | /** 12 | * Creates a new pair. 13 | * 14 | * @param namespace The namespace. 15 | * @param metaData The meta data. 16 | */ 17 | public NamespaceMetaDataPair(final Namespace namespace, final DefaultMetaData metaData) { 18 | super("namespace", "meta", namespace, metaData); 19 | } 20 | 21 | /** 22 | * Deserializes a pair. 23 | * 24 | * @param deserializer The deserializer 25 | */ 26 | public NamespaceMetaDataPair(final Deserializer deserializer) { 27 | super("namespace", "meta", Namespace::new, DefaultMetaData::new, deserializer); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /core/src/test/java/org/nem/core/model/ncc/UnconfirmedTransactionMetaDataPairTest.java: -------------------------------------------------------------------------------- 1 | package org.nem.core.model.ncc; 2 | 3 | import org.nem.core.crypto.Hash; 4 | import org.nem.core.model.Transaction; 5 | import org.nem.core.test.RandomTransactionFactory; 6 | 7 | public class UnconfirmedTransactionMetaDataPairTest extends AbstractMetaDataPairTest { 8 | 9 | public UnconfirmedTransactionMetaDataPairTest() { 10 | super(account -> { 11 | final Transaction transfer = RandomTransactionFactory.createTransfer(account); 12 | transfer.sign(); 13 | return transfer; 14 | }, id -> new UnconfirmedTransactionMetaData(Hash.fromHexString(Integer.toHexString(id))), UnconfirmedTransactionMetaDataPair::new, 15 | UnconfirmedTransactionMetaDataPair::new, transaction -> transaction.getSigner().getAddress(), 16 | metaData -> Integer.parseInt(metaData.getInnerTransactionHash().toString(), 16)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/controller/requests/AccountTransactionsId.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.controller.requests; 2 | 3 | import org.nem.core.crypto.Hash; 4 | import org.nem.core.model.ncc.AccountId; 5 | import org.nem.core.utils.StringUtils; 6 | 7 | /** 8 | * An identifier comprised of an address and an optional transaction hash used when performing transaction paging. 9 | */ 10 | public class AccountTransactionsId extends AccountId { 11 | private final Hash hash; 12 | 13 | /** 14 | * Creates a new account page. 15 | * 16 | * @param address The address. 17 | * @param hash The hash. 18 | */ 19 | public AccountTransactionsId(final String address, final String hash) { 20 | super(address); 21 | this.hash = StringUtils.isNullOrEmpty(hash) ? null : Hash.fromHexString(hash); 22 | } 23 | 24 | /** 25 | * Gets the hash. 26 | * 27 | * @return The hash. 28 | */ 29 | public Hash getHash() { 30 | return this.hash; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/dao/HibernateUtils.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.dao; 2 | 3 | import java.util.List; 4 | import org.hibernate.*; 5 | 6 | /** 7 | * Helper class containing hibernate utility functions. 8 | */ 9 | public class HibernateUtils { 10 | 11 | /** 12 | * Calls list on query and casts the result. 13 | * 14 | * @param query The query. 15 | * @param The result entity type. 16 | * @return The typed list. 17 | */ 18 | @SuppressWarnings("unchecked") 19 | public static List listAndCast(final Query query) { 20 | return (List) query.list(); 21 | } 22 | 23 | /** 24 | * Calls list on criteria and casts the result. 25 | * 26 | * @param criteria The criteria. 27 | * @param The result entity type. 28 | * @return The typed list. 29 | */ 30 | @SuppressWarnings("unchecked") 31 | public static List listAndCast(final Criteria criteria) { 32 | return (List) criteria.list(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /nis/src/main/java/org/nem/nis/mappers/MosaicModelToDbModelMapping.java: -------------------------------------------------------------------------------- 1 | package org.nem.nis.mappers; 2 | 3 | import org.nem.core.model.mosaic.Mosaic; 4 | import org.nem.nis.dbmodel.*; 5 | 6 | /** 7 | * A mapping that is able to map a model mosaic to a db model mosaic. 8 | */ 9 | public class MosaicModelToDbModelMapping implements IMapping { 10 | private final IMapper mapper; 11 | 12 | /** 13 | * Creates a new mapping. 14 | * 15 | * @param mapper The mapper. 16 | */ 17 | public MosaicModelToDbModelMapping(final IMapper mapper) { 18 | this.mapper = mapper; 19 | } 20 | 21 | @Override 22 | public DbMosaic map(final Mosaic source) { 23 | final DbMosaicId dbMosaicId = this.mapper.map(source.getMosaicId(), DbMosaicId.class); 24 | final DbMosaic dbMosaic = new DbMosaic(); 25 | dbMosaic.setDbMosaicId(dbMosaicId.getId()); 26 | dbMosaic.setQuantity(source.getQuantity().getRaw()); 27 | return dbMosaic; 28 | } 29 | } 30 | --------------------------------------------------------------------------------