├── DOCKER ├── testnet │ ├── node1 │ │ ├── tendermint.log │ │ ├── data │ │ │ └── priv_validator_state.json │ │ └── config │ │ │ ├── node_key.json │ │ │ ├── priv_validator_key.json │ │ │ └── genesis.json │ ├── node2 │ │ ├── tendermint.log │ │ ├── data │ │ │ └── priv_validator_state.json │ │ └── config │ │ │ ├── node_key.json │ │ │ ├── priv_validator_key.json │ │ │ └── genesis.json │ ├── node3 │ │ ├── tendermint.log │ │ ├── data │ │ │ └── priv_validator_state.json │ │ └── config │ │ │ ├── node_key.json │ │ │ ├── priv_validator_key.json │ │ │ └── genesis.json │ └── node0 │ │ ├── data │ │ └── priv_validator_state.json │ │ └── config │ │ ├── node_key.json │ │ ├── priv_validator_key.json │ │ └── genesis.json ├── Dockerfile └── wrapper.sh ├── .idea └── .idea.PhantasmaChain │ └── .idea │ ├── .name │ ├── encodings.xml │ ├── vcs.xml │ ├── indexLayout.xml │ └── .gitignore ├── logo.png ├── fix-eol.sh ├── Phantasma.Core ├── src │ ├── Domain │ │ ├── IChainSwap.cs │ │ ├── IOracleObserver.cs │ │ ├── ITask.cs │ │ ├── ICustomContract.cs │ │ ├── IFeed.cs │ │ ├── Leaderboard.cs │ │ ├── ITransaction.cs │ │ ├── IExecutionContext.cs │ │ ├── IArchiveEncryption.cs │ │ ├── IChainTask.cs │ │ ├── IExecutionFrame.cs │ │ ├── IAPIResult.cs │ │ ├── INativeContract.cs │ │ ├── IOrganization.cs │ │ ├── IOracleReader.cs │ │ ├── ExecutionContext.cs │ │ ├── IArchive.cs │ │ ├── TransactionResult.cs │ │ ├── ExecutionFrame.cs │ │ ├── OracleEntry.cs │ │ ├── Opcodes.cs │ │ ├── IVirtualMachine.cs │ │ ├── OracleFeed.cs │ │ ├── Exceptions.cs │ │ └── PlatformInfo.cs │ ├── Cryptography │ │ ├── SignatureKind.cs │ │ ├── Hashing │ │ │ ├── RIPEMD160.cs │ │ │ ├── SHA3Keccak.cs │ │ │ └── SHA256.cs │ │ ├── Entropy.cs │ │ ├── PoW.cs │ │ ├── Signature.cs │ │ └── EdDSA │ │ │ └── Ed25519Signature.cs │ ├── Numerics │ │ └── Phantasma.Numerics.csproj.user │ ├── Storage │ │ └── Context │ │ │ ├── IStorageCollection.cs │ │ │ ├── KeyStoreStorage.cs │ │ │ └── StorageValue.cs │ ├── Utils │ │ └── StreamUtils.cs │ └── Phantasma.Core.csproj └── tests │ ├── AddressTests.cs │ └── Phantasma.Core.Tests.csproj ├── Phantasma.Node ├── testnet │ ├── node0 │ │ ├── data │ │ │ └── priv_validator_state.json │ │ └── config │ │ │ ├── node_key.json │ │ │ ├── priv_validator_key.json │ │ │ └── genesis.json │ ├── node1 │ │ ├── data │ │ │ └── priv_validator_state.json │ │ └── config │ │ │ ├── node_key.json │ │ │ ├── priv_validator_key.json │ │ │ └── genesis.json │ ├── node2 │ │ ├── data │ │ │ └── priv_validator_state.json │ │ └── config │ │ │ ├── node_key.json │ │ │ ├── priv_validator_key.json │ │ │ └── genesis.json │ └── node3 │ │ ├── data │ │ └── priv_validator_state.json │ │ └── config │ │ ├── node_key.json │ │ ├── priv_validator_key.json │ │ └── genesis.json ├── Events │ ├── InvalidateEndpointCacheEvent.cs │ ├── IEventBus.cs │ └── EventBus.cs ├── Authentication │ ├── BasicAuthenticationDefaults.cs │ ├── BasicAuthenticationSchemeOptions.cs │ └── BasicAuthenticationExtensions.cs ├── Caching │ ├── EndpointCacheResult.cs │ └── IEndpointCacheManager.cs ├── Metrics │ ├── IEndpointMetrics.cs │ └── EndpointMetrics.cs ├── Shell │ └── SpookShell.cs ├── Chains │ ├── Neo2 │ │ └── Asset.cs │ └── Ethereum │ │ ├── EthEvents.cs │ │ ├── EthTxExtensions.cs │ │ └── EthFunctions.cs ├── Hosting │ └── EventBusBackgroundService.cs ├── Converters │ └── EnumerableJsonConverterFactory.cs ├── DeliverTxResult.cs ├── Oracles │ ├── Pricer.cs │ ├── CryptoCompare.cs │ └── CoinGecko.cs ├── Swagger │ ├── SwaggerAuthorizationMiddleware.cs │ └── SwaggerExtensions.cs └── Middleware │ ├── ErrorLoggingMiddleware.cs │ └── PerformanceMiddleware.cs ├── global.json ├── Phantasma.Business ├── tests │ ├── Blockchain │ │ ├── SwapsTest.cs │ │ ├── GasMachineTest.cs │ │ ├── TransactionTest.cs │ │ └── BlockTest.cs │ ├── VM │ │ ├── DisassemblerTest.cs │ │ ├── ScriptContextTest.cs │ │ ├── ExecutionContextTest.cs │ │ ├── ExecutionFrameTest.cs │ │ └── DebugInfoTest.cs │ └── Phantasma.Business.Tests.csproj └── src │ ├── CodeGen │ ├── CompilerException.cs │ ├── Core │ │ ├── Nodes │ │ │ ├── ExpressionNode.cs │ │ │ ├── ImportNode.cs │ │ │ ├── ExitNode.cs │ │ │ ├── TypeNode.cs │ │ │ ├── CallNode.cs │ │ │ ├── WhileNode.cs │ │ │ ├── ParameterNode.cs │ │ │ ├── StatementNode.cs │ │ │ ├── ClassNode.cs │ │ │ ├── DeclarationNode.cs │ │ │ ├── AssignmentNode.cs │ │ │ ├── ModuleNode.cs │ │ │ ├── StackAssignmentNode.cs │ │ │ ├── BlockNode.cs │ │ │ ├── ReturnNode.cs │ │ │ ├── VariableExpressionNode.cs │ │ │ ├── LiteralExpressionNode.cs │ │ │ └── UnaryExpressionNode.cs │ │ ├── LanguageProcessor.cs │ │ └── Compiler.cs │ └── Assembler │ │ └── Label.cs │ ├── Blockchain │ ├── TransactionExtensions.cs │ ├── Interop.cs │ ├── CustomContract.cs │ ├── Contracts │ │ ├── CrownContract.tomb │ │ ├── ContractNames.cs │ │ └── FriendContract.cs │ └── Storage │ │ └── SharedArchiveEncryption.cs │ └── Phantasma.Business.csproj ├── Tendermint.RPC ├── src │ ├── Endpoint │ │ ├── IEndpointResponse.cs │ │ ├── Subscribe.cs │ │ ├── Unsubscribe.cs │ │ ├── UnsubscribeAll.cs │ │ ├── Health.cs │ │ ├── EEndpointRequest.cs │ │ ├── UnconfirmedTxs.cs │ │ ├── Blockchain.cs │ │ ├── ConsensusParams.cs │ │ ├── BroadcastTxAsync.cs │ │ ├── NumUnconfirmedTxs.cs │ │ ├── TxSearch.cs │ │ ├── BroadcastTxSync.cs │ │ ├── AbciInfo.cs │ │ └── Block.cs │ ├── NodeRpcException.cs │ ├── RpcRequest.cs │ ├── JsonNetSerializer.cs │ ├── RpcResponse.cs │ └── INodeRpc.cs └── Tendermint.RPC.csproj ├── .gitignore ├── .editorconfig ├── Tendermint ├── CodeType.cs ├── proto │ └── tendermint │ │ ├── libs │ │ └── bits │ │ │ └── types.proto │ │ ├── types │ │ ├── events.proto │ │ ├── block.proto │ │ ├── validator.proto │ │ ├── evidence.proto │ │ └── canonical.proto │ │ ├── mempool │ │ ├── types.proto │ │ └── message.go │ │ ├── crypto │ │ ├── keys.proto │ │ └── proof.proto │ │ ├── privval │ │ └── service.proto │ │ ├── version │ │ └── types.proto │ │ ├── p2p │ │ ├── conn.proto │ │ ├── pex.proto │ │ ├── pex.go │ │ └── types.proto │ │ ├── rpc │ │ └── grpc │ │ │ └── types.proto │ │ ├── consensus │ │ ├── message_test.go │ │ ├── wal.proto │ │ └── message.go │ │ ├── blocksync │ │ └── types.proto │ │ └── statesync │ │ └── types.proto ├── Extensions │ ├── ByteArrayExtensions.cs │ ├── IntExtensions.cs │ ├── StringExtensions.cs │ └── ByteStringExtensions.cs └── Tendermint.csproj ├── Phantasma.Shared └── src │ ├── Types │ ├── Surprise.cs │ └── Map.cs │ ├── Phantasma.Shared.csproj │ └── Utils │ └── ByteArrayComparer.cs ├── .github ├── pull_request_template.md └── workflows │ ├── dotnet-core.yml │ └── dotnet-server.yml ├── Phantasma.Tests ├── Phantasma.Tests.csproj.user ├── .idea │ └── .idea.Phantasma.Tests.dir │ │ └── .idea │ │ └── .gitignore ├── Phantasma.Neo │ └── Utils │ │ └── LuxUtils.cs ├── WalletTests.cs ├── NachoTests.cs ├── Phantasma.Simulator │ └── Phantasma.Simulator.csproj └── Phantasma.Tests.csproj ├── Phantasma.Infrastructure └── src │ ├── API │ ├── Controllers │ │ ├── BaseControllerV1.cs │ │ ├── BaseRpcControllerV1.cs │ │ ├── ValidatorController.cs │ │ ├── ChainController.cs │ │ ├── OrganizationController.cs │ │ ├── ContractController.cs │ │ ├── LeaderboardController.cs │ │ └── PlatformController.cs │ └── DefaultAvatar.cs │ ├── RocksDB │ └── Phantasma.RocksDB.csproj │ ├── Pay │ ├── Phantasma.Pay.csproj │ └── WalletUtils.cs │ └── Phantasma.Infrastructure.csproj ├── cl.sh ├── .travis.yml ├── clean.sh └── LICENSE /DOCKER/testnet/node1/tendermint.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /DOCKER/testnet/node2/tendermint.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /DOCKER/testnet/node3/tendermint.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.idea/.idea.PhantasmaChain/.idea/.name: -------------------------------------------------------------------------------- 1 | PhantasmaChain -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Relfos/phantasma-ng/master/logo.png -------------------------------------------------------------------------------- /fix-eol.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | find ./ -name "*.cs" -exec dos2unix --keepdate --keep-bom {} + -------------------------------------------------------------------------------- /DOCKER/testnet/node0/data/priv_validator_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "height": "0", 3 | "round": 0, 4 | "step": 0 5 | } -------------------------------------------------------------------------------- /DOCKER/testnet/node1/data/priv_validator_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "height": "0", 3 | "round": 0, 4 | "step": 0 5 | } -------------------------------------------------------------------------------- /DOCKER/testnet/node2/data/priv_validator_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "height": "0", 3 | "round": 0, 4 | "step": 0 5 | } -------------------------------------------------------------------------------- /DOCKER/testnet/node3/data/priv_validator_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "height": "0", 3 | "round": 0, 4 | "step": 0 5 | } -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/IChainSwap.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Core; 2 | 3 | public interface IChainSwap 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node0/data/priv_validator_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "height": "0", 3 | "round": 0, 4 | "step": 0 5 | } -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node1/data/priv_validator_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "height": "0", 3 | "round": 0, 4 | "step": 0 5 | } -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node2/data/priv_validator_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "height": "0", 3 | "round": 0, 4 | "step": 0 5 | } -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node3/data/priv_validator_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "height": "0", 3 | "round": 0, 4 | "step": 0 5 | } -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "6.0", 4 | "rollForward": "latestMajor", 5 | "allowPrerelease": true 6 | } 7 | } -------------------------------------------------------------------------------- /Phantasma.Business/tests/Blockchain/SwapsTest.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Business.Tests; 2 | 3 | public class SwapsTest 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Phantasma.Business/tests/Blockchain/GasMachineTest.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Business.Tests; 2 | 3 | public class GasMachineTest 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Phantasma.Business/tests/VM/DisassemblerTest.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Business.Tests.VM; 2 | 3 | public class DisassemblerTest 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Phantasma.Business/tests/VM/ScriptContextTest.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Business.Tests.VM; 2 | 3 | public class ScriptContextTest 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/IEndpointResponse.cs: -------------------------------------------------------------------------------- 1 | namespace Tendermint.RPC.Endpoint 2 | { 3 | public interface IEndpointResponse 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.tmp 2 | .vs/ 3 | TestResults/ 4 | Published/ 5 | */obj/ 6 | */bin/ 7 | packages/ 8 | .github/* 9 | 10 | **/obj/** 11 | **/bin/** 12 | **/Dumps/** 13 | -------------------------------------------------------------------------------- /Phantasma.Node/Events/InvalidateEndpointCacheEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Node.Events; 2 | 3 | public class InvalidateEndpointCacheEvent 4 | { 5 | public string Tag { get; set; } 6 | } 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Don't use tabs for indentation. 2 | [*] 3 | indent_style = space 4 | end_of_line = lf 5 | 6 | # Code files 7 | [*.{cs}] 8 | indent_size = 4 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Cryptography/SignatureKind.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Core 2 | { 3 | public enum SignatureKind 4 | { 5 | None, 6 | Ed25519, 7 | ECDSA 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /.idea/.idea.PhantasmaChain/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Phantasma.Node/Authentication/BasicAuthenticationDefaults.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Node.Authentication; 2 | 3 | public class BasicAuthenticationDefaults 4 | { 5 | public const string AuthenticationScheme = "Basic"; 6 | } 7 | -------------------------------------------------------------------------------- /DOCKER/testnet/node0/config/node_key.json: -------------------------------------------------------------------------------- 1 | {"id":"0c8203a0e63d7c025a4be9e4391b42fb65d344ab","priv_key":{"type":"tendermint/PrivKeyEd25519","value":"fYOKXzF1PA/dGFBu0KS/0ldzXjv0Gqv+/hP9s1d7J28H8bu7BcWOIlEqOROTr5ifhDk+NCQdJB+LBqlTgaVahA=="}} -------------------------------------------------------------------------------- /DOCKER/testnet/node1/config/node_key.json: -------------------------------------------------------------------------------- 1 | {"id":"e602bda8f1bc8b916af4d312ce2b5c610074f423","priv_key":{"type":"tendermint/PrivKeyEd25519","value":"AhVZnuWq8cmgnd8c63IuGDnYjYN+MiflhHNGPZOi3EKhWo/EABxxszjAb2bzEzJTPF287GMicERJoGTtI6ss3Q=="}} -------------------------------------------------------------------------------- /DOCKER/testnet/node2/config/node_key.json: -------------------------------------------------------------------------------- 1 | {"id":"ea9eb814c23bc75d53324f9b650ff2b71720a0c3","priv_key":{"type":"tendermint/PrivKeyEd25519","value":"EZOV8eeJiu0k/dR12nW+K4AZ3DUpmtypHQesg0larNB47zZ5YGxHRTwDRgdkLaE6wsU+lgev81qh0heXck5rQw=="}} -------------------------------------------------------------------------------- /DOCKER/testnet/node3/config/node_key.json: -------------------------------------------------------------------------------- 1 | {"id":"5aa2fce0959bc52e743b5653f5010b9f7eafcdb1","priv_key":{"type":"tendermint/PrivKeyEd25519","value":"MS5+pO4SJ2tRu98tl7tMUzBwN/1llU9Hgk77l4o2ASrzUefZM44woD13da48P2BGWB6703tPSaDBM353kIMaWQ=="}} -------------------------------------------------------------------------------- /.idea/.idea.PhantasmaChain/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node0/config/node_key.json: -------------------------------------------------------------------------------- 1 | {"id":"0c8203a0e63d7c025a4be9e4391b42fb65d344ab","priv_key":{"type":"tendermint/PrivKeyEd25519","value":"fYOKXzF1PA/dGFBu0KS/0ldzXjv0Gqv+/hP9s1d7J28H8bu7BcWOIlEqOROTr5ifhDk+NCQdJB+LBqlTgaVahA=="}} -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node1/config/node_key.json: -------------------------------------------------------------------------------- 1 | {"id":"e602bda8f1bc8b916af4d312ce2b5c610074f423","priv_key":{"type":"tendermint/PrivKeyEd25519","value":"AhVZnuWq8cmgnd8c63IuGDnYjYN+MiflhHNGPZOi3EKhWo/EABxxszjAb2bzEzJTPF287GMicERJoGTtI6ss3Q=="}} -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node2/config/node_key.json: -------------------------------------------------------------------------------- 1 | {"id":"ea9eb814c23bc75d53324f9b650ff2b71720a0c3","priv_key":{"type":"tendermint/PrivKeyEd25519","value":"EZOV8eeJiu0k/dR12nW+K4AZ3DUpmtypHQesg0larNB47zZ5YGxHRTwDRgdkLaE6wsU+lgev81qh0heXck5rQw=="}} -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node3/config/node_key.json: -------------------------------------------------------------------------------- 1 | {"id":"5aa2fce0959bc52e743b5653f5010b9f7eafcdb1","priv_key":{"type":"tendermint/PrivKeyEd25519","value":"MS5+pO4SJ2tRu98tl7tMUzBwN/1llU9Hgk77l4o2ASrzUefZM44woD13da48P2BGWB6703tPSaDBM353kIMaWQ=="}} -------------------------------------------------------------------------------- /Tendermint/CodeType.cs: -------------------------------------------------------------------------------- 1 | namespace Types 2 | { 3 | public enum CodeType : uint 4 | { 5 | Ok = 0, 6 | Error = 1, 7 | Expired = 2, 8 | InvalidChain = 3, 9 | UnsignedTx = 4, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Phantasma.Node/Events/IEventBus.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace Phantasma.Node.Events; 5 | 6 | public interface IEventBus 7 | { 8 | Task Run(CancellationToken cancellationToken); 9 | } 10 | -------------------------------------------------------------------------------- /Phantasma.Shared/src/Types/Surprise.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Shared.Types 2 | { 3 | public interface IPromise 4 | { 5 | T Value { get; } 6 | Timestamp Timestamp { get; } 7 | bool Hidden { get; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Phantasma.Node/Caching/EndpointCacheResult.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Node.Caching; 2 | 3 | public class EndpointCacheResult 4 | { 5 | public string Key { get; set; } 6 | public string Content { get; set; } 7 | public bool Cached { get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Please do not open any `Pull Requests` to the `master` branch. 2 | ## If you do so expect them to be closed without further notice. 3 | 4 | ## `Pull Requests` are very weclome on the `development` branch. 5 | 6 | Thank you. 7 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/IOracleObserver.cs: -------------------------------------------------------------------------------- 1 | using Phantasma.Core.Context; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public interface IOracleObserver 6 | { 7 | void Update(INexus nexus, StorageContext storage); 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /Phantasma.Business/tests/VM/ExecutionContextTest.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | 3 | namespace Phantasma.Business.Tests.VM; 4 | 5 | public class ExecutionContextTest 6 | { 7 | [Fact] 8 | public void test_something() 9 | { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Phantasma.Tests/Phantasma.Tests.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | 6 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Numerics/Phantasma.Numerics.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | 6 | -------------------------------------------------------------------------------- /Phantasma.Node/Authentication/BasicAuthenticationSchemeOptions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authentication; 2 | 3 | namespace Phantasma.Node.Authentication; 4 | 5 | public class BasicAuthenticationSchemeOptions : AuthenticationSchemeOptions 6 | { 7 | public string Realm { get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/libs/bits/types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.libs.bits; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/libs/bits"; 5 | 6 | message BitArray { 7 | int64 bits = 1; 8 | repeated uint64 elems = 2; 9 | } 10 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/Subscribe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Tendermint.RPC.Endpoint 6 | { 7 | /// 8 | /// Websocket API 9 | /// 10 | public class Subscribe 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/Unsubscribe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Tendermint.RPC.Endpoint 6 | { 7 | /// 8 | /// Websocket API 9 | /// 10 | public class Unsubscribe 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/types/events.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.types; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types"; 5 | 6 | message EventDataRoundState { 7 | int64 height = 1; 8 | int32 round = 2; 9 | string step = 3; 10 | } 11 | -------------------------------------------------------------------------------- /Phantasma.Infrastructure/src/API/Controllers/BaseControllerV1.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace Phantasma.Infrastructure.Controllers; 4 | 5 | [ApiController] 6 | [Produces("application/json")] 7 | [Route("api/v1")] 8 | public abstract class BaseControllerV1 : ControllerBase 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /Phantasma.Infrastructure/src/API/Controllers/BaseRpcControllerV1.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace Phantasma.Infrastructure.Controllers; 4 | 5 | [ApiController] 6 | [Produces("application/json")] 7 | [Route("")] 8 | public abstract class BaseRpcControllerV1 : ControllerBase 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/UnsubscribeAll.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Tendermint.RPC.Endpoint 6 | { 7 | /// 8 | /// Websocket API 9 | /// 10 | public class UnsubscribeAll 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Phantasma.Shared/src/Phantasma.Shared.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/.idea.PhantasmaChain/.idea/indexLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ../../new 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/mempool/types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.mempool; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/mempool"; 5 | 6 | message Txs { 7 | repeated bytes txs = 1; 8 | } 9 | 10 | message Message { 11 | oneof sum { 12 | Txs txs = 1; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/CompilerException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Phantasma.Business 4 | { 5 | public class CompilerException : Exception 6 | { 7 | public CompilerException(uint lineNumber, string message) 8 | : base($"ERROR: {message} in line {lineNumber}.") 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/ITask.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public enum TaskFrequencyMode 6 | { 7 | Always, 8 | Time, 9 | Blocks, 10 | } 11 | 12 | public enum TaskResult 13 | { 14 | Running, 15 | Halted, 16 | Crashed, 17 | Skipped, 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /.idea/.idea.PhantasmaChain/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Rider ignored files 5 | /contentModel.xml 6 | /projectSettingsUpdater.xml 7 | /.idea.PhantasmaChain.iml 8 | /modules.xml 9 | # Editor-based HTTP Client requests 10 | /httpRequests/ 11 | # Datasource local storage ignored files 12 | /dataSources/ 13 | /dataSources.local.xml 14 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/ICustomContract.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | 3 | namespace Phantasma.Core; 4 | 5 | public interface ICustomContract 6 | { 7 | string Name { get; } 8 | byte[] Script { get; } 9 | ContractInterface ABI { get; } 10 | BigInteger Order { get; } // TODO remove this? 11 | IRuntime Runtime { get; } 12 | Address Address { get; } 13 | } 14 | -------------------------------------------------------------------------------- /Phantasma.Business/src/Blockchain/TransactionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Phantasma.Core; 2 | 3 | namespace Phantasma.Business 4 | { 5 | public static class TransactionExtensions 6 | { 7 | public static bool IsValid(this Transaction tx, IChain chain) 8 | { 9 | return (chain.Name == tx.ChainName && chain.Nexus.Name == tx.NexusName); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/IFeed.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Phantasma.Core 3 | { 4 | public enum FeedMode 5 | { 6 | First, 7 | Last, 8 | Max, 9 | Min, 10 | Average 11 | } 12 | 13 | public interface IFeed 14 | { 15 | public string Name { get; } 16 | public Address Address { get; } 17 | public FeedMode Mode { get; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Phantasma.Tests/.idea/.idea.Phantasma.Tests.dir/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Rider ignored files 5 | /modules.xml 6 | /contentModel.xml 7 | /projectSettingsUpdater.xml 8 | /.idea.Phantasma.Tests.iml 9 | # Editor-based HTTP Client requests 10 | /httpRequests/ 11 | # Datasource local storage ignored files 12 | /dataSources/ 13 | /dataSources.local.xml 14 | -------------------------------------------------------------------------------- /DOCKER/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:stable-slim 2 | WORKDIR /app 3 | 4 | # Copy everything 5 | COPY DOCKER/wrapper.sh ./ 6 | COPY DOCKER/testnet ./testnet 7 | COPY DOCKER/bin ./testnet 8 | 9 | RUN apt-get update; apt-get install -y libc6-dev \ 10 | libsnappy-dev libicu-dev screen bash vim net-tools ca-certificates openssl libssl-dev 11 | 12 | EXPOSE 5101 5102 5103 5104 13 | 14 | ENTRYPOINT ["/app/wrapper.sh"] 15 | 16 | -------------------------------------------------------------------------------- /DOCKER/testnet/node0/config/priv_validator_key.json: -------------------------------------------------------------------------------- 1 | { 2 | "address": "11BB132EC77BC788B65CEAE309A21EC9AD30686C", 3 | "pub_key": { 4 | "type": "tendermint/PubKeyEd25519", 5 | "value": "XGZrm1htSmuI3+fhsu8+VxOuPGbqubdE13gVbhIHe1Q=" 6 | }, 7 | "priv_key": { 8 | "type": "tendermint/PrivKeyEd25519", 9 | "value": "IfyqKw3PG2PA2bwDL8Z4WB6ecddnX7cMY4jb/TXEOKRcZmubWG1Ka4jf5+Gy7z5XE648Zuq5t0TXeBVuEgd7VA==" 10 | } 11 | } -------------------------------------------------------------------------------- /DOCKER/testnet/node1/config/priv_validator_key.json: -------------------------------------------------------------------------------- 1 | { 2 | "address": "7CCF8D79D6B7ED4B0FACFD4C3C1FA547DEA0E5CD", 3 | "pub_key": { 4 | "type": "tendermint/PubKeyEd25519", 5 | "value": "IiiA7W0pkTGnIFi/zqIHjfgMt/1gLZUwo/Bt6L8F6Ms=" 6 | }, 7 | "priv_key": { 8 | "type": "tendermint/PrivKeyEd25519", 9 | "value": "qJvlX0IFlM1jq5NdOzeTBdd2nwOajnNMhYHQDcpoPvoiKIDtbSmRMacgWL/OogeN+Ay3/WAtlTCj8G3ovwXoyw==" 10 | } 11 | } -------------------------------------------------------------------------------- /DOCKER/testnet/node2/config/priv_validator_key.json: -------------------------------------------------------------------------------- 1 | { 2 | "address": "C06DF36A9325CAA700406E1404E777D3DE7533B2", 3 | "pub_key": { 4 | "type": "tendermint/PubKeyEd25519", 5 | "value": "ZXuG6/FObVz4mhCpKwPHi6R/ZnehI/t+Xww74DX56II=" 6 | }, 7 | "priv_key": { 8 | "type": "tendermint/PrivKeyEd25519", 9 | "value": "0vO2mjoK9/eioHHpLtHs3E7Z4GY7lIySiFJIxa5Te6lle4br8U5tXPiaEKkrA8eLpH9md6Ej+35fDDvgNfnogg==" 10 | } 11 | } -------------------------------------------------------------------------------- /DOCKER/testnet/node3/config/priv_validator_key.json: -------------------------------------------------------------------------------- 1 | { 2 | "address": "92544D338AB5935A8F6D4CE3953546FB6B0368C5", 3 | "pub_key": { 4 | "type": "tendermint/PubKeyEd25519", 5 | "value": "/tirj7G+lHmiZ/L94DVoXDwBhC7bqPv4zoVS7Rlau8E=" 6 | }, 7 | "priv_key": { 8 | "type": "tendermint/PrivKeyEd25519", 9 | "value": "MJOu+vhS1Z3wttneYCSb64ijevipO7qI4Y2BrkVmTx7+2KuPsb6UeaJn8v3gNWhcPAGELtuo+/jOhVLtGVq7wQ==" 10 | } 11 | } -------------------------------------------------------------------------------- /Phantasma.Shared/src/Types/Map.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Phantasma.Shared.Types 4 | { 5 | public interface IMap 6 | { 7 | void Put(Key key, Value val); 8 | Value Get(Key key); 9 | bool Remove(Key key); 10 | bool Contains(Key key); 11 | void Clear(); 12 | void Iterate(Action visitor); 13 | 14 | uint Count { get; } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Storage/Context/IStorageCollection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Phantasma.Core.Context 4 | { 5 | public interface IStorageCollection 6 | { 7 | byte[] BaseKey { get; } 8 | StorageContext Context { get; } 9 | } 10 | 11 | public class StorageException: Exception 12 | { 13 | public StorageException(string msg): base(msg) 14 | { 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node0/config/priv_validator_key.json: -------------------------------------------------------------------------------- 1 | { 2 | "address": "11BB132EC77BC788B65CEAE309A21EC9AD30686C", 3 | "pub_key": { 4 | "type": "tendermint/PubKeyEd25519", 5 | "value": "XGZrm1htSmuI3+fhsu8+VxOuPGbqubdE13gVbhIHe1Q=" 6 | }, 7 | "priv_key": { 8 | "type": "tendermint/PrivKeyEd25519", 9 | "value": "IfyqKw3PG2PA2bwDL8Z4WB6ecddnX7cMY4jb/TXEOKRcZmubWG1Ka4jf5+Gy7z5XE648Zuq5t0TXeBVuEgd7VA==" 10 | } 11 | } -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node1/config/priv_validator_key.json: -------------------------------------------------------------------------------- 1 | { 2 | "address": "7CCF8D79D6B7ED4B0FACFD4C3C1FA547DEA0E5CD", 3 | "pub_key": { 4 | "type": "tendermint/PubKeyEd25519", 5 | "value": "IiiA7W0pkTGnIFi/zqIHjfgMt/1gLZUwo/Bt6L8F6Ms=" 6 | }, 7 | "priv_key": { 8 | "type": "tendermint/PrivKeyEd25519", 9 | "value": "qJvlX0IFlM1jq5NdOzeTBdd2nwOajnNMhYHQDcpoPvoiKIDtbSmRMacgWL/OogeN+Ay3/WAtlTCj8G3ovwXoyw==" 10 | } 11 | } -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node2/config/priv_validator_key.json: -------------------------------------------------------------------------------- 1 | { 2 | "address": "C06DF36A9325CAA700406E1404E777D3DE7533B2", 3 | "pub_key": { 4 | "type": "tendermint/PubKeyEd25519", 5 | "value": "ZXuG6/FObVz4mhCpKwPHi6R/ZnehI/t+Xww74DX56II=" 6 | }, 7 | "priv_key": { 8 | "type": "tendermint/PrivKeyEd25519", 9 | "value": "0vO2mjoK9/eioHHpLtHs3E7Z4GY7lIySiFJIxa5Te6lle4br8U5tXPiaEKkrA8eLpH9md6Ej+35fDDvgNfnogg==" 10 | } 11 | } -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node3/config/priv_validator_key.json: -------------------------------------------------------------------------------- 1 | { 2 | "address": "92544D338AB5935A8F6D4CE3953546FB6B0368C5", 3 | "pub_key": { 4 | "type": "tendermint/PubKeyEd25519", 5 | "value": "/tirj7G+lHmiZ/L94DVoXDwBhC7bqPv4zoVS7Rlau8E=" 6 | }, 7 | "priv_key": { 8 | "type": "tendermint/PrivKeyEd25519", 9 | "value": "MJOu+vhS1Z3wttneYCSb64ijevipO7qI4Y2BrkVmTx7+2KuPsb6UeaJn8v3gNWhcPAGELtuo+/jOhVLtGVq7wQ==" 10 | } 11 | } -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/Leaderboard.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public struct LeaderboardRow 6 | { 7 | public Address address; 8 | public BigInteger score; 9 | } 10 | 11 | public struct Leaderboard 12 | { 13 | public string name; 14 | public Address owner; 15 | public BigInteger size; 16 | public BigInteger round; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/ExpressionNode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Phantasma.Business.Core.Nodes 4 | { 5 | public abstract class ExpressionNode : CompilerNode 6 | { 7 | public ExpressionNode(CompilerNode owner) : base(owner) 8 | { 9 | } 10 | 11 | public abstract List Emit(Compiler compiler); 12 | 13 | public abstract TypeKind GetKind(); 14 | } 15 | } -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/ITransaction.cs: -------------------------------------------------------------------------------- 1 | using Phantasma.Shared.Types; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public interface ITransaction 6 | { 7 | byte[] Script { get; } 8 | 9 | string NexusName { get; } 10 | string ChainName { get; } 11 | 12 | Timestamp Expiration { get; } 13 | 14 | byte[] Payload { get; } 15 | 16 | Signature[] Signatures { get; } 17 | Hash Hash { get; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Phantasma.Node/Metrics/IEndpointMetrics.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | 4 | namespace Phantasma.Node.Metrics; 5 | 6 | public interface IEndpointMetrics 7 | { 8 | Task Count( 9 | string path 10 | ); 11 | 12 | Task[]> GetCounts(); 13 | 14 | Task Average( 15 | string path, 16 | long duration 17 | ); 18 | 19 | Task[]> GetAverages(); 20 | } 21 | -------------------------------------------------------------------------------- /Phantasma.Node/Shell/SpookShell.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Collections.Generic; 6 | using Phantasma.Core; 7 | using Phantasma.Node.Utils; 8 | 9 | namespace Phantasma.Node.Shell 10 | { 11 | class SpookShell 12 | { 13 | private Node _node; 14 | 15 | public SpookShell(string[] args, Node node) 16 | { 17 | _node = node; 18 | } 19 | 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Phantasma.Business/tests/VM/ExecutionFrameTest.cs: -------------------------------------------------------------------------------- 1 | using Phantasma.Core; 2 | using Xunit; 3 | 4 | namespace Phantasma.Business.Tests.VM; 5 | 6 | public class ExecutionFrameTest 7 | { 8 | 9 | private ExecutionFrame ExecutionFrame; 10 | 11 | private void Init() 12 | { 13 | //ExecutionFrame = new ExecutionFrame(); 14 | } 15 | 16 | [Fact] 17 | public void get_test_register() 18 | { 19 | //ExecutionFrame.GetRegister(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/Health.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Tendermint.RPC.Endpoint 6 | { 7 | /* 8 | The above command returns JSON structured like this: 9 | { 10 | "error": "", 11 | "result": {}, 12 | "id": "", 13 | "jsonrpc": "2.0" 14 | } 15 | */ 16 | 17 | public class ResultHealth : IEndpointResponse 18 | { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Cryptography/Hashing/RIPEMD160.cs: -------------------------------------------------------------------------------- 1 | using Org.BouncyCastle.Crypto.Digests; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public class RIPEMD160 6 | { 7 | public byte[] ComputeHash(byte[] rgb) 8 | { 9 | var digest = new RipeMD160Digest(); 10 | var result = new byte[digest.GetDigestSize()]; 11 | digest.BlockUpdate(rgb, 0, rgb.Length); 12 | digest.DoFinal(result, 0); 13 | 14 | return result; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /cl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | previous_tag=0 3 | for current_tag in $(git tag --sort=-creatordate) 4 | do 5 | 6 | if [ "$previous_tag" != 0 ];then 7 | tag_date=$(git log -1 --pretty=format:'%ad' --date=short ${previous_tag}) 8 | printf "## ${previous_tag} (${tag_date})\n\n" 9 | git log ${current_tag}...${previous_tag} --pretty=format:'* %s [View](https://github.com/phantasma-io/PhantasmaChain/commits/%H)' --reverse | grep -v Merge 10 | printf "\n\n" 11 | fi 12 | previous_tag=${current_tag} 13 | done 14 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/IExecutionContext.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public enum ExecutionState 6 | { 7 | Running, 8 | Break, 9 | Fault, 10 | Halt 11 | } 12 | 13 | public interface IExecutionContext 14 | { 15 | public string Name { get; } 16 | 17 | public Address Address { get; } 18 | 19 | public abstract ExecutionState Execute(IExecutionFrame frame, Stack stack); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Tendermint/Extensions/ByteArrayExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace Types.Extensions 4 | { 5 | public static class ByteArrayExtensions 6 | { 7 | // https://stackoverflow.com/a/311179/959687 8 | public static string ByteArrayToString(this byte[] ba) 9 | { 10 | var hex = new StringBuilder(ba.Length * 2); 11 | foreach (var b in ba) 12 | hex.AppendFormat("{0:x2}", b); 13 | return hex.ToString(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/IArchiveEncryption.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Core; 2 | 3 | public enum ArchiveEncryptionMode 4 | { 5 | None, 6 | Private, 7 | Shared 8 | } 9 | 10 | public interface IArchiveEncryption : ISerializable 11 | { 12 | ArchiveEncryptionMode Mode { get; } 13 | 14 | string EncryptName(string name, PhantasmaKeys keys); 15 | string DecryptName(string name, PhantasmaKeys keys); 16 | byte[] Encrypt(byte[] chunk, PhantasmaKeys keys); 17 | byte[] Decrypt(byte[] chunk, PhantasmaKeys keys); 18 | } 19 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/IChainTask.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using Phantasma.Core; 3 | 4 | namespace Phantasma.Core; 5 | 6 | public interface IChainTask 7 | { 8 | BigInteger ID { get; } 9 | bool State { get; } 10 | Address Owner { get; } 11 | string ContextName { get; } 12 | string Method { get; } 13 | uint Frequency { get; } 14 | uint Delay { get; } 15 | TaskFrequencyMode Mode { get; } 16 | BigInteger GasLimit { get; } 17 | BigInteger Height { get; } 18 | byte[] ToByteArray(); 19 | } 20 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/EEndpointRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Tendermint.RPC.Endpoint 6 | { 7 | public enum EEndpointRequest 8 | { 9 | AbciInfo, ConsensusState, DumpConsesusState, NetInfo, Genesis, Health, NumUnconfirmedTxs, Status, 10 | AbciQuery, Block, BlockByHash, BlockResults, Blockchain, Commit, ConsensusParams, Tx, TxSearch, UnconfirmedTxs, Validators, 11 | BroadcastTxAsync, BroadcastTxCommit, BroadcastTxSync 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/crypto/keys.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.crypto; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/crypto"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | 8 | // PublicKey defines the keys available for use with Tendermint Validators 9 | message PublicKey { 10 | option (gogoproto.compare) = true; 11 | option (gogoproto.equal) = true; 12 | 13 | oneof sum { 14 | bytes ed25519 = 1; 15 | bytes secp256k1 = 2; 16 | bytes sr25519 = 3; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Cryptography/Hashing/SHA3Keccak.cs: -------------------------------------------------------------------------------- 1 | using Org.BouncyCastle.Crypto.Digests; 2 | 3 | namespace Phantasma.Core.Hashing 4 | { 5 | public static class SHA3Keccak 6 | { 7 | public static byte[] CalculateHash(byte[] value) 8 | { 9 | var digest = new KeccakDigest(256); 10 | var output = new byte[digest.GetDigestSize()]; 11 | digest.BlockUpdate(value, 0, value.Length); 12 | digest.DoFinal(output, 0); 13 | return output; 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Phantasma.Infrastructure/src/API/DefaultAvatar.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Infrastructure 2 | { 3 | public static class DefaultAvatar 4 | { 5 | public readonly static string Data = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAAJFBMVEWcnJz////39/etra3e3t6lpaW1tbXn5+fW1tbv7+/Ozs69vb2ss4cPAAAAk0lEQVQoz2OgJWA2QOWnKAqVIfM5BIGgAUlgIUhAAsFnEwSDBLgAC0SgAC7ABBEQhQsYQgSEMQRwa2GHGopu7QaEQxpBfBF0pzsg+3WioKAkkn9ZHcFaAuACRhBDleEaFCECQjBNQYJQoAoVcIQJiCA5Cx4iCIcjHB+IEBCFBigcSMHMRDV1IkJAEiygiBAQYmAAABD5F4JgcTScAAAAAElFTkSuQmCC"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Phantasma.Infrastructure/src/RocksDB/Phantasma.RocksDB.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.1 4 | 40 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Phantasma.Node/Authentication/BasicAuthenticationExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authentication; 2 | 3 | namespace Phantasma.Node.Authentication; 4 | 5 | public static class BasicAuthenticationExtensions 6 | { 7 | public static AuthenticationBuilder AddBasicAuthentication(this AuthenticationBuilder builder) 8 | { 9 | return builder.AddScheme( 10 | BasicAuthenticationDefaults.AuthenticationScheme, options => options.Realm = "Phantasma"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Phantasma.Node/Caching/IEndpointCacheManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using Microsoft.Extensions.Primitives; 4 | 5 | namespace Phantasma.Node.Caching; 6 | 7 | public interface IEndpointCacheManager 8 | { 9 | Task Add(string key, string content, int duration, string tag = null); 10 | 11 | Task Get(string route, IEnumerable> queryParams, 12 | string tag = null); 13 | 14 | Task Invalidate(string tag = null); 15 | } 16 | -------------------------------------------------------------------------------- /Tendermint/Extensions/IntExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Google.Protobuf; 3 | 4 | namespace Types.Extensions 5 | { 6 | public static class IntExtensions 7 | { 8 | public static ByteString ToByteString(this int value) 9 | { 10 | var buffer = BitConverter.GetBytes(value); 11 | if (BitConverter.IsLittleEndian) 12 | { 13 | Array.Reverse(buffer); 14 | } 15 | 16 | return ByteString.CopyFrom(buffer, 0, buffer.Length); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Phantasma.Node/Chains/Neo2/Asset.cs: -------------------------------------------------------------------------------- 1 | using Neo; 2 | 3 | namespace Phantasma.Node.Chains 4 | { 5 | public class Asset 6 | { 7 | public UInt256 hash; 8 | public string name; 9 | } 10 | 11 | public enum AssetType : byte 12 | { 13 | CreditFlag = 0x40, 14 | DutyFlag = 0x80, 15 | 16 | GoverningToken = 0x00, 17 | UtilityToken = 0x01, 18 | Currency = 0x08, 19 | Share = DutyFlag | 0x10, 20 | Invoice = DutyFlag | 0x18, 21 | Token = CreditFlag | 0x20, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/privval/service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.privval; 3 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/privval"; 4 | 5 | import "tendermint/privval/types.proto"; 6 | 7 | //---------------------------------------- 8 | // Service Definition 9 | 10 | service PrivValidatorAPI { 11 | rpc GetPubKey(PubKeyRequest) returns (PubKeyResponse); 12 | rpc SignVote(SignVoteRequest) returns (SignedVoteResponse); 13 | rpc SignProposal(SignProposalRequest) returns (SignedProposalResponse); 14 | } 15 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/version/types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.version; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/version"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | 8 | // Consensus captures the consensus rules for processing a block in the blockchain, 9 | // including all blockchain data structures and the rules of the application's 10 | // state transition machine. 11 | message Consensus { 12 | option (gogoproto.equal) = true; 13 | 14 | uint64 block = 1; 15 | uint64 app = 2; 16 | } 17 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/IExecutionFrame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Numerics; 4 | using System.Collections.Generic; 5 | using System.Security.Policy; 6 | 7 | namespace Phantasma.Core 8 | { 9 | public interface IExecutionFrame 10 | { 11 | public VMObject[] Registers { get; } 12 | 13 | uint Offset { get; } // current instruction pointer **before** the frame was entered 14 | IExecutionContext Context { get; } 15 | IVirtualMachine VM { get; } 16 | 17 | VMObject GetRegister(int index); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Assembler/Label.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Business.Assembler 2 | { 3 | internal class Label : Semanteme 4 | { 5 | public readonly string Name; 6 | 7 | public Label(uint lineNumber, string name) : base(lineNumber) 8 | { 9 | this.Name = name; 10 | } 11 | 12 | public override void Process(ScriptBuilder sb) 13 | { 14 | sb.EmitLabel(Name); 15 | } 16 | 17 | public override string ToString() 18 | { 19 | return Name; 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Phantasma.Business/src/Blockchain/Interop.cs: -------------------------------------------------------------------------------- 1 | using Phantasma.Core; 2 | 3 | namespace Phantasma.Business 4 | { 5 | public static class InteropUtils 6 | { 7 | public static PhantasmaKeys GenerateInteropKeys(PhantasmaKeys genesisKeys, Hash genesisHash, string platformName) 8 | { 9 | var temp = $"{genesisKeys.ToWIF()}{genesisHash.ToString()}{platformName}"; 10 | temp = temp.ToUpper(); 11 | 12 | var privateKey = CryptoExtensions.Sha256(temp); 13 | var key = new PhantasmaKeys(privateKey); 14 | return key; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Phantasma.Core/tests/AddressTests.cs: -------------------------------------------------------------------------------- 1 | using Phantasma.Core; 2 | using Shouldly; 3 | using System.Text.Json.Nodes; 4 | using System.Collections.Generic; 5 | using Xunit; 6 | using static Phantasma.Core.WalletLink; 7 | 8 | namespace Phantasma.Core.Tests 9 | { 10 | public class AddressTests 11 | { 12 | [Fact] 13 | public void null_address_test() 14 | { 15 | var address = Address.Null; 16 | address.ToByteArray().Length.ShouldBe(Address.LengthInBytes); 17 | address.ToByteArray().ShouldBe(new byte[Address.LengthInBytes]); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Phantasma.Node/Chains/Ethereum/EthEvents.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using Nethereum.Contracts; 3 | using Nethereum.ABI.FunctionEncoding.Attributes; 4 | 5 | namespace Phantasma.Node.Chains 6 | { 7 | [Event("Swap")] 8 | public class SwapEventDTO : IEventDTO 9 | { 10 | [Parameter("address", "_from", 1, true)] 11 | public virtual string From { get; set; } 12 | [Parameter("address", "_to", 2, true)] 13 | public virtual string To { get; set; } 14 | [Parameter("uint256", "_value", 3, false)] 15 | public virtual BigInteger Value { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/IAPIResult.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | using System.Text.Json.Nodes; 3 | 4 | namespace Phantasma.Core 5 | { 6 | public struct ErrorResult 7 | { 8 | public string error; 9 | } 10 | 11 | public static class APIUtils 12 | { 13 | public static JsonNode FromAPIResult(object input) 14 | { 15 | return FromObject(input); 16 | } 17 | 18 | private static JsonNode FromObject(object input) 19 | { 20 | return JsonNode.Parse(JsonSerializer.Serialize(input, input.GetType())); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | 3 | os: 4 | - linux 5 | 6 | dist: trusty 7 | sudo: required 8 | 9 | mono: none 10 | dotnet: 3.1.0 11 | 12 | before_install: 13 | - cd Phantasma.Tests 14 | 15 | script: 16 | - dotnet restore 17 | - dotnet test 18 | 19 | after_success: 20 | - wget https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh 21 | - chmod +x send.sh 22 | - ./send.sh success $WEBHOOK_URL 23 | after_failure: 24 | - wget https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh 25 | - chmod +x send.sh 26 | - ./send.sh failure $WEBHOOK_URL 27 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Cryptography/Entropy.cs: -------------------------------------------------------------------------------- 1 | using Phantasma.Shared.Utils; 2 | using System; 3 | 4 | namespace Phantasma.Core 5 | { 6 | public static class Entropy 7 | { 8 | private static System.Security.Cryptography.RandomNumberGenerator rnd = System.Security.Cryptography.RandomNumberGenerator.Create(); 9 | 10 | public static byte[] GetRandomBytes(int targetLength) 11 | { 12 | var bytes = new byte[targetLength]; 13 | lock (rnd) 14 | { 15 | rnd.GetBytes(bytes); 16 | } 17 | 18 | return bytes; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Phantasma.Infrastructure/src/Pay/Phantasma.Pay.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0 4 | 40 5 | C:\code\PhantasmaSpook\Backup\Phantasma.Pay\ 6 | Current 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/types/block.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.types; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | import "tendermint/types/types.proto"; 8 | import "tendermint/types/evidence.proto"; 9 | 10 | message Block { 11 | Header header = 1 [(gogoproto.nullable) = false]; 12 | Data data = 2 [(gogoproto.nullable) = false]; 13 | tendermint.types.EvidenceList evidence = 3 [(gogoproto.nullable) = false]; 14 | Commit last_commit = 4; 15 | } 16 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/ImportNode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Phantasma.Business.Core.Nodes 5 | { 6 | public class ImportNode : CompilerNode 7 | { 8 | public string reference; 9 | 10 | public ImportNode(ModuleNode owner) : base(owner) 11 | { 12 | owner.imports.Add(this); 13 | } 14 | 15 | public override IEnumerable Nodes => Enumerable.Empty(); 16 | 17 | public override string ToString() 18 | { 19 | return base.ToString() + "=>" + this.reference; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /.github/workflows/dotnet-core.yml: -------------------------------------------------------------------------------- 1 | name: .NET Core 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Setup .NET Core 13 | uses: actions/setup-dotnet@v1 14 | with: 15 | dotnet-version: 6.0.x 16 | - name: Install dependencies 17 | run: | 18 | sudo apt-get install libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev libzstd-dev librocksdb-dev 19 | dotnet restore 20 | - name: Build 21 | run: dotnet build --configuration Release --no-restore 22 | - name: Test 23 | run: dotnet test --no-restore --verbosity normal 24 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/INativeContract.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using Phantasma.Core.Context; 3 | 4 | namespace Phantasma.Core; 5 | 6 | public interface INativeContract 7 | { 8 | string Name { get; } 9 | NativeContractKind Kind { get; } 10 | ContractInterface ABI { get; } 11 | BigInteger Order { get; } // TODO remove this? 12 | IRuntime Runtime { get; } 13 | Address Address { get; } 14 | void SetRuntime(IRuntime runtime); 15 | void LoadFromStorage(StorageContext storage); 16 | void SaveChangesToStorage(); 17 | bool HasInternalMethod(string methodName); 18 | object CallInternalMethod(IRuntime runtime, string name, object[] args); 19 | } 20 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Cryptography/Hashing/SHA256.cs: -------------------------------------------------------------------------------- 1 | using Org.BouncyCastle.Crypto.Digests; 2 | 3 | namespace Phantasma.Core.Hashing 4 | { 5 | public class SHA256 6 | { 7 | public byte[] ComputeHash(byte[] data) 8 | { 9 | return ComputeHash(data, 0, (uint)data.Length); 10 | } 11 | 12 | public byte[] ComputeHash(byte[] data, uint offset, uint length) 13 | { 14 | var digest = new Sha256Digest(); 15 | var output = new byte[digest.GetDigestSize()]; 16 | digest.BlockUpdate(data, (int)offset, (int)length); 17 | digest.DoFinal(output, 0); 18 | return output; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Tendermint.RPC/src/NodeRpcException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Tendermint.RPC 6 | { 7 | public class NodeRpcException : Exception 8 | { 9 | public Error Error { get; } 10 | 11 | public NodeRpcException(String message) : base(message) 12 | { 13 | } 14 | 15 | public NodeRpcException(String message, Error error) : base(message) 16 | { 17 | Error = error; 18 | } 19 | 20 | public NodeRpcException(String message, Exception innerException, Error error) : base(message, innerException) 21 | { 22 | Error = error; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Phantasma.Business/src/Blockchain/CustomContract.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using Phantasma.Core; 3 | using Phantasma.Shared; 4 | 5 | namespace Phantasma.Business 6 | { 7 | public sealed class CustomContract : SmartContract, ICustomContract 8 | { 9 | private string _name; 10 | public override string Name => _name; 11 | 12 | public byte[] Script { get; private set; } 13 | 14 | public CustomContract(string name, byte[] script, ContractInterface abi) : base() 15 | { 16 | Throw.IfNull(script, nameof(script)); 17 | this.Script = script; 18 | 19 | _name = name; 20 | 21 | this.ABI = abi; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/ExitNode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Phantasma.Business.Core.Nodes 5 | { 6 | public class ExitNode : StatementNode 7 | { 8 | public ExitNode(CompilerNode owner) : base(owner) 9 | { 10 | } 11 | 12 | public override List Emit(Compiler compiler) 13 | { 14 | var temp = new List(); 15 | temp.Add(new Instruction() { source = this, target = null, a = null, op = Instruction.Opcode.Return }); 16 | return temp; 17 | } 18 | 19 | public override IEnumerable Nodes => Enumerable.Empty(); 20 | } 21 | } -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/UnconfirmedTxs.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Tendermint.RPC.Endpoint 8 | { 9 | /* 10 | { 11 | "jsonrpc": "2.0", 12 | "id": "", 13 | "result": { 14 | "n_txs": "0", 15 | "txs": [] 16 | } 17 | } 18 | */ 19 | 20 | public class ResultUnconfirmedTxs : IEndpointResponse 21 | { 22 | [JsonProperty("n_txs")] 23 | public string NTxs { get; set; } 24 | 25 | [JsonExtensionData, JsonProperty("txs")] 26 | public IDictionary Txs { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/IOrganization.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public interface IOrganization 6 | { 7 | string ID { get; } 8 | string Name { get; } 9 | Address Address { get; } 10 | byte[] Script { get; } 11 | BigInteger Size { get; } // number of members 12 | 13 | bool IsMember(Address address); 14 | bool IsWitness(Transaction tx); 15 | bool MigrateMember(IRuntime Runtime, Address admin, Address from, Address to); 16 | bool AddMember(IRuntime Runtime, Address from, Address target); 17 | bool RemoveMember(IRuntime Runtime, Address from, Address target); 18 | Address[] GetMembers(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/TypeNode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Phantasma.Business.Core.Nodes 5 | { 6 | 7 | public enum TypeKind 8 | { 9 | Unknown, 10 | Void, 11 | String, 12 | Integer, 13 | Float, 14 | Boolean, 15 | ByteArray, 16 | Struct, 17 | } 18 | 19 | public class TypeNode: CompilerNode 20 | { 21 | public TypeKind Kind; 22 | 23 | public TypeNode(CompilerNode owner, TypeKind kind) : base(owner) 24 | { 25 | this.Kind = kind; 26 | } 27 | 28 | public override IEnumerable Nodes => Enumerable.Empty(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/IOracleReader.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using System.Collections.Generic; 3 | using Phantasma.Shared.Types; 4 | 5 | namespace Phantasma.Core; 6 | 7 | public interface IOracleReader 8 | { 9 | BigInteger ProtocolVersion { get; } 10 | IEnumerable Entries { get; } 11 | string GetCurrentHeight(string platformName, string chainName); 12 | void SetCurrentHeight(string platformName, string chainName, string height); 13 | List ReadAllBlocks(string platformName, string chainName); 14 | T Read(Timestamp time, string url) where T : class; 15 | InteropTransaction ReadTransaction(string platform, string chain, Hash hash); 16 | void Clear(); 17 | void MergeTxData(); 18 | } 19 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/CallNode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Phantasma.Business.Core.Nodes 5 | { 6 | public class CallNode: StatementNode 7 | { 8 | public MethodNode method; 9 | 10 | public CallNode(CompilerNode owner) : base(owner) 11 | { 12 | } 13 | 14 | public override IEnumerable Nodes => Enumerable.Empty(); 15 | 16 | public override List Emit(Compiler compiler) 17 | { 18 | var temp = new List(); 19 | temp.Add(new Instruction() { source = this, target = method.name, op = Instruction.Opcode.Call }); 20 | return temp; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/WhileNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Phantasma.Business.Core.Nodes 5 | { 6 | public class WhileNode : StatementNode 7 | { 8 | public ExpressionNode expr; 9 | public StatementNode body; 10 | 11 | public WhileNode(BlockNode owner) : base(owner) 12 | { 13 | } 14 | 15 | public override IEnumerable Nodes 16 | { 17 | get 18 | { 19 | yield return expr; 20 | yield return body; 21 | } 22 | } 23 | 24 | public override List Emit(Compiler compiler) 25 | { 26 | throw new NotImplementedException(); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/ParameterNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Phantasma.Business.Core.Nodes 5 | { 6 | public class ParameterNode : CompilerNode 7 | { 8 | public DeclarationNode decl; 9 | 10 | public ParameterNode(MethodNode owner) : base(owner) 11 | { 12 | owner.parameters.Add(this); 13 | } 14 | 15 | public override string ToString() 16 | { 17 | return base.ToString() + "=>" + this.decl.ToString(); 18 | } 19 | 20 | public override IEnumerable Nodes 21 | { 22 | get 23 | { 24 | yield return decl; 25 | yield break; 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/ExecutionContext.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public abstract class ExecutionContext 6 | { 7 | public abstract string Name { get; } 8 | 9 | private Address _address; 10 | public Address Address { 11 | get 12 | { 13 | if (_address.IsNull) 14 | { 15 | _address = Address.FromHash(Name); 16 | } 17 | 18 | return _address; 19 | } 20 | } 21 | 22 | public abstract ExecutionState Execute(ExecutionFrame frame, Stack stack); 23 | 24 | public override string ToString() 25 | { 26 | return Name; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/StatementNode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Phantasma.Business.Core.Nodes 4 | { 5 | public abstract class StatementNode : CompilerNode 6 | { 7 | public StatementNode(CompilerNode owner) : base(owner) 8 | { 9 | } 10 | 11 | public abstract List Emit(Compiler compiler); 12 | 13 | public MethodNode FindParentMethod() 14 | { 15 | var node = Owner; 16 | while (node != null) 17 | { 18 | if (node is MethodNode) 19 | { 20 | return (MethodNode)node; 21 | } 22 | 23 | node = node.Owner; 24 | } 25 | 26 | return null; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Phantasma.Core/src/Utils/StreamUtils.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public static class StreamExtensions 6 | { 7 | public static uint ReadUInt24(this BinaryReader reader) 8 | { 9 | var b1 = reader.ReadByte(); 10 | var b2 = reader.ReadByte(); 11 | var b3 = reader.ReadByte(); 12 | return 13 | (((uint)b1) << 16) | 14 | (((uint)b2) << 8) | 15 | ((uint)b3); 16 | } 17 | 18 | public static void WriteUInt24(this BinaryWriter writer, uint val) 19 | { 20 | writer.Write((byte)((val >> 16) & 0xFF)); 21 | writer.Write((byte)((val >> 8) & 0xFF)); 22 | writer.Write((byte)(val & 0xFF)); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/mempool/message.go: -------------------------------------------------------------------------------- 1 | package mempool 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/gogo/protobuf/proto" 7 | ) 8 | 9 | // Wrap implements the p2p Wrapper interface and wraps a mempool message. 10 | func (m *Message) Wrap(pb proto.Message) error { 11 | switch msg := pb.(type) { 12 | case *Txs: 13 | m.Sum = &Message_Txs{Txs: msg} 14 | 15 | default: 16 | return fmt.Errorf("unknown message: %T", msg) 17 | } 18 | 19 | return nil 20 | } 21 | 22 | // Unwrap implements the p2p Wrapper interface and unwraps a wrapped mempool 23 | // message. 24 | func (m *Message) Unwrap() (proto.Message, error) { 25 | switch msg := m.Sum.(type) { 26 | case *Message_Txs: 27 | return m.GetTxs(), nil 28 | 29 | default: 30 | return nil, fmt.Errorf("unknown message: %T", msg) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Phantasma.Business/src/Phantasma.Business.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0 4 | disable 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Phantasma.Core/tests/Phantasma.Core.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | all 12 | runtime; build; native; contentfiles; analyzers; buildtransitive 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/ClassNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Phantasma.Business.Core.Nodes 5 | { 6 | public class ClassNode : CompilerNode 7 | { 8 | public string name; 9 | public string parent; 10 | public bool isAbstract; 11 | public bool isStatic; 12 | public Visibility visibility; 13 | 14 | public List methods = new List(); 15 | 16 | public ClassNode(ModuleNode owner) : base(owner) 17 | { 18 | owner.classes.Add(this); 19 | } 20 | 21 | public override IEnumerable Nodes => methods; 22 | 23 | public override string ToString() 24 | { 25 | return base.ToString() + "=>" + this.name; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Phantasma.Infrastructure/src/API/Controllers/ValidatorController.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Phantasma.Core; 4 | 5 | namespace Phantasma.Infrastructure.Controllers 6 | { 7 | public class ValidatorController : BaseControllerV1 8 | { 9 | [APIInfo(typeof(ValidatorResult[]), "Returns an array of available validators.", false, 300)] 10 | [HttpGet("GetValidators")] 11 | public ValidatorResult[] GetValidators() 12 | { 13 | var nexus = NexusAPI.GetNexus(); 14 | 15 | var validators = nexus.GetValidators(). 16 | Where(x => !x.address.IsNull). 17 | Select(x => new ValidatorResult() { address = x.address.ToString(), type = x.type.ToString() }); 18 | 19 | return validators.ToArray(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/p2p/conn.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.p2p; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/p2p"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | import "tendermint/crypto/keys.proto"; 8 | 9 | message PacketPing {} 10 | 11 | message PacketPong {} 12 | 13 | message PacketMsg { 14 | int32 channel_id = 1 [(gogoproto.customname) = "ChannelID"]; 15 | bool eof = 2 [(gogoproto.customname) = "EOF"]; 16 | bytes data = 3; 17 | } 18 | 19 | message Packet { 20 | oneof sum { 21 | PacketPing packet_ping = 1; 22 | PacketPong packet_pong = 2; 23 | PacketMsg packet_msg = 3; 24 | } 25 | } 26 | 27 | message AuthSigMessage { 28 | tendermint.crypto.PublicKey pub_key = 1 [(gogoproto.nullable) = false]; 29 | bytes sig = 2; 30 | } 31 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/RpcRequest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Tendermint.RPC 7 | { 8 | public class RpcRequest 9 | { 10 | /* 11 | { 12 | "method": "broadcast_tx_sync", 13 | "jsonrpc": "2.0", 14 | "params": [ 15 | "abc" 16 | ], 17 | "id": "dontcare" 18 | } 19 | */ 20 | 21 | [JsonProperty("method")] 22 | public string Method { get; set; } 23 | 24 | [JsonProperty("jsonrpc")] 25 | public string JsonRpc { get; set; } 26 | 27 | [JsonProperty("params")] 28 | public List Params { get; set; } 29 | 30 | [JsonProperty("id")] 31 | public string Id { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Tendermint/Extensions/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Google.Protobuf; 4 | 5 | namespace Types.Extensions 6 | { 7 | public static class StringExtensions 8 | { 9 | public static ByteString ToByteString(this string input) 10 | { 11 | var base64String = Convert.ToBase64String(Encoding.UTF8.GetBytes(input)); 12 | return ByteString.FromBase64(base64String); 13 | } 14 | 15 | // https://stackoverflow.com/a/311179/959687 16 | public static byte[] StringToByteArray(this string hex) 17 | { 18 | var numberChars = hex.Length; 19 | var bytes = new byte[numberChars / 2]; 20 | for (var i = 0; i < numberChars; i += 2) 21 | bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16); 22 | return bytes; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/types/validator.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.types; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | import "tendermint/crypto/keys.proto"; 8 | 9 | message ValidatorSet { 10 | repeated Validator validators = 1; 11 | Validator proposer = 2; 12 | int64 total_voting_power = 3; 13 | } 14 | 15 | message Validator { 16 | bytes address = 1; 17 | tendermint.crypto.PublicKey pub_key = 2 [(gogoproto.nullable) = false]; 18 | int64 voting_power = 3; 19 | int64 proposer_priority = 4; 20 | } 21 | 22 | message SimpleValidator { 23 | tendermint.crypto.PublicKey pub_key = 1; 24 | int64 voting_power = 2; 25 | } 26 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/JsonNetSerializer.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using RestSharp; 3 | using RestSharp.Serialization; 4 | 5 | namespace Tendermint.RPC 6 | { 7 | public class JsonNetSerializer : IRestSerializer 8 | { 9 | public string Serialize(object obj) => JsonConvert.SerializeObject(obj); 10 | 11 | public string Serialize(Parameter parameter) => JsonConvert.SerializeObject(parameter.Value); 12 | 13 | public T Deserialize(IRestResponse response) => JsonConvert.DeserializeObject(response.Content); 14 | 15 | public string[] SupportedContentTypes { get; } = 16 | { 17 | "application/json", "text/json", "text/x-json", "text/javascript", "*+json" 18 | }; 19 | 20 | public string ContentType { get; set; } = "application/json"; 21 | 22 | public DataFormat DataFormat { get; } = DataFormat.Json; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm --force -r .vs 4 | rm --force -r Phantasma.Business/src/bin 5 | rm --force -r Phantasma.Business/src/obj 6 | rm --force -r Phantasma.Core/src/bin 7 | rm --force -r Phantasma.Core/src/obj 8 | rm --force -r Phantasma.Core.Tests/bin 9 | rm --force -r Phantasma.Core.Tests/obj 10 | rm --force -r Phantasma.Infrastructure/src/bin 11 | rm --force -r Phantasma.Infrastructure/src/obj 12 | rm --force -r Phantasma.Shared/src/bin 13 | rm --force -r Phantasma.Shared/src/obj 14 | rm --force -r Phantasma.Node/bin 15 | rm --force -r Phantasma.Node/obj 16 | rm --force -r Phantasma.Tests/bin 17 | rm --force -r Phantasma.Tests/obj 18 | rm --force -r Phantasma.Tests/Phantasma.Simulator/bin 19 | rm --force -r Phantasma.Tests/Phantasma.Simulator/obj 20 | rm --force -r Tendermint/bin 21 | rm --force -r Tendermint/obj 22 | rm --force -r Tendermint.RPC/bin 23 | rm --force -r Tendermint.RPC/obj 24 | 25 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/rpc/grpc/types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.rpc.grpc; 3 | option go_package = "github.com/tendermint/tendermint/rpc/grpc;coregrpc"; 4 | 5 | import "tendermint/abci/types.proto"; 6 | 7 | //---------------------------------------- 8 | // Request types 9 | 10 | message RequestPing {} 11 | 12 | message RequestBroadcastTx { 13 | bytes tx = 1; 14 | } 15 | 16 | //---------------------------------------- 17 | // Response types 18 | 19 | message ResponsePing {} 20 | 21 | message ResponseBroadcastTx { 22 | tendermint.abci.ResponseCheckTx check_tx = 1; 23 | tendermint.abci.ResponseDeliverTx deliver_tx = 2; 24 | } 25 | 26 | //---------------------------------------- 27 | // Service Definition 28 | 29 | service BroadcastAPI { 30 | rpc Ping(RequestPing) returns (ResponsePing); 31 | rpc BroadcastTx(RequestBroadcastTx) returns (ResponseBroadcastTx); 32 | } 33 | -------------------------------------------------------------------------------- /Phantasma.Business/tests/Phantasma.Business.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | all 12 | runtime; build; native; contentfiles; analyzers; buildtransitive 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Phantasma.Shared/src/Utils/ByteArrayComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Phantasma.Shared.Utils 6 | { 7 | public class ByteArrayComparer : IEqualityComparer 8 | { 9 | public bool Equals(byte[] left, byte[] right) 10 | { 11 | return left.CompareBytes(right); 12 | } 13 | 14 | public int GetHashCode(byte[] key) 15 | { 16 | Throw.IfNull(key, nameof(key)); 17 | unchecked // disable overflow, for the unlikely possibility that you 18 | { // are compiling with overflow-checking enabled 19 | int hash = 27; 20 | for (int i=0; i(); 13 | 14 | var nexus = NexusAPI.GetNexus(); 15 | 16 | var chains = nexus.GetChains(nexus.RootStorage); 17 | foreach (var chainName in chains) 18 | { 19 | var chain = nexus.GetChainByName(chainName); 20 | var single = NexusAPI.FillChain(chain); 21 | objs.Add(single); 22 | } 23 | 24 | return objs.ToArray(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Phantasma.Business/tests/Blockchain/TransactionTest.cs: -------------------------------------------------------------------------------- 1 | using Phantasma.Core; 2 | using Shouldly; 3 | using System.Text.Json.Nodes; 4 | using System.Collections.Generic; 5 | using Xunit; 6 | using static Phantasma.Core.WalletLink; 7 | 8 | namespace Phantasma.Business.Tests 9 | { 10 | public class TransactionTest 11 | { 12 | [Fact] 13 | public void null_transaction_test() 14 | { 15 | var transaction = new Phantasma.Core.Transaction(); 16 | transaction.NexusName.ShouldBe(null); 17 | transaction.ChainName.ShouldBe(null); 18 | transaction.Hash.ShouldBeOfType(); 19 | transaction.HasSignatures.ShouldBe(false); 20 | transaction.Signatures.ShouldBe(null); 21 | transaction.Script.ShouldBe(null); 22 | transaction.Payload.ShouldBe(null); 23 | } 24 | 25 | [Fact] 26 | public void is_signed_by() 27 | { 28 | 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/IArchive.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System.Numerics; 4 | using Phantasma.Shared.Types; 5 | 6 | namespace Phantasma.Core; 7 | 8 | public interface IArchive 9 | { 10 | string Name { get; } 11 | Hash Hash { get; } 12 | MerkleTree MerkleTree { get; } 13 | BigInteger Size { get; } 14 | Timestamp Time { get; } 15 | IArchiveEncryption Encryption { get; } 16 | BigInteger BlockCount { get; } 17 | IEnumerable
Owners { get; } 18 | int OwnerCount { get; } 19 | IEnumerable MissingBlockIndices { get; } 20 | int MissingBlockCount { get; } 21 | IEnumerable BlockHashes { get; } 22 | void SerializeData(BinaryWriter writer); 23 | byte[] ToByteArray(); 24 | void UnserializeData(BinaryReader reader); 25 | void AddOwner(Address address); 26 | void RemoveOwner(Address address); 27 | bool IsOwner(Address address); 28 | void AddMissingBlock(int blockIndex); 29 | } 30 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/p2p/pex.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.p2p; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/p2p"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | 8 | message PexAddress { 9 | string id = 1 [(gogoproto.customname) = "ID"]; 10 | string ip = 2 [(gogoproto.customname) = "IP"]; 11 | uint32 port = 3; 12 | } 13 | 14 | message PexRequest {} 15 | 16 | message PexResponse { 17 | repeated PexAddress addresses = 1 [(gogoproto.nullable) = false]; 18 | } 19 | 20 | message PexAddressV2 { 21 | string url = 1 [(gogoproto.customname) = "URL"]; 22 | } 23 | 24 | message PexRequestV2 {} 25 | 26 | message PexResponseV2 { 27 | repeated PexAddressV2 addresses = 1 [(gogoproto.nullable) = false]; 28 | } 29 | 30 | message PexMessage { 31 | oneof sum { 32 | PexRequest pex_request = 1; 33 | PexResponse pex_response = 2; 34 | PexRequestV2 pex_request_v2 = 3; 35 | PexResponseV2 pex_response_v2 = 4; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Phantasma.Node/Hosting/EventBusBackgroundService.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | using Foundatio.Extensions.Hosting.Startup; 4 | using Phantasma.Node.Events; 5 | using Microsoft.Extensions.Hosting; 6 | 7 | namespace Phantasma.Node.Hosting; 8 | 9 | public class EventBusBackgroundService : BackgroundService 10 | { 11 | private readonly IEventBus _bus; 12 | private readonly StartupActionsContext _startupContext; 13 | 14 | public EventBusBackgroundService( 15 | IEventBus bus, 16 | StartupActionsContext startupContext 17 | ) 18 | { 19 | _bus = bus; 20 | _startupContext = startupContext; 21 | } 22 | 23 | protected override async Task ExecuteAsync( 24 | CancellationToken stoppingToken 25 | ) 26 | { 27 | if (_startupContext != null) 28 | { 29 | await _startupContext.WaitForStartupAsync(stoppingToken); 30 | } 31 | 32 | await _bus.Run(stoppingToken); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Phantasma.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0 4 | disable 5 | 6 | 7 | true 8 | 9 | 10 | true 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/Blockchain.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Tendermint.RPC.Endpoint 7 | { 8 | /* 9 | Get block headers for minHeight <= height <= maxHeight. Block headers are returned in descending order (highest first). Query Parameters 10 | Parameter Type Default Required Description 11 | minHeight int64 false true height of blockchain 12 | maxHeight int64 false true height of blockchain 13 | 14 | Return Type: List of blocks 15 | 16 | type ResultBlockchainInfo struct { 17 | LastHeight int64 18 | BlockMetas []*types.BlockMeta 19 | } 20 | */ 21 | 22 | public class ResultBlockchainInfo : IEndpointResponse 23 | { 24 | [JsonProperty("last_height")] 25 | public string LastHeight { get; set; } 26 | 27 | [JsonProperty("block_metas")] 28 | public List BlockMetas { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Tendermint/Tendermint.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0 4 | 5 | 6 | 7 | 8 | 9 | 10 | 22 | 23 | -------------------------------------------------------------------------------- /Tendermint.RPC/Tendermint.RPC.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0 4 | 5 | 6 | 7 | 8 | 9 | 10 | 22 | 23 | -------------------------------------------------------------------------------- /Phantasma.Infrastructure/src/API/Controllers/OrganizationController.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace Phantasma.Infrastructure.Controllers 5 | { 6 | public class OrganizationController : BaseControllerV1 7 | { 8 | [APIInfo(typeof(OrganizationResult), "Returns info about an organization.", false, 60)] 9 | [HttpGet("GetOrganization")] 10 | public OrganizationResult GetOrganization(string ID) 11 | { 12 | var nexus = NexusAPI.GetNexus(); 13 | 14 | if (!nexus.OrganizationExists(nexus.RootStorage, ID)) 15 | { 16 | throw new APIException("invalid organization"); 17 | } 18 | 19 | var org = nexus.GetOrganizationByName(nexus.RootStorage, ID); 20 | var members = org.GetMembers(); 21 | 22 | return new OrganizationResult() 23 | { 24 | id = ID, 25 | name = org.Name, 26 | members = members.Select(x => x.Text).ToArray(), 27 | }; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Phantasma.Node/Converters/EnumerableJsonConverterFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Text.Json; 5 | using System.Text.Json.Serialization; 6 | 7 | namespace Phantasma.Node.Converters; 8 | 9 | public class EnumerableJsonConverterFactory : JsonConverterFactory 10 | { 11 | public override bool CanConvert(Type typeToConvert) 12 | { 13 | if (!typeToConvert.IsGenericType) return false; 14 | 15 | var realType = typeToConvert.GetGenericTypeDefinition(); 16 | 17 | return realType.IsAssignableTo(typeof(IEnumerable<>)); 18 | } 19 | 20 | public override JsonConverter CreateConverter(Type type, JsonSerializerOptions options) 21 | { 22 | var valueType = type.GetGenericArguments()[0]; 23 | 24 | var converter = (JsonConverter)Activator.CreateInstance( 25 | typeof(EnumerableJsonConverter<>).MakeGenericType(valueType), BindingFlags.Instance | BindingFlags.Public, 26 | null, new object[] { options }, null); 27 | 28 | return converter; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Phantasma.Tests/Phantasma.Neo/Utils/LuxUtils.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using Phantasma.Neo.Utils; 3 | 4 | // Testing methods: 5 | // bool IsValidAddress(this string address) 6 | 7 | namespace Phantasma.Tests 8 | { 9 | [TestClass] 10 | public class PhantasmaNeoUtilsTests 11 | { 12 | [TestMethod] 13 | public void IsValidAddressTest() 14 | { 15 | // Checking valid address 16 | Assert.IsTrue("AP6ZkjweW4NGskMca2KH2cchNJbFWW2vZe".IsValidAddress()); 17 | 18 | // Checking invalid address 19 | Assert.IsFalse("AP6ZkjweW4NGskMca2KH2cchNJbFWW2vZee".IsValidAddress()); 20 | 21 | // Checking invalid address 22 | Assert.IsFalse("AP6ZkjweW4NGskMca2KH2cchNJbFWW2vZ".IsValidAddress()); 23 | 24 | // Checking invalid address 25 | Assert.IsFalse("AP6ZkjweW4NGskMca2KH2cchNJbFWW2vZE".IsValidAddress()); 26 | 27 | // Checking invalid address 28 | Assert.IsFalse("AP6ZkjweW4NGskMca2KH2cchNJbFWW2lOI".IsValidAddress()); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/crypto/proof.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.crypto; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/crypto"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | 8 | message Proof { 9 | int64 total = 1; 10 | int64 index = 2; 11 | bytes leaf_hash = 3; 12 | repeated bytes aunts = 4; 13 | } 14 | 15 | message ValueOp { 16 | // Encoded in ProofOp.Key. 17 | bytes key = 1; 18 | 19 | // To encode in ProofOp.Data 20 | Proof proof = 2; 21 | } 22 | 23 | message DominoOp { 24 | string key = 1; 25 | string input = 2; 26 | string output = 3; 27 | } 28 | 29 | // ProofOp defines an operation used for calculating Merkle root 30 | // The data could be arbitrary format, providing nessecary data 31 | // for example neighbouring node hash 32 | message ProofOp { 33 | string type = 1; 34 | bytes key = 2; 35 | bytes data = 3; 36 | } 37 | 38 | // ProofOps is Merkle proof defined by the list of ProofOps 39 | message ProofOps { 40 | repeated ProofOp ops = 1 [(gogoproto.nullable) = false]; 41 | } 42 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/consensus/message_test.go: -------------------------------------------------------------------------------- 1 | package consensus_test 2 | 3 | import ( 4 | "encoding/hex" 5 | "math" 6 | "testing" 7 | 8 | "github.com/gogo/protobuf/proto" 9 | "github.com/stretchr/testify/require" 10 | 11 | tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus" 12 | tmproto "github.com/tendermint/tendermint/proto/tendermint/types" 13 | ) 14 | 15 | func TestHasVoteVector(t *testing.T) { 16 | testCases := []struct { 17 | msg tmcons.HasVote 18 | expBytes string 19 | }{ 20 | {tmcons.HasVote{1, 3, tmproto.PrevoteType, 1}, "3a080801100318012001"}, 21 | {tmcons.HasVote{2, 2, tmproto.PrecommitType, 2}, "3a080802100218022002"}, 22 | {tmcons.HasVote{math.MaxInt64, math.MaxInt32, tmproto.ProposalType, math.MaxInt32}, 23 | "3a1808ffffffffffffffff7f10ffffffff07182020ffffffff07"}, 24 | } 25 | 26 | for i, tc := range testCases { 27 | msg := tmcons.Message{&tmcons.Message_HasVote{HasVote: &tc.msg}} 28 | bz, err := proto.Marshal(&msg) 29 | require.NoError(t, err) 30 | require.Equal(t, tc.expBytes, hex.EncodeToString(bz), "test vector failed", i) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Phantasma.Business/tests/Blockchain/BlockTest.cs: -------------------------------------------------------------------------------- 1 | using Phantasma.Core; 2 | using Shouldly; 3 | using System.Text.Json.Nodes; 4 | using System.Collections.Generic; 5 | using Phantasma.Shared.Types; 6 | using Xunit; 7 | using static Phantasma.Core.WalletLink; 8 | 9 | namespace Phantasma.Business.Tests 10 | { 11 | public class BlockTest 12 | { 13 | [Fact] 14 | public void null_block_test() 15 | { 16 | var block = new Block(); 17 | block.Timestamp.ShouldBe(Timestamp.Null); 18 | block.Payload.ShouldBe(null); 19 | block.Events.ShouldBe(new List()); 20 | block.OracleData.ShouldBe(new OracleEntry[0]); 21 | block.TransactionCount.ShouldBe(0); 22 | // TODO: Need to check transactions to be null 23 | //block.PreviousHash.ShouldBeNull(Hash.Null); 24 | block.TransactionHashes.ShouldBe(new Hash[0]); 25 | block.Height.ShouldBe(0); 26 | block.ChainAddress.ShouldBe(Address.Null); 27 | block.Validator.ShouldBe(Address.Null); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/DeclarationNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace Phantasma.Business.Core.Nodes 6 | { 7 | public class DeclarationNode : CompilerNode 8 | { 9 | public string identifier; 10 | public TypeNode type; 11 | 12 | public DeclarationNode(CompilerNode owner) : base(owner) 13 | { 14 | if (owner is BlockNode) 15 | { 16 | ((BlockNode)owner).declarations.Add(this); 17 | } 18 | else 19 | if (owner is ParameterNode) 20 | { 21 | ((ParameterNode)owner).decl = this; 22 | } 23 | else 24 | { 25 | throw new Exception("Invalid owner"); 26 | } 27 | } 28 | 29 | public override IEnumerable Nodes => Enumerable.Empty(); 30 | 31 | public override string ToString() 32 | { 33 | return base.ToString() + "=>" + this.identifier+"/"+this.type.Kind; 34 | } 35 | 36 | } 37 | } -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/AssignmentNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Phantasma.Business.Core.Nodes 6 | { 7 | public class AssignmentNode : StatementNode 8 | { 9 | public string identifier; 10 | public ExpressionNode expr; 11 | 12 | public AssignmentNode(CompilerNode owner) : base(owner) 13 | { 14 | } 15 | 16 | public override IEnumerable Nodes 17 | { 18 | get 19 | { 20 | yield return expr; 21 | yield break; 22 | } 23 | } 24 | 25 | public override string ToString() 26 | { 27 | return base.ToString() + "=>" + this.identifier; 28 | } 29 | 30 | public override List Emit(Compiler compiler) 31 | { 32 | var temp = expr.Emit(compiler); 33 | temp.Add(new Instruction() { source = this, target = this.identifier, a = temp.Last(), op = Instruction.Opcode.Assign}); 34 | return temp; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/ConsensusParams.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Tendermint.RPC.Endpoint 7 | { 8 | /* 9 | { 10 | "jsonrpc": "2.0", 11 | "id": "", 12 | "result": { 13 | "block_height": "10779111", 14 | "consensus_params": { 15 | "block_size": { 16 | "max_bytes": "1048576", 17 | "max_gas": "-1" 18 | }, 19 | "evidence": { 20 | "max_age": "100000" 21 | }, 22 | "validator": { 23 | "pub_key_types": [ 24 | "ed25519" 25 | ] 26 | } 27 | } 28 | } 29 | } 30 | */ 31 | 32 | public class ResultConsensusParams : IEndpointResponse 33 | { 34 | [JsonProperty("block_height")] 35 | public string BlockHeight { get; set; } 36 | 37 | [JsonProperty("consensus_params")] 38 | public ConsensusParams ConsensusParams { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/BroadcastTxAsync.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Tendermint.RPC.Endpoint 6 | { 7 | /* 8 | BroadcastTxAsync 9 | 10 | This method just return transaction hash right away and there is no return from CheckTx or DeliverTx. Transaction Parameters 11 | Parameter Type Default Required Description 12 | tx Tx nil true The transaction info bytes in hex 13 | 14 | Return Parameters Checktx Result 15 | 16 | type ResultBroadcastTx struct { 17 | Code uint32 18 | Data cmn.HexBytes 19 | Log string 20 | Hash cmn.HexBytes 21 | } 22 | */ 23 | 24 | /* 25 | { 26 | "error": "", 27 | "result": { 28 | "hash": "721B67C1772EA5FC7E80D70DEAA3C52034204FC60C057FF1117EE45468C1A980", 29 | "log": "", 30 | "data": "", 31 | "code": "0" 32 | }, 33 | "id": "", 34 | "jsonrpc": "2.0" 35 | 36 | } 37 | */ 38 | } 39 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-server.yml: -------------------------------------------------------------------------------- 1 | name: Deploy Testnet 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | build: 8 | 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v3 13 | 14 | - name: Copy Files via scp 15 | uses: appleboy/scp-action@master 16 | with: 17 | host: ${{ secrets.HOST }} 18 | port: ${{ secrets.PORT }} 19 | username: ${{ secrets.USERNAME }} 20 | key: ${{ secrets.SSHKEY }} 21 | passphrase: ${{ secrets.PASSPHRASE }} 22 | source: "./" 23 | target: ${{ secrets.FOLDER }} 24 | 25 | - name: Building Docker in the server 26 | uses: appleboy/ssh-action@master 27 | with: 28 | host: ${{ secrets.HOST }} 29 | port: ${{ secrets.PORT }} 30 | username: ${{ secrets.USERNAME }} 31 | key: ${{ secrets.SSHKEY }} 32 | passphrase: ${{ secrets.PASSPHRASE }} 33 | script: | 34 | cd ${{ secrets.FOLDER }} 35 | echo ${{ secrets.PASS }} | sudo -S chmod u+x ./testnet_startup.sh; 36 | echo ${{ secrets.PASS }} | sudo -S ./testnet_startup.sh; 37 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/TransactionResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Phantasma.Core; 4 | 5 | namespace Phantasma.Core; 6 | 7 | public class TransactionResult 8 | { 9 | public Hash Hash{ get; set; } 10 | 11 | public uint Code { get; set; } 12 | 13 | public VMObject Result { get; set; } 14 | 15 | public string Log { get; set; } 16 | 17 | public string Info { get; set; } 18 | 19 | public long Gas { get; set; } 20 | 21 | public long GasUsed { get; set; } 22 | 23 | public Event[] Events { get; set; } 24 | 25 | public string Codespace { get; set; } 26 | 27 | 28 | public TransactionResult() {} 29 | public TransactionResult(uint code, VMObject result, string log, string info, long gas, long gasUsed, IEnumerable events, 30 | string codespace) 31 | { 32 | this.Code = code; 33 | this.Result = result; 34 | this.Log = log; 35 | this.Info = info; 36 | this.Gas = gas; 37 | this.GasUsed = gasUsed; 38 | this.Events = events.ToArray(); 39 | this.Codespace = codespace; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Phantasma.Node/DeliverTxResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Phantasma.Core; 4 | 5 | namespace Phantasma.Business; 6 | public class DeliverTxResult 7 | { 8 | public Hash Hash { get; set; } 9 | public uint Code { get; set; } 10 | 11 | public byte[] Result { get; set; } 12 | 13 | public string Log { get; set; } 14 | 15 | public string Info { get; set; } 16 | 17 | public long Gas { get; set; } 18 | 19 | public long GasUsed { get; set; } 20 | 21 | public Event[] Events { get; set; } 22 | 23 | public string Codespace { get; set; } 24 | 25 | 26 | public DeliverTxResult() {} 27 | public DeliverTxResult(uint code, byte[] result, string log, string info, long gas, long gasUsed, IEnumerable events, 28 | string codespace) 29 | { 30 | this.Code = code; 31 | this.Result = result; 32 | this.Log = log; 33 | this.Info = info; 34 | this.Gas = gas; 35 | this.GasUsed = gasUsed; 36 | this.Events = events.ToArray(); 37 | this.Codespace = codespace; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Phantasma.Tests/WalletTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using Phantasma.Blockchain; 3 | using Phantasma.Cryptography; 4 | using Phantasma.Domain; 5 | using Phantasma.Numerics; 6 | using Phantasma.VM.Utils; 7 | using System.Linq; 8 | 9 | namespace Phantasma.Tests 10 | { 11 | [TestClass] 12 | public class WalletTests 13 | { 14 | [TestMethod] 15 | public void TransferScriptMethodExtraction() 16 | { 17 | var source = PhantasmaKeys.Generate(); 18 | var dest = PhantasmaKeys.Generate(); 19 | var amount = UnitConversion.GetUnitValue(DomainSettings.StakingTokenDecimals); 20 | var script = ScriptUtils.BeginScript().AllowGas(source.Address, Address.Null, 1, 999).TransferTokens(DomainSettings.StakingTokenSymbol, source.Address, dest.Address, amount).SpendGas(source.Address).EndScript(); 21 | 22 | var table = DisasmUtils.GetDefaultDisasmTable(); 23 | var methods = DisasmUtils.ExtractMethodCalls(script, table); 24 | 25 | Assert.IsTrue(methods != null && methods.Count() == 3); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Tendermint/Extensions/ByteStringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | using Google.Protobuf; 5 | 6 | namespace Types.Extensions 7 | { 8 | public static class ByteStringExtensions 9 | { 10 | public static int ToInt(this ByteString value) 11 | { 12 | var originalByteArray = value.ToByteArray(); 13 | var byteArray = Enumerable 14 | .Repeat(0, 4 - originalByteArray.Length) 15 | .Concat(originalByteArray) 16 | .ToArray(); 17 | 18 | if (BitConverter.IsLittleEndian) 19 | { 20 | Array.Reverse(byteArray); 21 | } 22 | 23 | return BitConverter.ToInt32(byteArray, 0); 24 | } 25 | 26 | public static string ToStringSafe(this ByteString value) 27 | { 28 | var byteArray = value.ToByteArray(); 29 | var utf8String = Encoding.UTF8.GetString(byteArray); 30 | var decodedByteArray = Convert.FromBase64String(utf8String); 31 | return Encoding.UTF8.GetString(decodedByteArray); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/ExecutionFrame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public class ExecutionFrame 6 | { 7 | public VMObject[] Registers { get; } 8 | 9 | public uint Offset { get; } // current instruction pointer **before** the frame was entered 10 | public ExecutionContext Context { get; } 11 | public IVirtualMachine VM { get; } 12 | 13 | public ExecutionFrame(IVirtualMachine VM, uint offset, ExecutionContext context, int registerCount) 14 | { 15 | this.VM = VM; 16 | this.Offset = offset; 17 | this.Context = context; 18 | 19 | Registers = new VMObject[registerCount]; 20 | 21 | for (int i = 0; i < registerCount; i++) 22 | { 23 | Registers[i] = new VMObject(); 24 | } 25 | } 26 | 27 | public VMObject GetRegister(int index) 28 | { 29 | if (index < 0 || index >= Registers.Length) 30 | { 31 | throw new ArgumentException("Invalid index"); 32 | } 33 | 34 | return Registers[index]; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/OracleEntry.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public struct OracleEntry 6 | { 7 | public string URL { get; private set; } 8 | public byte[] Content { get; private set; } 9 | 10 | public OracleEntry(string url, byte[] content) 11 | { 12 | URL = url; 13 | Content = content; 14 | } 15 | 16 | public override bool Equals(object obj) 17 | { 18 | if (!(obj is OracleEntry)) 19 | { 20 | return false; 21 | } 22 | 23 | var entry = (OracleEntry)obj; 24 | return URL == entry.URL && 25 | EqualityComparer.Default.Equals(Content, entry.Content); 26 | } 27 | 28 | public override int GetHashCode() 29 | { 30 | var hashCode = 1993480784; 31 | hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(URL); 32 | hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Content); 33 | return hashCode; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/NumUnconfirmedTxs.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Tendermint.RPC.Endpoint 8 | { 9 | /* 10 | Get number of unconfirmed transactions. Query Parameters 11 | Parameter Type Default Required Description 12 | limit int 30 false Maximum number of entries (max: 100) 13 | 14 | Return Parameters 15 | 16 | // List of mempool txs 17 | type ResultUnconfirmedTxs struct { 18 | N int 19 | Txs []types.Tx 20 | } 21 | */ 22 | 23 | /* 24 | { 25 | "jsonrpc": "2.0", 26 | "id": "", 27 | "result": { 28 | "n_txs": "0", 29 | "txs": null 30 | } 31 | } 32 | */ 33 | 34 | public class ResultNumUnconfirmedTxs : IEndpointResponse 35 | { 36 | [JsonProperty("n_txs")] 37 | public string NTxs { get; set; } 38 | 39 | [JsonExtensionData, JsonProperty("txs")] 40 | public IDictionary Txs { get; set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Cryptography/Signature.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | 4 | namespace Phantasma.Core 5 | { 6 | public abstract class Signature: ISerializable 7 | { 8 | public abstract SignatureKind Kind { get; } 9 | 10 | public abstract void SerializeData(BinaryWriter writer); 11 | public abstract void UnserializeData(BinaryReader reader); 12 | 13 | /// 14 | /// Checks if this transaction was signed by at least one of the addresses 15 | /// 16 | public abstract bool Verify(byte[] message, IEnumerable
addresses); 17 | 18 | public bool Verify(byte[] message, Address address) 19 | { 20 | return Verify(message, new Address[] { address }); 21 | } 22 | 23 | public byte[] ToByteArray() 24 | { 25 | using (var stream = new MemoryStream()) 26 | { 27 | using (var writer = new BinaryWriter(stream)) 28 | { 29 | this.SerializeData(writer); 30 | } 31 | 32 | return stream.ToArray(); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/blocksync/types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.blocksync; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/blocksync"; 5 | 6 | import "tendermint/types/block.proto"; 7 | 8 | // BlockRequest requests a block for a specific height 9 | message BlockRequest { 10 | int64 height = 1; 11 | } 12 | 13 | // NoBlockResponse informs the node that the peer does not have block at the requested height 14 | message NoBlockResponse { 15 | int64 height = 1; 16 | } 17 | 18 | // BlockResponse returns block to the requested 19 | message BlockResponse { 20 | tendermint.types.Block block = 1; 21 | } 22 | 23 | // StatusRequest requests the status of a peer. 24 | message StatusRequest { 25 | } 26 | 27 | // StatusResponse is a peer response to inform their status. 28 | message StatusResponse { 29 | int64 height = 1; 30 | int64 base = 2; 31 | } 32 | 33 | message Message { 34 | oneof sum { 35 | BlockRequest block_request = 1; 36 | NoBlockResponse no_block_response = 2; 37 | BlockResponse block_response = 3; 38 | StatusRequest status_request = 4; 39 | StatusResponse status_response = 5; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Phantasma.Business/src/Blockchain/Contracts/CrownContract.tomb: -------------------------------------------------------------------------------- 1 | struct crownStruct 2 | { 3 | staker:address; 4 | date:timestamp; 5 | } 6 | 7 | token CROWN { 8 | import Runtime; 9 | import Time; 10 | import NFT; 11 | 12 | global _owner:address; 13 | 14 | property name:string = "Phantasma Reward"; 15 | property isTransferable:bool = true; 16 | property isBurnable:bool = true; 17 | property isFinite:bool = false; 18 | property maxSupply:number = 0; 19 | property owner:address = _owner; 20 | 21 | nft crownNFT { 22 | property name:string { 23 | return "Crown #" + _mintID; 24 | } 25 | 26 | property description:string { 27 | return "Reward obtained by " + _ROM.staker; 28 | } 29 | 30 | property imageURL:string { 31 | return "https://phantasma.io/img/crown.png"; 32 | } 33 | 34 | property infoURL:string { 35 | return "https://phantasma.io/crown/" + _tokenID; 36 | } 37 | } 38 | 39 | constructor(owner:address) { 40 | _owner:= owner; 41 | NFT.createSeries(owner, $THIS_SYMBOL, 0, 0, TokenSeries.Unique, crownNFT); 42 | } 43 | 44 | trigger onMigrate(from:address, to:address) { 45 | if (from == _owner) { 46 | _owner := to; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/ModuleNode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Phantasma.Business.Core.Nodes 4 | { 5 | public class ModuleNode : CompilerNode 6 | { 7 | public List imports = new List(); 8 | public List classes = new List(); 9 | 10 | public StatementNode body; 11 | 12 | public ModuleNode() : base(null) 13 | { 14 | } 15 | 16 | public override IEnumerable Nodes 17 | { 18 | get 19 | { 20 | foreach (var import in imports) 21 | { 22 | yield return import; 23 | } 24 | 25 | foreach (var @class in classes) 26 | { 27 | yield return @class; 28 | } 29 | 30 | if (body != null) 31 | { 32 | yield return body; 33 | } 34 | 35 | yield break; 36 | } 37 | } 38 | 39 | protected override bool ValidateSemantics() 40 | { 41 | return body != null; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Phantasma.Tests/NachoTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using Phantasma.API; 3 | using Phantasma.Cryptography; 4 | using Phantasma.Numerics; 5 | using Phantasma.Simulator; 6 | using Phantasma.Storage; 7 | using Phantasma.VM; 8 | using Phantasma.VM.Utils; 9 | 10 | namespace Phantasma.Tests 11 | { 12 | /* 13 | [TestClass] 14 | class NachoTests 15 | { 16 | [TestMethod] 17 | public void TestGetBotWrestler() 18 | { 19 | var owner = PhantasmaKeys.Generate(); 20 | var simulator = new NexusSimulator(owner, 1234); 21 | var nexus = simulator.Nexus; 22 | var api = new NexusAPI(nexus); 23 | 24 | 25 | var callScript = ScriptUtils.BeginScript().CallContract("nacho", "GetWrestler", new object[] {-1}).EndScript(); 26 | var apiResult = (ScriptResult)api.InvokeRawScript("main", Base16.Encode(callScript)); 27 | var bytes = Base16.Decode(apiResult.results[0]); 28 | var objResult = Serialization.Unserialize(bytes); 29 | var nachoWrestler = objResult.ToStruct(); 30 | 31 | } 32 | 33 | }*/ 34 | } 35 | -------------------------------------------------------------------------------- /Phantasma.Node/Chains/Ethereum/EthTxExtensions.cs: -------------------------------------------------------------------------------- 1 | using Nethereum.Util; 2 | 3 | namespace Nethereum.RPC.Eth.DTOs 4 | { 5 | public static class EthTXExtension 6 | { 7 | public static bool IsToAny(this Transaction txn, string[] addresses) 8 | { 9 | if (string.IsNullOrEmpty(txn.To)) 10 | { 11 | return false; 12 | } 13 | 14 | string toAddress; 15 | if (txn.To.StartsWith("0x")) 16 | { 17 | toAddress = txn.To.Substring(2); 18 | } 19 | else 20 | { 21 | toAddress = txn.To; 22 | } 23 | 24 | foreach (var address in addresses) 25 | { 26 | string checkAddress; 27 | if (address.StartsWith("0x")) 28 | { 29 | checkAddress = address.Substring(2); 30 | } 31 | else 32 | { 33 | checkAddress = address; 34 | } 35 | 36 | if (toAddress.IsTheSameAddress(checkAddress)) 37 | { 38 | return true; 39 | } 40 | } 41 | 42 | return false; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/p2p/pex.go: -------------------------------------------------------------------------------- 1 | package p2p 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/gogo/protobuf/proto" 7 | ) 8 | 9 | // Wrap implements the p2p Wrapper interface and wraps a PEX message. 10 | func (m *PexMessage) Wrap(pb proto.Message) error { 11 | switch msg := pb.(type) { 12 | case *PexRequest: 13 | m.Sum = &PexMessage_PexRequest{PexRequest: msg} 14 | case *PexResponse: 15 | m.Sum = &PexMessage_PexResponse{PexResponse: msg} 16 | case *PexRequestV2: 17 | m.Sum = &PexMessage_PexRequestV2{PexRequestV2: msg} 18 | case *PexResponseV2: 19 | m.Sum = &PexMessage_PexResponseV2{PexResponseV2: msg} 20 | default: 21 | return fmt.Errorf("unknown pex message: %T", msg) 22 | } 23 | return nil 24 | } 25 | 26 | // Unwrap implements the p2p Wrapper interface and unwraps a wrapped PEX 27 | // message. 28 | func (m *PexMessage) Unwrap() (proto.Message, error) { 29 | switch msg := m.Sum.(type) { 30 | case *PexMessage_PexRequest: 31 | return msg.PexRequest, nil 32 | case *PexMessage_PexResponse: 33 | return msg.PexResponse, nil 34 | case *PexMessage_PexRequestV2: 35 | return msg.PexRequestV2, nil 36 | case *PexMessage_PexResponseV2: 37 | return msg.PexResponseV2, nil 38 | default: 39 | return nil, fmt.Errorf("unknown pex message: %T", msg) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /DOCKER/wrapper.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # reset all nodes 3 | TMHOME=/app/testnet/node0 testnet/tendermint unsafe-reset-all 4 | TMHOME=/app/testnet/node1 testnet/tendermint unsafe-reset-all 5 | TMHOME=/app/testnet/node2 testnet/tendermint unsafe-reset-all 6 | TMHOME=/app/testnet/node3 testnet/tendermint unsafe-reset-all 7 | 8 | # start all tendermint sessions 9 | screen -S node0 -dm bash -c 'TMHOME=/app/testnet/node0 /app/testnet/tendermint node; exec sh' 10 | screen -S node1 -dm bash -c 'TMHOME=/app/testnet/node1 /app/testnet/tendermint node; exec sh' 11 | screen -S node2 -dm bash -c 'TMHOME=/app/testnet/node2 /app/testnet/tendermint node; exec sh' 12 | screen -S node3 -dm bash -c 'TMHOME=/app/testnet/node3 /app/testnet/tendermint node; exec sh' 13 | 14 | screen -S node0p -dm bash -c 'cd /app/testnet/node0/publish/; rm -rf Storage; ./phantasma-node --urls "http://*:5101"; exec sh' 15 | screen -S node1p -dm bash -c 'cd /app/testnet/node1/publish/; rm -rf Storage; ./phantasma-node --urls "http://*:5102"; exec sh' 16 | screen -S node2p -dm bash -c 'cd /app/testnet/node2/publish/; rm -rf Storage; ./phantasma-node --urls "http://*:5103"; exec sh' 17 | screen -S node3p -dm bash -c 'cd /app/testnet/node3/publish/; rm -rf Storage; ./phantasma-node --urls "http://*:5104"; exec sh' 18 | 19 | screen -rd node0p 20 | -------------------------------------------------------------------------------- /Phantasma.Tests/Phantasma.Simulator/Phantasma.Simulator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.1 4 | 40 5 | C:\code\PhantasmaSpook\Backup\Phantasma.Simulator\ 6 | Current 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Phantasma.Business/tests/VM/DebugInfoTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Shouldly; 4 | using Xunit; 5 | 6 | namespace Phantasma.Business.Tests.VM; 7 | 8 | public class DebugInfoTest 9 | { 10 | [Fact] 11 | public void null_debugRange_test() 12 | { 13 | var debugRange = new DebugRange(); 14 | debugRange.SourceLine.ShouldBe((uint)0); 15 | debugRange.StartOffset.ShouldBe(0); 16 | debugRange.EndOffset.ShouldBe(0); 17 | } 18 | 19 | [Fact] 20 | public void someValue_debugRange_test() 21 | { 22 | var debugRange = new DebugRange(1,2,3); 23 | debugRange.SourceLine.ShouldBe((uint)1); 24 | debugRange.StartOffset.ShouldBe(2); 25 | debugRange.EndOffset.ShouldBe(3); 26 | } 27 | 28 | [Fact] 29 | public void null_debugInfo_test() 30 | { 31 | DebugInfo debugInfo = null; 32 | debugInfo.ShouldBeNull(); 33 | } 34 | 35 | [Fact] 36 | public void someValue_debugInfo_test() 37 | { 38 | var emptyDebugRangeList = new List(); 39 | var filename = "testFile.txt"; 40 | var debugInfo = new DebugInfo(filename, emptyDebugRangeList ); 41 | debugInfo.Ranges.ShouldBe(emptyDebugRangeList); 42 | debugInfo.FileName.ShouldBe(filename); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/StackAssignmentNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Phantasma.Business.Core.Nodes 6 | { 7 | public class StackAssignmentNode : StatementNode 8 | { 9 | public string identifier; 10 | public DeclarationNode declaration; 11 | 12 | public StackAssignmentNode(CompilerNode owner) : base(owner) 13 | { 14 | } 15 | 16 | public override IEnumerable Nodes 17 | { 18 | get 19 | { 20 | if (declaration != null) 21 | { 22 | yield return declaration; 23 | } 24 | 25 | yield break; 26 | } 27 | } 28 | 29 | public override string ToString() 30 | { 31 | return base.ToString() + "=>" + this.identifier; 32 | } 33 | 34 | public override List Emit(Compiler compiler) 35 | { 36 | var reg = compiler.AllocRegister(); 37 | compiler.varMap[declaration.identifier] = reg; 38 | 39 | var temp = new List(); 40 | temp.Add(new Instruction() { source = this, target = reg, op = Instruction.Opcode.Pop }); 41 | return temp; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Phantasma.Infrastructure/src/API/Controllers/ContractController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace Phantasma.Infrastructure.Controllers 4 | { 5 | public class ContractController : BaseControllerV1 6 | { 7 | [APIInfo(typeof(ContractResult), "Returns the ABI interface of specific contract.", false, 300)] 8 | [HttpGet("GetContract")] 9 | public ContractResult GetContract([APIParameter("Chain address or name where the contract is deployed", "main")] string chainAddressOrName, [APIParameter("Contract name", "account")] string contractName) 10 | { 11 | var chain = NexusAPI.FindChainByInput(chainAddressOrName); 12 | if (chain == null) 13 | { 14 | throw new APIException("Chain not found"); 15 | } 16 | 17 | if (string.IsNullOrEmpty(contractName)) 18 | { 19 | throw new APIException("Invalid contract name"); 20 | } 21 | 22 | if (!chain.IsContractDeployed(chain.Storage, contractName)) 23 | { 24 | throw new APIException("Contract not found"); 25 | } 26 | 27 | var contract = chain.GetContractByName(chain.Storage, contractName); 28 | return NexusAPI.FillContract(contractName, contract); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/LanguageProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Phantasma.Business.Languages; 3 | using Phantasma.Shared; 4 | 5 | namespace Phantasma.Business.Core 6 | { 7 | public enum Language 8 | { 9 | Unknown, 10 | CSharp, 11 | Solidity 12 | } 13 | 14 | public abstract class LanguageProcessor 15 | { 16 | public abstract Lexer Lexer { get; } 17 | public abstract Parser Parser { get; } 18 | public abstract string Description { get; } 19 | 20 | public static Language GetLanguage(string extension) 21 | { 22 | switch (extension) 23 | { 24 | case ".cs": return Language.CSharp; 25 | case ".sol": return Language.Solidity; 26 | default: return Language.Unknown; 27 | } 28 | } 29 | 30 | public static LanguageProcessor GetProcessor(Language language) 31 | { 32 | Throw.If(language == Language.Unknown, "unknown language"); 33 | 34 | switch (language) 35 | { 36 | case Language.CSharp: return new CSharpProcessor(); 37 | case Language.Solidity: return new SolidityProcessor(); 38 | default: throw new NotImplementedException(language.ToString()); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Phantasma.Infrastructure/src/API/Controllers/LeaderboardController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Microsoft.AspNetCore.Mvc; 4 | using Phantasma.Business.Contracts; 5 | using Phantasma.Core; 6 | 7 | namespace Phantasma.Infrastructure.Controllers 8 | { 9 | public class LeaderboardController : BaseControllerV1 10 | { 11 | [APIInfo(typeof(LeaderboardResult), "Returns content of a Phantasma leaderboard.", false, 30)] 12 | [HttpGet("GetLeaderboard")] 13 | public LeaderboardResult GetLeaderboard(string name) 14 | { 15 | var nexus = NexusAPI.GetNexus(); 16 | 17 | var temp = nexus.RootChain.InvokeContract(nexus.RootChain.Storage, "ranking", nameof(RankingContract.GetRows), name).ToObject(); 18 | 19 | try 20 | { 21 | var board = ((LeaderboardRow[])temp).ToArray(); 22 | 23 | return new LeaderboardResult() 24 | { 25 | name = name, 26 | rows = board.Select(x => new LeaderboardRowResult() { address = x.address.Text, value = x.score.ToString() }).ToArray(), 27 | }; 28 | } 29 | catch (Exception e) 30 | { 31 | throw new APIException($"error fetching leaderboard: {e.Message}"); 32 | } 33 | 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/BlockNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Phantasma.Business.Core.Nodes 6 | { 7 | public class BlockNode : StatementNode 8 | { 9 | public List declarations = new List(); 10 | public List statements = new List(); 11 | 12 | public BlockNode(CompilerNode owner) : base(owner) 13 | { 14 | } 15 | 16 | public override DeclarationNode ResolveIdentifier(string identifier) 17 | { 18 | foreach (var decl in declarations) 19 | { 20 | if (decl.identifier == identifier) 21 | { 22 | return decl; 23 | } 24 | } 25 | 26 | return base.ResolveIdentifier(identifier); 27 | } 28 | 29 | public override List Emit(Compiler compiler) 30 | { 31 | var list = new List(); 32 | 33 | foreach (var st in statements) 34 | { 35 | var temp = st.Emit(compiler); 36 | list.AddRange(temp); 37 | } 38 | return list; 39 | } 40 | 41 | public override IEnumerable Nodes => declarations.Concat(statements); 42 | } 43 | } -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/TxSearch.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Tendermint.RPC.Endpoint 7 | { 8 | /* 9 | TxSearch allows you to query for multiple transactions results.You could search transaction by its index. It returns a list of transactions (maximum ?per_page entries) and the total count. Query Parameters 10 | Parameter Type Default Required Description 11 | query string "" true Query 12 | prove bool false false Include proofs of the transactions inclusion in the block 13 | page int 1 false Page number (1-based) 14 | per_page int 30 false Number of entries per page (max: 100) 15 | 16 | Returns Parameters 17 | proof: the types.TxProof object 18 | tx: []byte - the transaction 19 | tx_result: the abci.Result object 20 | index: int - index of the transaction 21 | height: int - height of the block where this transaction was in 22 | hash: []byte - hash of the transaction 23 | */ 24 | 25 | public class ResultTxSearch : IEndpointResponse 26 | { 27 | [JsonProperty("txs")] 28 | public List Txs { get; set; } 29 | 30 | [JsonProperty("total_count")] 31 | public string TotalCount { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/ReturnNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Phantasma.Business.Core.Nodes 6 | { 7 | public class ReturnNode : StatementNode 8 | { 9 | public ExpressionNode expr; 10 | 11 | public ReturnNode(CompilerNode owner) : base(owner) 12 | { 13 | } 14 | 15 | public override List Emit(Compiler compiler) 16 | { 17 | var temp = expr.Emit(compiler); 18 | var last = temp.Last(); 19 | temp.Add(new Instruction() { source = this, target = last.target, a = last, op = Instruction.Opcode.Push }); 20 | temp.Add(new Instruction() { source = this, target = null, a = null, op = Instruction.Opcode.Return }); 21 | return temp; 22 | } 23 | 24 | public override IEnumerable Nodes 25 | { 26 | get 27 | { 28 | yield return expr; 29 | yield break; 30 | } 31 | } 32 | 33 | protected override bool ValidateSemantics() 34 | { 35 | var method = FindParentMethod(); 36 | 37 | if (method == null) 38 | { 39 | return false; 40 | } 41 | 42 | return method.returnType.Kind == expr.GetKind(); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Phantasma.Core/src/Storage/Context/KeyStoreStorage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Phantasma.Core.Context 4 | { 5 | public class KeyStoreStorage : StorageContext 6 | { 7 | public readonly IKeyValueStoreAdapter Adapter; 8 | 9 | public KeyStoreStorage(IKeyValueStoreAdapter adapter) 10 | { 11 | this.Adapter = adapter; 12 | } 13 | 14 | public override void Clear() 15 | { 16 | throw new NotImplementedException(); 17 | } 18 | 19 | public override void Delete(StorageKey key) 20 | { 21 | Adapter.Remove(key.keyData); 22 | } 23 | 24 | public override byte[] Get(StorageKey key) 25 | { 26 | return Adapter.GetValue(key.keyData); 27 | } 28 | 29 | public override bool Has(StorageKey key) 30 | { 31 | return Adapter.ContainsKey(key.keyData); 32 | } 33 | 34 | public override void Put(StorageKey key, byte[] value) 35 | { 36 | Adapter.SetValue(key.keyData, value); 37 | } 38 | 39 | public override void Visit(Action visitor, ulong searchCount = 0, byte[] prefix = null) 40 | { 41 | Adapter.Visit((keyBytes, valBytes) => 42 | { 43 | visitor(keyBytes, valBytes); 44 | }, searchCount, prefix); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Phantasma.Infrastructure/src/Phantasma.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0 4 | 40 5 | disable 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/VariableExpressionNode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Phantasma.Business.Core.Nodes 5 | { 6 | public class VariableExpressionNode : ExpressionNode 7 | { 8 | public string identifier; 9 | 10 | public DeclarationNode declaration; // can resolved later 11 | 12 | public VariableExpressionNode(CompilerNode owner) : base(owner) 13 | { 14 | } 15 | 16 | public override IEnumerable Nodes => Enumerable.Empty(); 17 | 18 | public override string ToString() 19 | { 20 | return base.ToString() + "=>" + this.identifier; 21 | } 22 | 23 | public override List Emit(Compiler compiler) 24 | { 25 | if (this.declaration == null) 26 | { 27 | this.declaration = ResolveIdentifier(this.identifier); 28 | } 29 | 30 | var varLocation = compiler.varMap[this.declaration.identifier]; 31 | 32 | var temp = new List(); 33 | temp.Add(new Instruction() { source = this, target = compiler.AllocRegister(), varName = varLocation, op = Instruction.Opcode.Assign}); 34 | return temp; 35 | } 36 | 37 | public override TypeKind GetKind() 38 | { 39 | return TypeKind.Unknown; // TODO should return Kind of variable 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Tendermint.RPC/src/RpcResponse.cs: -------------------------------------------------------------------------------- 1 | using Tendermint.RPC.Endpoint; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Tendermint.RPC 8 | { 9 | public class Error 10 | { 11 | [JsonProperty("code")] 12 | public long Code { get; set; } 13 | 14 | [JsonProperty("message")] 15 | public string Message { get; set; } 16 | 17 | [JsonProperty("data")] 18 | public string Data { get; set; } 19 | } 20 | 21 | public class NoResult : IEndpointResponse 22 | { 23 | } 24 | 25 | public class RpcResponse where T : IEndpointResponse, new() 26 | { 27 | /* 28 | { 29 | "jsonrpc": "2.0", 30 | "id": "", 31 | "result": { 32 | "response": { 33 | "data": "BNBChain", 34 | "last_block_height": "7579978", 35 | "last_block_app_hash": "92HKpxrNKqYkzSRj49FI+PjzVx7oirnYrwhMzG0CRDg=" 36 | } 37 | } 38 | } 39 | */ 40 | 41 | [JsonProperty("jsonrpc")] 42 | public string JsonRpc { get; set; } 43 | 44 | [JsonProperty("id")] 45 | public string Id { get; set; } 46 | 47 | [JsonProperty("result")] 48 | public T Result { get; set; } 49 | 50 | [JsonProperty("error")] 51 | public Error Error { get; set; } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/Opcodes.cs: -------------------------------------------------------------------------------- 1 | namespace Phantasma.Core 2 | { 3 | public enum Opcode 4 | { 5 | NOP, 6 | 7 | // register 8 | MOVE, // copy reference 9 | COPY, // copy by value 10 | PUSH, 11 | POP, 12 | SWAP, 13 | 14 | // flow 15 | CALL, 16 | EXTCALL, 17 | JMP, 18 | JMPIF, 19 | JMPNOT, 20 | RET, 21 | THROW, 22 | 23 | // data 24 | LOAD, 25 | CAST, 26 | CAT, 27 | RANGE, 28 | LEFT, 29 | RIGHT, 30 | SIZE, 31 | COUNT, 32 | 33 | // logical 34 | NOT, 35 | AND, 36 | OR, 37 | XOR, 38 | EQUAL, 39 | LT, 40 | GT, 41 | LTE, 42 | GTE, 43 | 44 | // numeric 45 | INC, 46 | DEC, 47 | SIGN, 48 | NEGATE, 49 | ABS, 50 | ADD, 51 | SUB, 52 | MUL, 53 | DIV, 54 | MOD, 55 | SHL, 56 | SHR, 57 | MIN, 58 | MAX, 59 | POW, 60 | 61 | // context 62 | CTX, 63 | SWITCH, 64 | 65 | // array 66 | PUT, 67 | GET, // lookups a key and copies a reference into register 68 | CLEAR, // clears a register 69 | UNPACK, // unpacks serialized struct based on ref struct 70 | PACK, // unused for now 71 | 72 | // debugger 73 | DEBUG, 74 | 75 | // add 76 | SUBSTR 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/LiteralExpressionNode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Phantasma.Business.Core.Nodes 5 | { 6 | public class LiteralExpressionNode : ExpressionNode 7 | { 8 | public object value; 9 | public LiteralKind kind; 10 | 11 | public LiteralExpressionNode(CompilerNode owner) : base(owner) 12 | { 13 | } 14 | 15 | public override IEnumerable Nodes => Enumerable.Empty(); 16 | 17 | public override string ToString() 18 | { 19 | return base.ToString() + "=>" + this.value; 20 | } 21 | 22 | public override List Emit(Compiler compiler) 23 | { 24 | var temp = new List(); 25 | temp.Add(new Instruction() { source = this, target = compiler.AllocRegister(), literal = this, op = Instruction.Opcode.Assign }); 26 | return temp; 27 | } 28 | 29 | public override TypeKind GetKind() 30 | { 31 | switch (kind) 32 | { 33 | case LiteralKind.Binary: return TypeKind.ByteArray; 34 | case LiteralKind.Boolean: return TypeKind.Boolean; 35 | case LiteralKind.Float: return TypeKind.Float; 36 | case LiteralKind.Integer: return TypeKind.Integer; 37 | case LiteralKind.String: return TypeKind.String; 38 | default: return TypeKind.Unknown; 39 | } 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Phantasma.Node/Chains/Ethereum/EthFunctions.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using Nethereum.Contracts; 3 | using Nethereum.ABI.FunctionEncoding.Attributes; 4 | 5 | namespace Phantasma.Node.Chains 6 | { 7 | [Function("balanceOf", "uint256")] 8 | public class BalanceOfFunction : FunctionMessage 9 | { 10 | [Parameter("address", "_owner", 1)] 11 | public string Owner { get; set; } 12 | } 13 | 14 | [Function("swapOut", "bool")] 15 | public class SwapOutFunction : FunctionMessage 16 | { 17 | [Parameter("address", "source", 1)] 18 | public string Source { get; set; } 19 | 20 | [Parameter("address", "target", 2)] 21 | public string Target { get; set; } 22 | 23 | [Parameter("uint256", "amount", 3)] 24 | public BigInteger Amount { get; set; } 25 | } 26 | 27 | [Function("swapIn", "bool")] 28 | public class SwapInFunction : FunctionMessage 29 | { 30 | [Parameter("address", "source", 1)] 31 | public string Source { get; set; } 32 | 33 | [Parameter("address", "target", 2)] 34 | public string Target { get; set; } 35 | 36 | [Parameter("uint256", "amount", 3)] 37 | public BigInteger Amount { get; set; } 38 | } 39 | 40 | [Function("transfer", "bool")] 41 | public class TransferFunction : FunctionMessage 42 | { 43 | [Parameter("address", "_to", 1)] 44 | public string To { get; set; } 45 | 46 | [Parameter("uint256", "_value", 2)] 47 | public BigInteger TokenAmount { get; set; } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Phantasma.Business/src/Blockchain/Contracts/ContractNames.cs: -------------------------------------------------------------------------------- 1 | using Phantasma.Core; 2 | 3 | public static class ContractNames 4 | { 5 | public readonly static string GasContractName = NativeContractKind.Gas.GetContractName(); 6 | public readonly static string BlockContractName = NativeContractKind.Block.GetContractName(); 7 | public readonly static string StakeContractName = NativeContractKind.Stake.GetContractName(); 8 | public readonly static string SwapContractName = NativeContractKind.Swap.GetContractName(); 9 | public readonly static string AccountContractName = NativeContractKind.Account.GetContractName(); 10 | public readonly static string ConsensusContractName = NativeContractKind.Consensus.GetContractName(); 11 | public readonly static string GovernanceContractName = NativeContractKind.Governance.GetContractName(); 12 | public readonly static string StorageContractName = NativeContractKind.Storage.GetContractName(); 13 | public readonly static string ValidatorContractName = NativeContractKind.Validator.GetContractName(); 14 | public readonly static string InteropContractName = NativeContractKind.Interop.GetContractName(); 15 | public readonly static string ExchangeContractName = NativeContractKind.Exchange.GetContractName(); 16 | public readonly static string RelayContractName = NativeContractKind.Relay.GetContractName(); 17 | public readonly static string RankingContractName = NativeContractKind.Ranking.GetContractName(); 18 | public readonly static string MailContractName = NativeContractKind.Mail.GetContractName(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/p2p/types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.p2p; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/p2p"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | import "google/protobuf/timestamp.proto"; 8 | 9 | message ProtocolVersion { 10 | uint64 p2p = 1 [(gogoproto.customname) = "P2P"]; 11 | uint64 block = 2; 12 | uint64 app = 3; 13 | } 14 | 15 | message NodeInfo { 16 | ProtocolVersion protocol_version = 1 [(gogoproto.nullable) = false]; 17 | string node_id = 2 [(gogoproto.customname) = "NodeID"]; 18 | string listen_addr = 3; 19 | string network = 4; 20 | string version = 5; 21 | bytes channels = 6; 22 | string moniker = 7; 23 | NodeInfoOther other = 8 [(gogoproto.nullable) = false]; 24 | } 25 | 26 | message NodeInfoOther { 27 | string tx_index = 1; 28 | string rpc_address = 2 [(gogoproto.customname) = "RPCAddress"]; 29 | } 30 | 31 | message PeerInfo { 32 | string id = 1 [(gogoproto.customname) = "ID"]; 33 | repeated PeerAddressInfo address_info = 2; 34 | google.protobuf.Timestamp last_connected = 3 [(gogoproto.stdtime) = true]; 35 | } 36 | 37 | message PeerAddressInfo { 38 | string address = 1; 39 | google.protobuf.Timestamp last_dial_success = 2 [(gogoproto.stdtime) = true]; 40 | google.protobuf.Timestamp last_dial_failure = 3 [(gogoproto.stdtime) = true]; 41 | uint32 dial_failures = 4; 42 | } 43 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/IVirtualMachine.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public interface IVirtualMachine 6 | { 7 | public Stack Stack { get; } 8 | 9 | public byte[] EntryScript { get; } 10 | 11 | public Address EntryAddress { get; set; } 12 | 13 | public ExecutionContext CurrentContext { get; set; } 14 | 15 | public ExecutionContext PreviousContext { get; set; } 16 | 17 | public ExecutionFrame CurrentFrame { get; set; } 18 | 19 | public Stack Frames { get; } 20 | 21 | public void RegisterContext(string contextName, ExecutionContext context); 22 | 23 | public ExecutionState ExecuteInterop(string method); 24 | 25 | public abstract ExecutionContext LoadContext(string contextName); 26 | 27 | public ExecutionState Execute(); 28 | 29 | public void PushFrame(ExecutionContext context, uint instructionPointer, int registerCount); 30 | 31 | public uint PopFrame(); 32 | 33 | public ExecutionFrame PeekFrame(); 34 | 35 | public void SetCurrentContext(ExecutionContext context); 36 | 37 | public ExecutionContext FindContext(string contextName); 38 | 39 | public ExecutionState ValidateOpcode(Opcode opcode); 40 | 41 | public ExecutionState SwitchContext(ExecutionContext context, uint instructionPointer); 42 | 43 | public string GetDumpFileName(); 44 | 45 | public void DumpData(List lines); 46 | 47 | public void Expect(bool condition, string description); 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/BroadcastTxSync.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Tendermint.RPC.Endpoint 7 | { 8 | /* 9 | BroadcastTxSync 10 | 11 | The transaction will be broadcasted and returns with the response from CheckTx. Transaction Parameters | Parameter | Type | Default | Required | Description | |-----------|------|---------|----------|-----------------| | tx | Tx | nil | true | The transaction info bytes in hex| 12 | 13 | Return Parameters CheckTx results 14 | 15 | type ResultBroadcastTx struct { 16 | Code uint32 17 | Data cmn.HexBytes 18 | Log string 19 | Hash cmn.HexBytes 20 | } 21 | */ 22 | 23 | /* 24 | { 25 | "jsonrpc": "2.0", 26 | "id": "", 27 | "result": { 28 | "code": 0, 29 | "data": "7B226F726465725F6964223A22383133453439333946313536374232313937303446464332414434444635384244453031303837392D3438227D", 30 | "log": "Msg 0: ", 31 | "hash": "920EA6B3EE38AC9B700AB436DABCA8F3D97F06EA63CBCACA7AD22B2E5CA1DF75" 32 | } 33 | } 34 | */ 35 | 36 | public class ResultBroadcastTx : IEndpointResponse 37 | { 38 | [JsonProperty("code")] 39 | public int Code { get; set; } 40 | 41 | [JsonProperty("data")] 42 | public string Data { get; set; } 43 | 44 | [JsonProperty("log")] 45 | public string Log { get; set; } 46 | 47 | [JsonProperty("hash")] 48 | public string Hash { get; set; } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/AbciInfo.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Tendermint.RPC.Endpoint 7 | { 8 | /* 9 | * Get some info about the application. Return Type: 10 | * 11 | type ResponseInfo struct { 12 | Data string 13 | Version string 14 | AppVersion uint64 15 | LastBlockHeight int64 16 | LastBlockAppHash []byte 17 | } 18 | */ 19 | 20 | /* 21 | { 22 | "jsonrpc": "2.0", 23 | "id": "", 24 | "result": { 25 | "response": { 26 | "data": "BNBChain", 27 | "last_block_height": "9611317", 28 | "last_block_app_hash": "/drwJ+9iLMHGHN8ott4Niux5gZeuCpayZ5HtxBsoScM=" 29 | } 30 | } 31 | } 32 | */ 33 | 34 | public class ResponseInfo 35 | { 36 | [JsonProperty("data")] 37 | public string Data { get; set; } 38 | 39 | [JsonProperty("version")] 40 | public string Version { get; set; } 41 | 42 | [JsonProperty("app_version")] 43 | public string AppVersion { get; set; } 44 | 45 | [JsonProperty("last_block_height")] 46 | public string LastBlockHeight { get; set; } 47 | 48 | [JsonProperty("last_block_app_hash")] 49 | public string LastBlockAppHash { get; set; } 50 | } 51 | 52 | public class ResponseData : IEndpointResponse 53 | { 54 | [JsonProperty("response")] 55 | public ResponseInfo Response { get; set; } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/types/evidence.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.types; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | import "google/protobuf/timestamp.proto"; 8 | import "tendermint/types/types.proto"; 9 | import "tendermint/types/validator.proto"; 10 | 11 | message Evidence { 12 | oneof sum { 13 | DuplicateVoteEvidence duplicate_vote_evidence = 1; 14 | LightClientAttackEvidence light_client_attack_evidence = 2; 15 | } 16 | } 17 | 18 | // DuplicateVoteEvidence contains evidence of a validator signed two conflicting votes. 19 | message DuplicateVoteEvidence { 20 | tendermint.types.Vote vote_a = 1; 21 | tendermint.types.Vote vote_b = 2; 22 | int64 total_voting_power = 3; 23 | int64 validator_power = 4; 24 | google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; 25 | } 26 | 27 | // LightClientAttackEvidence contains evidence of a set of validators attempting to mislead a light client. 28 | message LightClientAttackEvidence { 29 | tendermint.types.LightBlock conflicting_block = 1; 30 | int64 common_height = 2; 31 | repeated tendermint.types.Validator byzantine_validators = 3; 32 | int64 total_voting_power = 4; 33 | google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; 34 | } 35 | 36 | message EvidenceList { 37 | repeated Evidence evidence = 1 [(gogoproto.nullable) = false]; 38 | } 39 | -------------------------------------------------------------------------------- /Phantasma.Node/Oracles/Pricer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Serilog; 3 | 4 | namespace Phantasma.Node.Oracles 5 | { 6 | public static class Pricer 7 | { 8 | public static decimal GetCoinRate(string baseSymbol, string quoteSymbol, string cryptoCompApiKey, bool cgEnabled, PricerSupportedToken[] supportedTokens) 9 | { 10 | try 11 | { 12 | Decimal cGeckoPrice = 0; 13 | Decimal cComparePrice = 0; 14 | 15 | if (string.IsNullOrEmpty(cryptoCompApiKey)) 16 | { 17 | cComparePrice = CryptoCompareUtils.GetCoinRate(baseSymbol, quoteSymbol, cryptoCompApiKey, supportedTokens); 18 | } 19 | 20 | if (cgEnabled) 21 | { 22 | cGeckoPrice = CoinGeckoUtils.GetCoinRate(baseSymbol, quoteSymbol, supportedTokens); 23 | } 24 | 25 | if ((cGeckoPrice > 0) && (cComparePrice > 0)) 26 | { 27 | return ((cGeckoPrice + cComparePrice) / 2); 28 | } 29 | if((cGeckoPrice > 0) && (cComparePrice <= 0)) 30 | { 31 | return (cGeckoPrice); 32 | } 33 | if ((cComparePrice > 0) && (cGeckoPrice <= 0)) 34 | { 35 | return (cComparePrice); 36 | } 37 | return 0; 38 | 39 | } 40 | catch (Exception ex) 41 | { 42 | var errorMsg = ex.ToString(); 43 | Log.Error($"Pricer error: {errorMsg}"); 44 | return 0; 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/consensus/wal.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.consensus; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/consensus"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | import "tendermint/consensus/types.proto"; 8 | import "tendermint/types/events.proto"; 9 | import "google/protobuf/duration.proto"; 10 | import "google/protobuf/timestamp.proto"; 11 | 12 | // MsgInfo are msgs from the reactor which may update the state 13 | message MsgInfo { 14 | Message msg = 1 [(gogoproto.nullable) = false]; 15 | string peer_id = 2 [(gogoproto.customname) = "PeerID"]; 16 | } 17 | 18 | // TimeoutInfo internally generated messages which may update the state 19 | message TimeoutInfo { 20 | google.protobuf.Duration duration = 1 21 | [(gogoproto.nullable) = false, (gogoproto.stdduration) = true]; 22 | int64 height = 2; 23 | int32 round = 3; 24 | uint32 step = 4; 25 | } 26 | 27 | // EndHeight marks the end of the given height inside WAL. 28 | // @internal used by scripts/wal2json util. 29 | message EndHeight { 30 | int64 height = 1; 31 | } 32 | 33 | message WALMessage { 34 | oneof sum { 35 | tendermint.types.EventDataRoundState event_data_round_state = 1; 36 | MsgInfo msg_info = 2; 37 | TimeoutInfo timeout_info = 3; 38 | EndHeight end_height = 4; 39 | } 40 | } 41 | 42 | // TimedWALMessage wraps WALMessage and adds Time for debugging purposes. 43 | message TimedWALMessage { 44 | google.protobuf.Timestamp time = 1 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; 45 | WALMessage msg = 2; 46 | } 47 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/statesync/types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.statesync; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "tendermint/types/types.proto"; 6 | import "tendermint/types/params.proto"; 7 | 8 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/statesync"; 9 | 10 | message Message { 11 | oneof sum { 12 | SnapshotsRequest snapshots_request = 1; 13 | SnapshotsResponse snapshots_response = 2; 14 | ChunkRequest chunk_request = 3; 15 | ChunkResponse chunk_response = 4; 16 | LightBlockRequest light_block_request = 5; 17 | LightBlockResponse light_block_response = 6; 18 | ParamsRequest params_request = 7; 19 | ParamsResponse params_response = 8; 20 | } 21 | } 22 | 23 | message SnapshotsRequest {} 24 | 25 | message SnapshotsResponse { 26 | uint64 height = 1; 27 | uint32 format = 2; 28 | uint32 chunks = 3; 29 | bytes hash = 4; 30 | bytes metadata = 5; 31 | } 32 | 33 | message ChunkRequest { 34 | uint64 height = 1; 35 | uint32 format = 2; 36 | uint32 index = 3; 37 | } 38 | 39 | message ChunkResponse { 40 | uint64 height = 1; 41 | uint32 format = 2; 42 | uint32 index = 3; 43 | bytes chunk = 4; 44 | bool missing = 5; 45 | } 46 | 47 | message LightBlockRequest { 48 | uint64 height = 1; 49 | } 50 | 51 | message LightBlockResponse { 52 | tendermint.types.LightBlock light_block = 1; 53 | } 54 | 55 | message ParamsRequest { 56 | uint64 height = 1; 57 | } 58 | 59 | message ParamsResponse { 60 | uint64 height = 1; 61 | tendermint.types.ConsensusParams consensus_params = 2 [(gogoproto.nullable) = false]; 62 | } -------------------------------------------------------------------------------- /Phantasma.Node/Metrics/EndpointMetrics.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Phantasma.Node.Metrics; 7 | 8 | public class EndpointMetrics : IEndpointMetrics 9 | { 10 | private readonly ConcurrentDictionary> _averages = new(); 11 | private readonly ConcurrentDictionary _counters = new(); 12 | 13 | public Task Count( 14 | string path 15 | ) 16 | { 17 | _counters.AddOrUpdate(path, 1, ( 18 | _, 19 | value 20 | ) => value + 1); 21 | 22 | return Task.CompletedTask; 23 | } 24 | 25 | public Task[]> GetCounts() 26 | { 27 | return Task.FromResult(_counters.ToArray()); 28 | } 29 | 30 | public Task Average( 31 | string path, 32 | long duration 33 | ) 34 | { 35 | _averages.AddOrUpdate(path, new ConcurrentQueue(new[] { duration }), ( 36 | _, 37 | value 38 | ) => 39 | { 40 | lock (value) 41 | { 42 | if (value.Count > 99) 43 | { 44 | value.TryDequeue(out long _); 45 | } 46 | 47 | value.Enqueue(duration); 48 | } 49 | 50 | return value; 51 | }); 52 | 53 | return Task.CompletedTask; 54 | } 55 | 56 | public Task[]> GetAverages() 57 | { 58 | return Task.FromResult(_averages.Select(pair => new KeyValuePair(pair.Key, (long)pair.Value.Average())) 59 | .ToArray()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Phantasma.Node/Oracles/CryptoCompare.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using Phantasma.Shared.Utils; 4 | using Serilog; 5 | 6 | namespace Phantasma.Node.Oracles 7 | { 8 | public static class CryptoCompareUtils 9 | { 10 | 11 | public static decimal GetCoinRate(string baseSymbol, string quoteSymbol, string APIKey, PricerSupportedToken[] supportedTokens) 12 | { 13 | 14 | string baseticker = ""; 15 | 16 | foreach (var token in supportedTokens) 17 | { 18 | if (token.ticker == baseSymbol) 19 | { 20 | baseticker = token.cryptocompareId; 21 | break; 22 | } 23 | } 24 | 25 | if (String.IsNullOrEmpty(baseticker)) 26 | return 0; 27 | 28 | var url = $"https://min-api.cryptocompare.com/data/price?fsym={baseticker}&tsyms={quoteSymbol}&api_key={APIKey}"; 29 | 30 | try 31 | { 32 | var response = RequestUtils.Request(RequestType.GET, url, out var _); 33 | 34 | if(response == null) 35 | return 0; 36 | 37 | if (response.RootElement.TryGetProperty(quoteSymbol, out var priceProperty)) 38 | { 39 | return priceProperty.GetDecimal(); 40 | } 41 | 42 | return 0; 43 | } 44 | catch (Exception ex) 45 | { 46 | var errorMsg = ex.Message; 47 | Log.Error($"Error while trying to query {baseticker} price from CryptoCompare API: {errorMsg}"); 48 | return 0; 49 | } 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Cryptography/EdDSA/Ed25519Signature.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System.Linq; 4 | 5 | namespace Phantasma.Core.EdDSA 6 | { 7 | public class Ed25519Signature : Signature 8 | { 9 | public byte[] Bytes { get; private set; } 10 | 11 | public override SignatureKind Kind => SignatureKind.Ed25519; 12 | 13 | internal Ed25519Signature() 14 | { 15 | this.Bytes = null; 16 | } 17 | 18 | public Ed25519Signature(byte[] bytes) 19 | { 20 | this.Bytes = bytes; 21 | } 22 | 23 | public override bool Verify(byte[] message, IEnumerable
addresses) 24 | { 25 | foreach (var address in addresses) 26 | { 27 | if (!address.IsUser) 28 | { 29 | continue; 30 | } 31 | 32 | var pubKey = address.ToByteArray().Skip(2).ToArray(); 33 | if (Ed25519.Verify(this.Bytes, message, pubKey)) 34 | { 35 | return true; 36 | } 37 | } 38 | 39 | return false; 40 | } 41 | 42 | public override void SerializeData(BinaryWriter writer) 43 | { 44 | writer.WriteByteArray(this.Bytes); 45 | } 46 | 47 | public override void UnserializeData(BinaryReader reader) 48 | { 49 | this.Bytes = reader.ReadByteArray(); 50 | } 51 | 52 | public static Ed25519Signature Generate(IKeyPair keypair, byte[] message) 53 | { 54 | var sign = Ed25519.Sign(message, keypair.PrivateKey); 55 | return new Ed25519Signature(sign); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Phantasma.Node/Swagger/SwaggerAuthorizationMiddleware.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Principal; 2 | using System.Threading.Tasks; 3 | using Microsoft.AspNetCore.Authentication; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.Extensions.Logging; 6 | using Phantasma.Node.Authentication; 7 | 8 | namespace Phantasma.Node.Swagger; 9 | 10 | public class SwaggerAuthorizationMiddleware 11 | { 12 | private readonly ILogger _logger; 13 | private readonly RequestDelegate _next; 14 | 15 | public SwaggerAuthorizationMiddleware(RequestDelegate next, ILogger logger) 16 | { 17 | _next = next; 18 | _logger = logger; 19 | } 20 | 21 | public async Task Invoke(HttpContext context, IPrincipal principal) 22 | { 23 | if (!context.Request.Path.StartsWithSegments("/swagger-internal") && 24 | !context.Request.Path.StartsWithSegments("/swagger/v1-internal")) 25 | { 26 | await _next.Invoke(context); 27 | 28 | return; 29 | } 30 | 31 | if (principal.Identity is { IsAuthenticated: true }) 32 | { 33 | await _next.Invoke(context); 34 | 35 | return; 36 | } 37 | 38 | var result = await context.AuthenticateAsync(BasicAuthenticationDefaults.AuthenticationScheme); 39 | if (result.Succeeded) 40 | { 41 | await _next.Invoke(context); 42 | 43 | return; 44 | } 45 | 46 | _logger.LogWarning(result.Failure, 47 | $"API documentation endpoint unauthorized access attempt by [{context.Connection.RemoteIpAddress}]"); 48 | await context.ChallengeAsync(BasicAuthenticationDefaults.AuthenticationScheme); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /DOCKER/testnet/node0/config/genesis.json: -------------------------------------------------------------------------------- 1 | { 2 | "genesis_time": "2022-06-07T07:19:27.620807337Z", 3 | "chain_id": "chain-Q6CmDc", 4 | "initial_height": "0", 5 | "consensus_params": { 6 | "block": { 7 | "max_bytes": "22020096", 8 | "max_gas": "-1" 9 | }, 10 | "evidence": { 11 | "max_age_num_blocks": "100000", 12 | "max_age_duration": "172800000000000", 13 | "max_bytes": "1048576" 14 | }, 15 | "validator": { 16 | "pub_key_types": [ 17 | "ed25519" 18 | ] 19 | }, 20 | "version": { 21 | "app_version": "0" 22 | } 23 | }, 24 | "validators": [ 25 | { 26 | "address": "11BB132EC77BC788B65CEAE309A21EC9AD30686C", 27 | "pub_key": { 28 | "type": "tendermint/PubKeyEd25519", 29 | "value": "XGZrm1htSmuI3+fhsu8+VxOuPGbqubdE13gVbhIHe1Q=" 30 | }, 31 | "power": "1", 32 | "name": "node0" 33 | }, 34 | { 35 | "address": "7CCF8D79D6B7ED4B0FACFD4C3C1FA547DEA0E5CD", 36 | "pub_key": { 37 | "type": "tendermint/PubKeyEd25519", 38 | "value": "IiiA7W0pkTGnIFi/zqIHjfgMt/1gLZUwo/Bt6L8F6Ms=" 39 | }, 40 | "power": "1", 41 | "name": "node1" 42 | }, 43 | { 44 | "address": "C06DF36A9325CAA700406E1404E777D3DE7533B2", 45 | "pub_key": { 46 | "type": "tendermint/PubKeyEd25519", 47 | "value": "ZXuG6/FObVz4mhCpKwPHi6R/ZnehI/t+Xww74DX56II=" 48 | }, 49 | "power": "1", 50 | "name": "node2" 51 | }, 52 | { 53 | "address": "92544D338AB5935A8F6D4CE3953546FB6B0368C5", 54 | "pub_key": { 55 | "type": "tendermint/PubKeyEd25519", 56 | "value": "/tirj7G+lHmiZ/L94DVoXDwBhC7bqPv4zoVS7Rlau8E=" 57 | }, 58 | "power": "1", 59 | "name": "node3" 60 | } 61 | ], 62 | "app_hash": "" 63 | } -------------------------------------------------------------------------------- /DOCKER/testnet/node1/config/genesis.json: -------------------------------------------------------------------------------- 1 | { 2 | "genesis_time": "2022-06-07T07:19:27.620807337Z", 3 | "chain_id": "chain-Q6CmDc", 4 | "initial_height": "0", 5 | "consensus_params": { 6 | "block": { 7 | "max_bytes": "22020096", 8 | "max_gas": "-1" 9 | }, 10 | "evidence": { 11 | "max_age_num_blocks": "100000", 12 | "max_age_duration": "172800000000000", 13 | "max_bytes": "1048576" 14 | }, 15 | "validator": { 16 | "pub_key_types": [ 17 | "ed25519" 18 | ] 19 | }, 20 | "version": { 21 | "app_version": "0" 22 | } 23 | }, 24 | "validators": [ 25 | { 26 | "address": "11BB132EC77BC788B65CEAE309A21EC9AD30686C", 27 | "pub_key": { 28 | "type": "tendermint/PubKeyEd25519", 29 | "value": "XGZrm1htSmuI3+fhsu8+VxOuPGbqubdE13gVbhIHe1Q=" 30 | }, 31 | "power": "1", 32 | "name": "node0" 33 | }, 34 | { 35 | "address": "7CCF8D79D6B7ED4B0FACFD4C3C1FA547DEA0E5CD", 36 | "pub_key": { 37 | "type": "tendermint/PubKeyEd25519", 38 | "value": "IiiA7W0pkTGnIFi/zqIHjfgMt/1gLZUwo/Bt6L8F6Ms=" 39 | }, 40 | "power": "1", 41 | "name": "node1" 42 | }, 43 | { 44 | "address": "C06DF36A9325CAA700406E1404E777D3DE7533B2", 45 | "pub_key": { 46 | "type": "tendermint/PubKeyEd25519", 47 | "value": "ZXuG6/FObVz4mhCpKwPHi6R/ZnehI/t+Xww74DX56II=" 48 | }, 49 | "power": "1", 50 | "name": "node2" 51 | }, 52 | { 53 | "address": "92544D338AB5935A8F6D4CE3953546FB6B0368C5", 54 | "pub_key": { 55 | "type": "tendermint/PubKeyEd25519", 56 | "value": "/tirj7G+lHmiZ/L94DVoXDwBhC7bqPv4zoVS7Rlau8E=" 57 | }, 58 | "power": "1", 59 | "name": "node3" 60 | } 61 | ], 62 | "app_hash": "" 63 | } -------------------------------------------------------------------------------- /DOCKER/testnet/node2/config/genesis.json: -------------------------------------------------------------------------------- 1 | { 2 | "genesis_time": "2022-06-07T07:19:27.620807337Z", 3 | "chain_id": "chain-Q6CmDc", 4 | "initial_height": "0", 5 | "consensus_params": { 6 | "block": { 7 | "max_bytes": "22020096", 8 | "max_gas": "-1" 9 | }, 10 | "evidence": { 11 | "max_age_num_blocks": "100000", 12 | "max_age_duration": "172800000000000", 13 | "max_bytes": "1048576" 14 | }, 15 | "validator": { 16 | "pub_key_types": [ 17 | "ed25519" 18 | ] 19 | }, 20 | "version": { 21 | "app_version": "0" 22 | } 23 | }, 24 | "validators": [ 25 | { 26 | "address": "11BB132EC77BC788B65CEAE309A21EC9AD30686C", 27 | "pub_key": { 28 | "type": "tendermint/PubKeyEd25519", 29 | "value": "XGZrm1htSmuI3+fhsu8+VxOuPGbqubdE13gVbhIHe1Q=" 30 | }, 31 | "power": "1", 32 | "name": "node0" 33 | }, 34 | { 35 | "address": "7CCF8D79D6B7ED4B0FACFD4C3C1FA547DEA0E5CD", 36 | "pub_key": { 37 | "type": "tendermint/PubKeyEd25519", 38 | "value": "IiiA7W0pkTGnIFi/zqIHjfgMt/1gLZUwo/Bt6L8F6Ms=" 39 | }, 40 | "power": "1", 41 | "name": "node1" 42 | }, 43 | { 44 | "address": "C06DF36A9325CAA700406E1404E777D3DE7533B2", 45 | "pub_key": { 46 | "type": "tendermint/PubKeyEd25519", 47 | "value": "ZXuG6/FObVz4mhCpKwPHi6R/ZnehI/t+Xww74DX56II=" 48 | }, 49 | "power": "1", 50 | "name": "node2" 51 | }, 52 | { 53 | "address": "92544D338AB5935A8F6D4CE3953546FB6B0368C5", 54 | "pub_key": { 55 | "type": "tendermint/PubKeyEd25519", 56 | "value": "/tirj7G+lHmiZ/L94DVoXDwBhC7bqPv4zoVS7Rlau8E=" 57 | }, 58 | "power": "1", 59 | "name": "node3" 60 | } 61 | ], 62 | "app_hash": "" 63 | } -------------------------------------------------------------------------------- /DOCKER/testnet/node3/config/genesis.json: -------------------------------------------------------------------------------- 1 | { 2 | "genesis_time": "2022-06-07T07:19:27.620807337Z", 3 | "chain_id": "chain-Q6CmDc", 4 | "initial_height": "0", 5 | "consensus_params": { 6 | "block": { 7 | "max_bytes": "22020096", 8 | "max_gas": "-1" 9 | }, 10 | "evidence": { 11 | "max_age_num_blocks": "100000", 12 | "max_age_duration": "172800000000000", 13 | "max_bytes": "1048576" 14 | }, 15 | "validator": { 16 | "pub_key_types": [ 17 | "ed25519" 18 | ] 19 | }, 20 | "version": { 21 | "app_version": "0" 22 | } 23 | }, 24 | "validators": [ 25 | { 26 | "address": "11BB132EC77BC788B65CEAE309A21EC9AD30686C", 27 | "pub_key": { 28 | "type": "tendermint/PubKeyEd25519", 29 | "value": "XGZrm1htSmuI3+fhsu8+VxOuPGbqubdE13gVbhIHe1Q=" 30 | }, 31 | "power": "1", 32 | "name": "node0" 33 | }, 34 | { 35 | "address": "7CCF8D79D6B7ED4B0FACFD4C3C1FA547DEA0E5CD", 36 | "pub_key": { 37 | "type": "tendermint/PubKeyEd25519", 38 | "value": "IiiA7W0pkTGnIFi/zqIHjfgMt/1gLZUwo/Bt6L8F6Ms=" 39 | }, 40 | "power": "1", 41 | "name": "node1" 42 | }, 43 | { 44 | "address": "C06DF36A9325CAA700406E1404E777D3DE7533B2", 45 | "pub_key": { 46 | "type": "tendermint/PubKeyEd25519", 47 | "value": "ZXuG6/FObVz4mhCpKwPHi6R/ZnehI/t+Xww74DX56II=" 48 | }, 49 | "power": "1", 50 | "name": "node2" 51 | }, 52 | { 53 | "address": "92544D338AB5935A8F6D4CE3953546FB6B0368C5", 54 | "pub_key": { 55 | "type": "tendermint/PubKeyEd25519", 56 | "value": "/tirj7G+lHmiZ/L94DVoXDwBhC7bqPv4zoVS7Rlau8E=" 57 | }, 58 | "power": "1", 59 | "name": "node3" 60 | } 61 | ], 62 | "app_hash": "" 63 | } -------------------------------------------------------------------------------- /Phantasma.Infrastructure/src/API/Controllers/PlatformController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Phantasma.Core; 6 | using Serilog; 7 | 8 | namespace Phantasma.Infrastructure.Controllers 9 | { 10 | public class PlatformController : BaseControllerV1 11 | { 12 | [APIInfo(typeof(PlatformResult[]), "Returns an array of available interop platforms.", false, 300)] 13 | [HttpGet("GetPlatforms")] 14 | public PlatformResult[] GetPlatforms() 15 | { 16 | var platformList = new List(); 17 | 18 | var nexus = NexusAPI.GetNexus(); 19 | 20 | var platforms = nexus.GetPlatforms(nexus.RootStorage); 21 | var symbols = nexus.GetTokens(nexus.RootStorage); 22 | 23 | foreach (var platform in platforms) 24 | { 25 | var info = nexus.GetPlatformInfo(nexus.RootStorage, platform); 26 | var entry = new PlatformResult(); 27 | entry.platform = platform; 28 | entry.interop = info.InteropAddresses.Select(x => new InteropResult() 29 | { 30 | local = x.LocalAddress.Text, 31 | external = x.ExternalAddress 32 | }).Reverse().ToArray(); 33 | //TODO reverse array for now, only the last item is valid for now. 34 | entry.chain = DomainExtensions.GetChainAddress(info).Text; 35 | entry.fuel = info.Symbol; 36 | entry.tokens = symbols.Where(x => nexus.HasTokenPlatformHash(x, platform, nexus.RootStorage)).ToArray(); 37 | platformList.Add(entry); 38 | } 39 | 40 | return platformList.ToArray(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node0/config/genesis.json: -------------------------------------------------------------------------------- 1 | { 2 | "genesis_time": "2022-06-07T07:19:27.620807337Z", 3 | "chain_id": "chain-Q6CmDc", 4 | "initial_height": "0", 5 | "consensus_params": { 6 | "block": { 7 | "max_bytes": "22020096", 8 | "max_gas": "-1" 9 | }, 10 | "evidence": { 11 | "max_age_num_blocks": "100000", 12 | "max_age_duration": "172800000000000", 13 | "max_bytes": "1048576" 14 | }, 15 | "validator": { 16 | "pub_key_types": [ 17 | "ed25519" 18 | ] 19 | }, 20 | "version": { 21 | "app_version": "0" 22 | } 23 | }, 24 | "validators": [ 25 | { 26 | "address": "11BB132EC77BC788B65CEAE309A21EC9AD30686C", 27 | "pub_key": { 28 | "type": "tendermint/PubKeyEd25519", 29 | "value": "XGZrm1htSmuI3+fhsu8+VxOuPGbqubdE13gVbhIHe1Q=" 30 | }, 31 | "power": "1", 32 | "name": "node0" 33 | }, 34 | { 35 | "address": "7CCF8D79D6B7ED4B0FACFD4C3C1FA547DEA0E5CD", 36 | "pub_key": { 37 | "type": "tendermint/PubKeyEd25519", 38 | "value": "IiiA7W0pkTGnIFi/zqIHjfgMt/1gLZUwo/Bt6L8F6Ms=" 39 | }, 40 | "power": "1", 41 | "name": "node1" 42 | }, 43 | { 44 | "address": "C06DF36A9325CAA700406E1404E777D3DE7533B2", 45 | "pub_key": { 46 | "type": "tendermint/PubKeyEd25519", 47 | "value": "ZXuG6/FObVz4mhCpKwPHi6R/ZnehI/t+Xww74DX56II=" 48 | }, 49 | "power": "1", 50 | "name": "node2" 51 | }, 52 | { 53 | "address": "92544D338AB5935A8F6D4CE3953546FB6B0368C5", 54 | "pub_key": { 55 | "type": "tendermint/PubKeyEd25519", 56 | "value": "/tirj7G+lHmiZ/L94DVoXDwBhC7bqPv4zoVS7Rlau8E=" 57 | }, 58 | "power": "1", 59 | "name": "node3" 60 | } 61 | ], 62 | "app_hash": "" 63 | } -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node1/config/genesis.json: -------------------------------------------------------------------------------- 1 | { 2 | "genesis_time": "2022-06-07T07:19:27.620807337Z", 3 | "chain_id": "chain-Q6CmDc", 4 | "initial_height": "0", 5 | "consensus_params": { 6 | "block": { 7 | "max_bytes": "22020096", 8 | "max_gas": "-1" 9 | }, 10 | "evidence": { 11 | "max_age_num_blocks": "100000", 12 | "max_age_duration": "172800000000000", 13 | "max_bytes": "1048576" 14 | }, 15 | "validator": { 16 | "pub_key_types": [ 17 | "ed25519" 18 | ] 19 | }, 20 | "version": { 21 | "app_version": "0" 22 | } 23 | }, 24 | "validators": [ 25 | { 26 | "address": "11BB132EC77BC788B65CEAE309A21EC9AD30686C", 27 | "pub_key": { 28 | "type": "tendermint/PubKeyEd25519", 29 | "value": "XGZrm1htSmuI3+fhsu8+VxOuPGbqubdE13gVbhIHe1Q=" 30 | }, 31 | "power": "1", 32 | "name": "node0" 33 | }, 34 | { 35 | "address": "7CCF8D79D6B7ED4B0FACFD4C3C1FA547DEA0E5CD", 36 | "pub_key": { 37 | "type": "tendermint/PubKeyEd25519", 38 | "value": "IiiA7W0pkTGnIFi/zqIHjfgMt/1gLZUwo/Bt6L8F6Ms=" 39 | }, 40 | "power": "1", 41 | "name": "node1" 42 | }, 43 | { 44 | "address": "C06DF36A9325CAA700406E1404E777D3DE7533B2", 45 | "pub_key": { 46 | "type": "tendermint/PubKeyEd25519", 47 | "value": "ZXuG6/FObVz4mhCpKwPHi6R/ZnehI/t+Xww74DX56II=" 48 | }, 49 | "power": "1", 50 | "name": "node2" 51 | }, 52 | { 53 | "address": "92544D338AB5935A8F6D4CE3953546FB6B0368C5", 54 | "pub_key": { 55 | "type": "tendermint/PubKeyEd25519", 56 | "value": "/tirj7G+lHmiZ/L94DVoXDwBhC7bqPv4zoVS7Rlau8E=" 57 | }, 58 | "power": "1", 59 | "name": "node3" 60 | } 61 | ], 62 | "app_hash": "" 63 | } -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node2/config/genesis.json: -------------------------------------------------------------------------------- 1 | { 2 | "genesis_time": "2022-06-07T07:19:27.620807337Z", 3 | "chain_id": "chain-Q6CmDc", 4 | "initial_height": "0", 5 | "consensus_params": { 6 | "block": { 7 | "max_bytes": "22020096", 8 | "max_gas": "-1" 9 | }, 10 | "evidence": { 11 | "max_age_num_blocks": "100000", 12 | "max_age_duration": "172800000000000", 13 | "max_bytes": "1048576" 14 | }, 15 | "validator": { 16 | "pub_key_types": [ 17 | "ed25519" 18 | ] 19 | }, 20 | "version": { 21 | "app_version": "0" 22 | } 23 | }, 24 | "validators": [ 25 | { 26 | "address": "11BB132EC77BC788B65CEAE309A21EC9AD30686C", 27 | "pub_key": { 28 | "type": "tendermint/PubKeyEd25519", 29 | "value": "XGZrm1htSmuI3+fhsu8+VxOuPGbqubdE13gVbhIHe1Q=" 30 | }, 31 | "power": "1", 32 | "name": "node0" 33 | }, 34 | { 35 | "address": "7CCF8D79D6B7ED4B0FACFD4C3C1FA547DEA0E5CD", 36 | "pub_key": { 37 | "type": "tendermint/PubKeyEd25519", 38 | "value": "IiiA7W0pkTGnIFi/zqIHjfgMt/1gLZUwo/Bt6L8F6Ms=" 39 | }, 40 | "power": "1", 41 | "name": "node1" 42 | }, 43 | { 44 | "address": "C06DF36A9325CAA700406E1404E777D3DE7533B2", 45 | "pub_key": { 46 | "type": "tendermint/PubKeyEd25519", 47 | "value": "ZXuG6/FObVz4mhCpKwPHi6R/ZnehI/t+Xww74DX56II=" 48 | }, 49 | "power": "1", 50 | "name": "node2" 51 | }, 52 | { 53 | "address": "92544D338AB5935A8F6D4CE3953546FB6B0368C5", 54 | "pub_key": { 55 | "type": "tendermint/PubKeyEd25519", 56 | "value": "/tirj7G+lHmiZ/L94DVoXDwBhC7bqPv4zoVS7Rlau8E=" 57 | }, 58 | "power": "1", 59 | "name": "node3" 60 | } 61 | ], 62 | "app_hash": "" 63 | } -------------------------------------------------------------------------------- /Phantasma.Node/testnet/node3/config/genesis.json: -------------------------------------------------------------------------------- 1 | { 2 | "genesis_time": "2022-06-07T07:19:27.620807337Z", 3 | "chain_id": "chain-Q6CmDc", 4 | "initial_height": "0", 5 | "consensus_params": { 6 | "block": { 7 | "max_bytes": "22020096", 8 | "max_gas": "-1" 9 | }, 10 | "evidence": { 11 | "max_age_num_blocks": "100000", 12 | "max_age_duration": "172800000000000", 13 | "max_bytes": "1048576" 14 | }, 15 | "validator": { 16 | "pub_key_types": [ 17 | "ed25519" 18 | ] 19 | }, 20 | "version": { 21 | "app_version": "0" 22 | } 23 | }, 24 | "validators": [ 25 | { 26 | "address": "11BB132EC77BC788B65CEAE309A21EC9AD30686C", 27 | "pub_key": { 28 | "type": "tendermint/PubKeyEd25519", 29 | "value": "XGZrm1htSmuI3+fhsu8+VxOuPGbqubdE13gVbhIHe1Q=" 30 | }, 31 | "power": "1", 32 | "name": "node0" 33 | }, 34 | { 35 | "address": "7CCF8D79D6B7ED4B0FACFD4C3C1FA547DEA0E5CD", 36 | "pub_key": { 37 | "type": "tendermint/PubKeyEd25519", 38 | "value": "IiiA7W0pkTGnIFi/zqIHjfgMt/1gLZUwo/Bt6L8F6Ms=" 39 | }, 40 | "power": "1", 41 | "name": "node1" 42 | }, 43 | { 44 | "address": "C06DF36A9325CAA700406E1404E777D3DE7533B2", 45 | "pub_key": { 46 | "type": "tendermint/PubKeyEd25519", 47 | "value": "ZXuG6/FObVz4mhCpKwPHi6R/ZnehI/t+Xww74DX56II=" 48 | }, 49 | "power": "1", 50 | "name": "node2" 51 | }, 52 | { 53 | "address": "92544D338AB5935A8F6D4CE3953546FB6B0368C5", 54 | "pub_key": { 55 | "type": "tendermint/PubKeyEd25519", 56 | "value": "/tirj7G+lHmiZ/L94DVoXDwBhC7bqPv4zoVS7Rlau8E=" 57 | }, 58 | "power": "1", 59 | "name": "node3" 60 | } 61 | ], 62 | "app_hash": "" 63 | } -------------------------------------------------------------------------------- /Tendermint.RPC/src/Endpoint/Block.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Tendermint.RPC.Endpoint 7 | { 8 | public class BlockRequestArguments 9 | { 10 | [JsonProperty("height")] 11 | public long Height { get; set; } 12 | } 13 | 14 | /* 15 | Get block at a given height. If no height is provided, it will fetch the latest block. 16 | 17 | Query Parameters 18 | Parameter Type Default Required Description 19 | height int64 false false height of blockchain 20 | Return Type: 21 | 22 | type ResultBlock struct { 23 | BlockMeta *types.BlockMeta 24 | Block *types.Block 25 | } 26 | // BlockMeta contains meta information about a block - namely, it's ID and Header. 27 | type BlockMeta struct { 28 | BlockID BlockID 29 | Header Header 30 | } 31 | // Block defines the atomic unit of a Tendermint blockchain. 32 | type Block struct { 33 | mtx sync.Mutex 34 | Header `json:"header"` 35 | Data `json:"data"` 36 | Evidence EvidenceData 37 | LastCommit *Commit 38 | } 39 | */ 40 | 41 | public class BlockMeta 42 | { 43 | [JsonProperty("block_Id")] 44 | public BlockId BlockId { get; set; } 45 | 46 | [JsonProperty("header")] 47 | public BlockHeader Header { get; set; } 48 | } 49 | 50 | public class ResultBlock : IEndpointResponse 51 | { 52 | [JsonProperty("block_meta")] 53 | public BlockMeta BlockMeta { get; set; } 54 | 55 | [JsonProperty("block")] 56 | public Block Block { get; set; } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/types/canonical.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.types; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | import "tendermint/types/types.proto"; 8 | import "google/protobuf/timestamp.proto"; 9 | 10 | message CanonicalBlockID { 11 | bytes hash = 1; 12 | CanonicalPartSetHeader part_set_header = 2 [(gogoproto.nullable) = false]; 13 | } 14 | 15 | message CanonicalPartSetHeader { 16 | uint32 total = 1; 17 | bytes hash = 2; 18 | } 19 | 20 | message CanonicalProposal { 21 | SignedMsgType type = 1; // type alias for byte 22 | sfixed64 height = 2; // canonicalization requires fixed size encoding here 23 | sfixed64 round = 3; // canonicalization requires fixed size encoding here 24 | int64 pol_round = 4 [(gogoproto.customname) = "POLRound"]; 25 | CanonicalBlockID block_id = 5 [(gogoproto.customname) = "BlockID"]; 26 | google.protobuf.Timestamp timestamp = 6 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; 27 | string chain_id = 7 [(gogoproto.customname) = "ChainID"]; 28 | } 29 | 30 | message CanonicalVote { 31 | SignedMsgType type = 1; // type alias for byte 32 | sfixed64 height = 2; // canonicalization requires fixed size encoding here 33 | sfixed64 round = 3; // canonicalization requires fixed size encoding here 34 | CanonicalBlockID block_id = 4 [(gogoproto.customname) = "BlockID"]; 35 | google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; 36 | string chain_id = 6 [(gogoproto.customname) = "ChainID"]; 37 | } 38 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/OracleFeed.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace Phantasma.Core 4 | { 5 | public struct OracleFeed: IFeed, ISerializable 6 | { 7 | public string Name { get; private set; } 8 | public Address Address { get; private set; } 9 | public FeedMode Mode { get; private set; } 10 | 11 | public OracleFeed(string name, Address address, FeedMode mode) 12 | { 13 | Name = name; 14 | Address = address; 15 | Mode = mode; 16 | } 17 | 18 | public void SerializeData(BinaryWriter writer) 19 | { 20 | writer.WriteVarString(Name); 21 | writer.WriteAddress(Address); 22 | writer.Write((byte)Mode); 23 | } 24 | 25 | public void UnserializeData(BinaryReader reader) 26 | { 27 | Name = reader.ReadVarString(); 28 | Address = reader.ReadAddress(); 29 | Mode = (FeedMode)reader.ReadByte(); 30 | } 31 | 32 | public byte[] ToByteArray() 33 | { 34 | using (var stream = new MemoryStream()) 35 | { 36 | using (var writer = new BinaryWriter(stream)) 37 | { 38 | SerializeData(writer); 39 | } 40 | 41 | return stream.ToArray(); 42 | } 43 | } 44 | 45 | public static OracleFeed Unserialize(byte[] bytes) 46 | { 47 | using (var stream = new MemoryStream(bytes)) 48 | { 49 | using (var reader = new BinaryReader(stream)) 50 | { 51 | var entity = new OracleFeed(); 52 | entity.UnserializeData(reader); 53 | return entity; 54 | } 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Phantasma.Node/Middleware/ErrorLoggingMiddleware.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Text.Json; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.Extensions.Logging; 7 | using Phantasma.Core; 8 | using Phantasma.Infrastructure; 9 | 10 | namespace Phantasma.Node.Middleware; 11 | 12 | public class ErrorLoggingMiddleware 13 | { 14 | private readonly ILogger _logger; 15 | private readonly RequestDelegate _next; 16 | 17 | public ErrorLoggingMiddleware(RequestDelegate next, ILogger logger) 18 | { 19 | _next = next; 20 | _logger = logger; 21 | } 22 | 23 | public async Task Invoke(HttpContext httpContext) 24 | { 25 | var path = httpContext.Request.Path; 26 | 27 | try 28 | { 29 | await _next(httpContext); 30 | } 31 | catch (APIException e) 32 | { 33 | // If there is no inner exception, it is likely just a field validation error so we won't log it 34 | if (e.InnerException != null) 35 | { 36 | _logger.LogError(e, "APIException exception caught: {Path}", path); 37 | } 38 | 39 | var body = JsonSerializer.Serialize(new ErrorResult { error = e.InnerException != null ? e.ToString() : e.Message }, 40 | new JsonSerializerOptions { IncludeFields = true }); 41 | var response = Encoding.UTF8.GetBytes(body); 42 | httpContext.Response.ContentType = "application/json; charset=utf-8"; 43 | await httpContext.Response.Body.WriteAsync(response); 44 | } 45 | catch (Exception e) 46 | { 47 | _logger.LogCritical(e, "Unexpected exception caught: {Path}", path); 48 | 49 | throw; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Nodes/UnaryExpressionNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Phantasma.Business.Core.Nodes 6 | { 7 | public class UnaryExpressionNode : ExpressionNode 8 | { 9 | public string op; 10 | public ExpressionNode term; 11 | 12 | public UnaryExpressionNode(CompilerNode owner) : base(owner) 13 | { 14 | } 15 | 16 | public override string ToString() 17 | { 18 | return base.ToString() + "=>" + this.op; 19 | } 20 | 21 | public override IEnumerable Nodes 22 | { 23 | get 24 | { 25 | yield return term; 26 | yield break; 27 | } 28 | } 29 | 30 | public override List Emit(Compiler compiler) 31 | { 32 | Instruction.Opcode opcode; 33 | switch (this.op) 34 | { 35 | case "+": opcode = Instruction.Opcode.Add; break; 36 | case "-": opcode = Instruction.Opcode.Sub; break; 37 | case "!": opcode = Instruction.Opcode.Not; break; 38 | case "++": opcode = Instruction.Opcode.Inc; break; 39 | case "--": opcode = Instruction.Opcode.Dec; break; 40 | default: throw new ArgumentException("Invalid opcode: " + op); 41 | } 42 | 43 | var temp = this.term.Emit(compiler); 44 | temp.Add(new Instruction() { source = this, target = compiler.AllocRegister(), a = temp.Last(), op = opcode }); 45 | return temp; 46 | } 47 | 48 | public override TypeKind GetKind() 49 | { 50 | if (op == "!") 51 | { 52 | return TypeKind.Boolean; 53 | } 54 | 55 | return TypeKind.Integer; 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /Phantasma.Node/Swagger/SwaggerExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.OpenApi.Models; 3 | 4 | namespace Phantasma.Node.Swagger; 5 | 6 | public static class SwaggerExtensions 7 | { 8 | public static IEnumerable FindAdditionalSchema(this OpenApiSchema schema, 9 | IDictionary listOfDefinition) 10 | { 11 | if (!string.IsNullOrEmpty(schema?.Reference?.ReferenceV2)) 12 | { 13 | OpenApiSchema definition; 14 | if (listOfDefinition.TryGetValue(schema.Reference.Id, out definition)) 15 | foreach (var propertySchema in definition.Properties) 16 | yield return propertySchema.Value; 17 | } 18 | 19 | if (!string.IsNullOrEmpty(schema?.Items?.Reference?.Id)) 20 | { 21 | OpenApiSchema definition; 22 | if (listOfDefinition.TryGetValue(schema.Items.Reference.Id, out definition)) 23 | foreach (var propertySchema in definition.Properties) 24 | yield return propertySchema.Value; 25 | } 26 | } 27 | 28 | public static IEnumerable EnumerateSchema(this OpenApiSchema schema, 29 | IDictionary listOfDefinition, int dept = 0) 30 | { 31 | if (schema == null) yield break; 32 | if (dept > 64) yield break; 33 | if (dept == 0) yield return schema; 34 | 35 | var listOfAdditionalSchema = schema.FindAdditionalSchema(listOfDefinition) ?? new List(); 36 | foreach (var additionalSchema in listOfAdditionalSchema) 37 | { 38 | yield return additionalSchema; 39 | foreach (var childSchema in additionalSchema.EnumerateSchema(listOfDefinition, dept++) ?? 40 | new List()) 41 | yield return childSchema; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Phantasma.Business/src/CodeGen/Core/Compiler.cs: -------------------------------------------------------------------------------- 1 | using Phantasma.Business.Core.Nodes; 2 | using System.Collections.Generic; 3 | 4 | namespace Phantasma.Business.Core 5 | { 6 | public class Compiler 7 | { 8 | private int registerIndex; 9 | private int labelIndex; 10 | 11 | public Dictionary varMap = new Dictionary(); 12 | 13 | public string AllocRegister() 14 | { 15 | var temp = "t"+registerIndex.ToString(); 16 | registerIndex++; 17 | return temp; 18 | } 19 | 20 | 21 | public string AllocLabel() 22 | { 23 | var temp = "p"+labelIndex.ToString(); 24 | labelIndex++; 25 | return temp; 26 | } 27 | 28 | private void ProcessBlock(List instructions, BlockNode block) 29 | { 30 | foreach (var st in block.statements) 31 | { 32 | var list = st.Emit(this); 33 | 34 | foreach (var item in list) 35 | { 36 | instructions.Add(item); 37 | } 38 | } 39 | } 40 | 41 | public List Execute(ModuleNode node) 42 | { 43 | var instructions = new List(); 44 | 45 | if (node.body != null) 46 | { 47 | var temp = node.body.Emit(this); 48 | instructions.AddRange(temp); 49 | } 50 | 51 | labelIndex = 0; 52 | registerIndex = 0; 53 | foreach (var entry in node.classes) 54 | { 55 | foreach (var method in entry.methods) 56 | { 57 | var temp = method.Emit(this); 58 | instructions.AddRange(temp); 59 | } 60 | } 61 | 62 | return instructions; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Phantasma.Tests/Phantasma.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netcoreapp3.1 4 | Phantasma.Tests 5 | 40 6 | C:\code\PhantasmaSpook\Backup\Phantasma.Tests\ 7 | Current 8 | 9 | 10 | false 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Storage/Context/StorageValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Phantasma.Core.Context 4 | { 5 | public struct StorageValue : IStorageCollection 6 | { 7 | public StorageValue(byte[] baseKey, StorageContext context) : this() 8 | { 9 | BaseKey = baseKey; 10 | Context = context; 11 | } 12 | 13 | public byte[] BaseKey { get; } 14 | public StorageContext Context { get; } 15 | } 16 | 17 | public static class ValueUtils 18 | { 19 | public static void Set(this StorageValue value, T element) 20 | { 21 | byte[] bytes; 22 | if (typeof(IStorageCollection).IsAssignableFrom(typeof(T))) 23 | { 24 | var collection = (IStorageCollection)element; 25 | //bytes = MergeKey(map.BaseKey, key); 26 | bytes = collection.BaseKey; 27 | } 28 | else 29 | { 30 | bytes = Serialization.Serialize(element); 31 | } 32 | 33 | value.Context.Put(value.BaseKey, bytes); 34 | } 35 | 36 | public static T Get(this StorageValue value) 37 | { 38 | var bytes = value.Context.Get(value.BaseKey); 39 | 40 | if (typeof(IStorageCollection).IsAssignableFrom(typeof(T))) 41 | { 42 | var args = new object[] { bytes, value.Context }; 43 | var obj = (T)Activator.CreateInstance(typeof(T), args); 44 | return obj; 45 | } 46 | else 47 | { 48 | return Serialization.Unserialize(bytes); 49 | } 50 | } 51 | 52 | public static bool HasValue(this StorageValue value) 53 | { 54 | return value.Context.Has(value.BaseKey); 55 | } 56 | 57 | public static void Clear(this StorageValue value) 58 | { 59 | value.Context.Delete(value.BaseKey); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Phantasma.Business/src/Blockchain/Contracts/FriendContract.cs: -------------------------------------------------------------------------------- 1 | using Phantasma.Core; 2 | using Phantasma.Core.Context; 3 | 4 | namespace Phantasma.Business.Contracts 5 | { 6 | public sealed class FriendsContract : NativeContract 7 | { 8 | public override NativeContractKind Kind => NativeContractKind.Friends; 9 | 10 | public static readonly int FRIEND_LIMIT_PER_ACCOUNT = 100; 11 | 12 | #pragma warning disable 0649 13 | internal StorageMap _friendMap; 14 | #pragma warning restore 0649 15 | 16 | #region FRIENDLIST 17 | public void AddFriend(Address target, Address friend) 18 | { 19 | Runtime.Expect(Runtime.IsWitness(target), "invalid witness"); 20 | 21 | Runtime.Expect(friend.IsUser, "friend must be user addres"); 22 | Runtime.Expect(friend != target, "friend must be different from target address"); 23 | 24 | var friendList = _friendMap.Get(target); 25 | Runtime.Expect(friendList.Count() < FRIEND_LIMIT_PER_ACCOUNT, "friend limit reached"); 26 | Runtime.Expect(!friendList.Contains(friend), "already is friend"); 27 | 28 | friendList.Add(friend); 29 | 30 | Runtime.Notify(EventKind.AddressLink, target, friend); 31 | } 32 | 33 | public void RemoveFriend(Address target, Address friend) 34 | { 35 | Runtime.Expect(Runtime.IsWitness(target), "invalid witness"); 36 | 37 | var friendList = _friendMap.Get(target); 38 | 39 | Runtime.Expect(friendList.Contains(friend), "friend not found"); 40 | friendList.Remove(friend); 41 | 42 | Runtime.Notify(EventKind.AddressUnlink, target, friend); 43 | } 44 | 45 | public Address[] GetFriends(Address target) 46 | { 47 | var friendList = _friendMap.Get(target); 48 | return friendList.All
(); 49 | } 50 | #endregion 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/Exceptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | //TODO 4 | namespace Phantasma.Core 5 | { 6 | public class ChainException : Exception 7 | { 8 | public ChainException(string msg) : base(msg) 9 | { 10 | 11 | } 12 | } 13 | 14 | public class ContractException : Exception 15 | { 16 | public ContractException(string msg) : base(msg) 17 | { 18 | 19 | } 20 | } 21 | 22 | public class ArchiveException : Exception 23 | { 24 | public ArchiveException(string msg) : base(msg) 25 | { 26 | 27 | } 28 | } 29 | 30 | public class RelayException : Exception 31 | { 32 | public RelayException(string msg) : base(msg) 33 | { 34 | 35 | } 36 | } 37 | 38 | public class OracleException : Exception 39 | { 40 | public OracleException(string msg) : base(msg) 41 | { 42 | 43 | } 44 | } 45 | 46 | public class SwapException : Exception 47 | { 48 | public SwapException(string msg) : base(msg) 49 | { 50 | 51 | } 52 | } 53 | 54 | public class NodeException : Exception 55 | { 56 | public NodeException(string msg) : base(msg) 57 | { 58 | 59 | } 60 | } 61 | 62 | 63 | public class BlockGenerationException : Exception 64 | { 65 | public BlockGenerationException(string msg) : base(msg) 66 | { 67 | 68 | } 69 | } 70 | 71 | public class DuplicatedTransactionException : Exception 72 | { 73 | public readonly Hash Hash; 74 | 75 | public DuplicatedTransactionException(Hash hash, string msg) : base(msg) 76 | { 77 | this.Hash = hash; 78 | } 79 | } 80 | 81 | public class InvalidTransactionException : Exception 82 | { 83 | public readonly Hash Hash; 84 | 85 | public InvalidTransactionException(Hash hash, string msg) : base(msg) 86 | { 87 | this.Hash = hash; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Phantasma.Infrastructure/src/Pay/WalletUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Phantasma.Infrastructure.Chains; 3 | 4 | namespace Phantasma.Infrastructure 5 | { 6 | public static class WalletUtils 7 | { 8 | /* 9 | public static void DecodePlatformAndAddress(Address source, out byte platformID, out string address) 10 | { 11 | byte[] bytes; 12 | 13 | source.DecodeInterop(out platform, out bytes, 0); 14 | 15 | switch (platform) 16 | { 17 | case NeoWallet.NeoPlatform: 18 | address = NeoWallet.DecodeAddress(source); 19 | break; 20 | 21 | case EthereumWallet.EthereumPlatform: 22 | address = EthereumWallet.DecodeAddress(source); 23 | break; 24 | 25 | default: 26 | throw new NotImplementedException($"cannot decode addresses for {platform} chain"); 27 | } 28 | }*/ 29 | 30 | /* public static Address EncodeAddress(string source, string chainName) 31 | { 32 | switch (chainName) 33 | { 34 | case NeoWallet.NeoPlatform: 35 | return NeoWallet.EncodeAddress(source); 36 | 37 | case EthereumWallet.EthereumPlatform: 38 | return NeoWallet.EncodeAddress(source); 39 | 40 | default: 41 | throw new NotImplementedException($"cannot encode addresses for {chainName} chain"); 42 | } 43 | }*/ 44 | 45 | public static string GetPlatformByID(byte platformID) 46 | { 47 | switch (platformID) 48 | { 49 | case 0: return PhantasmaWallet.PhantasmaPlatform; 50 | case 1: return NeoWallet.NeoPlatform; 51 | case 2: return EthereumWallet.EthereumPlatform; 52 | default: throw new NotImplementedException(); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Phantasma.Node/Oracles/CoinGecko.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using Phantasma.Shared.Utils; 4 | using Serilog; 5 | 6 | namespace Phantasma.Node.Oracles 7 | { 8 | public static class CoinGeckoUtils 9 | { 10 | public static decimal GetCoinRate(string baseSymbol, string quoteSymbol, PricerSupportedToken[] supportedTokens) 11 | { 12 | string baseticker = ""; 13 | 14 | foreach (var token in supportedTokens) 15 | { 16 | if(token.ticker == baseSymbol) 17 | { 18 | baseticker = token.coingeckoId; 19 | break; 20 | } 21 | } 22 | 23 | if (String.IsNullOrEmpty(baseticker)) 24 | return 0; 25 | 26 | // hack for goati price .10 27 | if (baseticker == "GOATI") 28 | { 29 | var price = 0.10m; 30 | return price; 31 | } 32 | 33 | var url = $"https://api.coingecko.com/api/v3/simple/price?ids={baseticker}&vs_currencies={quoteSymbol}"; 34 | 35 | try 36 | { 37 | var response = RequestUtils.Request(RequestType.GET, url, out var _); 38 | 39 | if (response == null) 40 | return 0; 41 | 42 | if(!response.RootElement.TryGetProperty(baseticker, out var baseTickerProperty)) 43 | { 44 | return 0; 45 | } 46 | if(baseTickerProperty.TryGetProperty(quoteSymbol.ToLower(), out var priceProperty)) 47 | { 48 | return priceProperty.GetDecimal(); 49 | } 50 | return 0; 51 | } 52 | catch (Exception ex) 53 | { 54 | var errorMsg = ex.Message; 55 | Log.Error($"Error while trying to query {baseticker} price from CoinGecko API: {errorMsg}"); 56 | return 0; 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Tendermint/proto/tendermint/consensus/message.go: -------------------------------------------------------------------------------- 1 | package consensus 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/gogo/protobuf/proto" 7 | ) 8 | 9 | // Wrap implements the p2p Wrapper interface and wraps a consensus proto message. 10 | func (m *Message) Wrap(pb proto.Message) error { 11 | switch msg := pb.(type) { 12 | case *NewRoundStep: 13 | m.Sum = &Message_NewRoundStep{NewRoundStep: msg} 14 | 15 | case *NewValidBlock: 16 | m.Sum = &Message_NewValidBlock{NewValidBlock: msg} 17 | 18 | case *Proposal: 19 | m.Sum = &Message_Proposal{Proposal: msg} 20 | 21 | case *ProposalPOL: 22 | m.Sum = &Message_ProposalPol{ProposalPol: msg} 23 | 24 | case *BlockPart: 25 | m.Sum = &Message_BlockPart{BlockPart: msg} 26 | 27 | case *Vote: 28 | m.Sum = &Message_Vote{Vote: msg} 29 | 30 | case *HasVote: 31 | m.Sum = &Message_HasVote{HasVote: msg} 32 | 33 | case *VoteSetMaj23: 34 | m.Sum = &Message_VoteSetMaj23{VoteSetMaj23: msg} 35 | 36 | case *VoteSetBits: 37 | m.Sum = &Message_VoteSetBits{VoteSetBits: msg} 38 | 39 | default: 40 | return fmt.Errorf("unknown message: %T", msg) 41 | } 42 | 43 | return nil 44 | } 45 | 46 | // Unwrap implements the p2p Wrapper interface and unwraps a wrapped consensus 47 | // proto message. 48 | func (m *Message) Unwrap() (proto.Message, error) { 49 | switch msg := m.Sum.(type) { 50 | case *Message_NewRoundStep: 51 | return m.GetNewRoundStep(), nil 52 | 53 | case *Message_NewValidBlock: 54 | return m.GetNewValidBlock(), nil 55 | 56 | case *Message_Proposal: 57 | return m.GetProposal(), nil 58 | 59 | case *Message_ProposalPol: 60 | return m.GetProposalPol(), nil 61 | 62 | case *Message_BlockPart: 63 | return m.GetBlockPart(), nil 64 | 65 | case *Message_Vote: 66 | return m.GetVote(), nil 67 | 68 | case *Message_HasVote: 69 | return m.GetHasVote(), nil 70 | 71 | case *Message_VoteSetMaj23: 72 | return m.GetVoteSetMaj23(), nil 73 | 74 | case *Message_VoteSetBits: 75 | return m.GetVoteSetBits(), nil 76 | 77 | default: 78 | return nil, fmt.Errorf("unknown message: %T", msg) 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Phantasma.Node/Events/EventBus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using Foundatio.Messaging; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using Microsoft.Extensions.Logging; 8 | using Phantasma.Node.Caching; 9 | 10 | namespace Phantasma.Node.Events; 11 | 12 | public class EventBus : IEventBus 13 | { 14 | private readonly ILogger _logger; 15 | private readonly IServiceScopeFactory _serviceScopeFactory; 16 | private readonly IMessageSubscriber _subscriber; 17 | 18 | public EventBus(ILogger logger, IMessageSubscriber subscriber, IServiceScopeFactory serviceScopeFactory) 19 | { 20 | _logger = logger; 21 | _subscriber = subscriber; 22 | _serviceScopeFactory = serviceScopeFactory; 23 | } 24 | 25 | public async Task Run(CancellationToken cancellationToken) 26 | { 27 | try 28 | { 29 | await RunInternal(cancellationToken); 30 | } 31 | catch (OperationCanceledException) 32 | { 33 | throw; 34 | } 35 | catch (Exception e) 36 | { 37 | _logger.LogCritical(e, "Event bus encountered an unexpected exception"); 38 | } 39 | } 40 | 41 | private Task RunInternal(CancellationToken cancellationToken) 42 | { 43 | _logger.LogInformation("Starting global event subscriptions"); 44 | 45 | var tasks = new List 46 | { 47 | _subscriber.SubscribeAsync(InvalidateEndpointCacheEventHandler, 48 | cancellationToken) 49 | }; 50 | 51 | return Task.WhenAll(tasks.ToArray()); 52 | } 53 | 54 | private async Task InvalidateEndpointCacheEventHandler(InvalidateEndpointCacheEvent evt) 55 | { 56 | using var scope = _serviceScopeFactory.CreateScope(); 57 | var cacheManager = scope.ServiceProvider.GetRequiredService(); 58 | await cacheManager.Invalidate(evt.Tag); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Phantasma.Business/src/Blockchain/Storage/SharedArchiveEncryption.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Phantasma.Core; 3 | 4 | namespace Phantasma.Business.Storage 5 | { 6 | // allows to encrypt data shared between two addresses 7 | public class SharedArchiveEncryption : IArchiveEncryption 8 | { 9 | public Address Source { get; private set; } 10 | public Address Destination { get; private set; } 11 | 12 | public SharedArchiveEncryption() 13 | { 14 | } 15 | 16 | public ArchiveEncryptionMode Mode => ArchiveEncryptionMode.Shared; 17 | 18 | public string EncryptName(string name, PhantasmaKeys keys) 19 | { 20 | throw new System.NotImplementedException(); 21 | } 22 | public string DecryptName(string name, PhantasmaKeys keys) 23 | { 24 | throw new System.NotImplementedException(); 25 | } 26 | public byte[] Encrypt(byte[] chunk, PhantasmaKeys keys) 27 | { 28 | if (keys.Address != this.Source && keys.Address != this.Destination) 29 | { 30 | throw new ChainException("encryption public address does not match"); 31 | } 32 | 33 | return DiffieHellman.Encrypt(chunk, keys.PrivateKey); 34 | } 35 | 36 | public byte[] Decrypt(byte[] chunk, PhantasmaKeys keys) 37 | { 38 | if (keys.Address != this.Source && keys.Address != this.Destination) 39 | { 40 | throw new ChainException("decryption public address does not match"); 41 | } 42 | 43 | return DiffieHellman.Decrypt(chunk, keys.PrivateKey); 44 | } 45 | 46 | public void SerializeData(BinaryWriter writer) 47 | { 48 | writer.WriteAddress(Source); 49 | writer.WriteAddress(Destination); 50 | } 51 | 52 | public void UnserializeData(BinaryReader reader) 53 | { 54 | this.Source = reader.ReadAddress(); 55 | this.Destination = reader.ReadAddress(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Phantasma.Core/src/Domain/PlatformInfo.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Phantasma.Core 6 | { 7 | public struct PlatformInfo : IPlatform, ISerializable 8 | { 9 | public string Name { get; private set; } 10 | public string Symbol { get; private set; } // for fuel 11 | public PlatformSwapAddress[] InteropAddresses { get; private set; } 12 | 13 | public PlatformInfo(string name, string symbol, IEnumerable interopAddresses) : this() 14 | { 15 | Name = name; 16 | Symbol = symbol; 17 | InteropAddresses = interopAddresses.ToArray(); 18 | } 19 | 20 | public void AddAddress(PlatformSwapAddress addr) 21 | { 22 | var list = InteropAddresses.ToList(); 23 | list.Add(addr); 24 | this.InteropAddresses = list.ToArray(); 25 | } 26 | 27 | public void SerializeData(BinaryWriter writer) 28 | { 29 | writer.WriteVarString(Name); 30 | writer.WriteVarString(Symbol); 31 | writer.WriteVarInt(InteropAddresses.Length); 32 | foreach (var address in InteropAddresses) 33 | { 34 | writer.WriteVarString(address.ExternalAddress); 35 | writer.WriteAddress(address.LocalAddress); 36 | } 37 | } 38 | 39 | public void UnserializeData(BinaryReader reader) 40 | { 41 | this.Name = reader.ReadVarString(); 42 | this.Symbol = reader.ReadVarString(); 43 | var interopCount = (int)reader.ReadVarInt(); 44 | this.InteropAddresses = new PlatformSwapAddress[interopCount]; 45 | for (int i = 0; i < interopCount; i++) 46 | { 47 | var temp = new PlatformSwapAddress(); 48 | temp.ExternalAddress = reader.ReadVarString(); 49 | temp.LocalAddress = reader.ReadAddress(); 50 | InteropAddresses[i] = temp; 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Phantasma.Node/Middleware/PerformanceMiddleware.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Threading.Tasks; 3 | using Phantasma.Node.Metrics; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.Extensions.Logging; 6 | 7 | namespace Phantasma.Node.Middleware; 8 | 9 | public class PerformanceMiddleware 10 | { 11 | private readonly ILogger _logger; 12 | private readonly IEndpointMetrics _metrics; 13 | private readonly RequestDelegate _next; 14 | 15 | public PerformanceMiddleware( 16 | RequestDelegate next, 17 | ILogger logger, 18 | IEndpointMetrics metrics 19 | ) 20 | { 21 | _next = next; 22 | _logger = logger; 23 | _metrics = metrics; 24 | } 25 | 26 | public async Task Invoke( 27 | HttpContext httpContext 28 | ) 29 | { 30 | Stopwatch timer = Stopwatch.StartNew(); 31 | 32 | await _next(httpContext); 33 | 34 | timer.Stop(); 35 | 36 | HttpRequest request = httpContext.Request; 37 | 38 | if (httpContext.Response.StatusCode >= 400 || 39 | request.Path.StartsWithSegments("/swagger") || 40 | request.Path.StartsWithSegments("/swagger-internal")) 41 | { 42 | // Ignore server errors and Swagger endpoints 43 | 44 | return; 45 | } 46 | 47 | //if (Settings.Default.PerformanceMetrics.CountsEnabled) 48 | //{ 49 | // await _metrics.Count(request.Path); 50 | //} 51 | 52 | //if (Settings.Default.PerformanceMetrics.AveragesEnabled) 53 | //{ 54 | // await _metrics.Average(request.Path, timer.ElapsedMilliseconds); 55 | //} 56 | 57 | //if (timer.ElapsedMilliseconds <= Settings.Default.PerformanceMetrics.LongRunningRequestThreshold) 58 | //{ 59 | // return; 60 | //} 61 | 62 | _logger.LogWarning("Long Running Request: Duration: {Duration}ms; Path: {Path}; Query: {@Query}", 63 | timer.ElapsedMilliseconds, request.Path, request.Query); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Tendermint.RPC/src/INodeRpc.cs: -------------------------------------------------------------------------------- 1 | using Tendermint.RPC.Endpoint; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Tendermint.RPC 7 | { 8 | /// 9 | /// RPC endpoints may be used to interact with a node directly over HTTP or websockets. 10 | /// Using RPC, you may perform low-level operations like executing 11 | /// ABCI queries, viewing network/consensus state or broadcasting a transaction. 12 | /// https://docs.binance.org/api-reference/node-rpc.html 13 | /// 14 | public interface INodeRpc 15 | { 16 | ResponseData AbciInfo(); 17 | 18 | ConsensusRoundStateData ConsensusState(); 19 | 20 | DumpRoundStateData DumpConsensusState(); 21 | 22 | ResultNetInfo NetInfo(); 23 | 24 | ResultGenesis Genesis(); 25 | 26 | ResultHealth Health(); 27 | 28 | ResultNumUnconfirmedTxs NumUnconfirmedTxs(); 29 | 30 | ResultStatus Status(); 31 | 32 | ResultAbciQuery AbciQuery(string path, string data = null, long height = 0, bool prove = false); 33 | 34 | ResultAbciQuery AbciQueryTokenList(int offset = 0, int limit = 10); 35 | 36 | ResultBlock Block(long? height = null); 37 | 38 | ResultBlock BlockByHash(string hash); 39 | 40 | ResultBlockResults BlockResults(long? height = null); 41 | 42 | ResultBlockchainInfo Blockchain(long minHeight, long maxHeight); 43 | 44 | ResultCommit Commit(long? height = null); 45 | 46 | ResultConsensusParams ConsensusParams(long? height = null); 47 | 48 | ResultTx Tx(string hash, bool prove = false); 49 | 50 | ResultTxSearch TxSearch(string query, bool prove = false, int page = 1, int perPage = 30); 51 | 52 | ResultUnconfirmedTxs UnconfirmedTxs(int? limit = null); 53 | 54 | ResultValidators Validators(long? height = null); 55 | 56 | ResultBroadcastTx BroadcastTxAsync(string tx); 57 | 58 | ResultBroadcastTxCommit BroadcastTxCommit(string tx); 59 | 60 | ResultBroadcastTx BroadcastTxSync(string tx); 61 | } 62 | } 63 | --------------------------------------------------------------------------------