diff --git a/ansible/group_vars/bastion b/ansible/group_vars/bastion index f13a2e3..8462a16 100644 --- a/ansible/group_vars/bastion +++ b/ansible/group_vars/bastion @@ -3,3 +3,5 @@ contracts_path: /var/contracts private_chain_alis_token_address: "0x7ad8f90cfa071c8420e3f09fe0e413d0c47502e6" private_chain_main_signer_address: "0x7ad8f90cfa071c8420e3f09fe0e413d0c47502e6" + +erc20_bridge_path: /var/erc20-bridge diff --git a/ansible/roles/bastion/tasks/main.yml b/ansible/roles/bastion/tasks/main.yml index 7442b48..53b5250 100644 --- a/ansible/roles/bastion/tasks/main.yml +++ b/ansible/roles/bastion/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: Add apt repositories + apt_repository: + repo: 'ppa:jonathonf/python-3.6' + - name: Install packages apt: name: "{{ item }}" @@ -6,20 +10,27 @@ update_cache: yes with_items: - build-essential + - python2.7 + - python3.6 + - python3.6-venv - name: Create dirctries file: path={{ item }} state=directory owner=root group=root mode=0755 with_items: - "{{ contracts_path }}" + - "{{ erc20_bridge_path }}" - name: Clone resources git: repo: "{{ item.src }}" dest: "{{ item.dest }}" + version: "{{ item.version }}" with_items: - - { src: 'https://github.com/AlisProject/private-chain-contracts.git', dest: "{{ contracts_path }}" } - - { src: 'https://github.com/riywo/ndenv', dest: "~/.ndenv" } - - { src: 'https://github.com/riywo/node-build.git', dest: "~/.ndenv/plugins/node-build" } + - { src: 'https://github.com/AlisProject/private-chain-contracts.git', dest: "{{ contracts_path }}", version: 'HEAD' } + - { src: 'https://github.com/AlisProject/erc20-bridge.git', dest: "{{ erc20_bridge_path }}", version: 'HEAD' } + - { src: 'https://github.com/riywo/ndenv', dest: "~/.ndenv", version: 'HEAD' } + - { src: 'https://github.com/riywo/node-build.git', dest: "~/.ndenv/plugins/node-build", version: 'HEAD' } + - { src: 'https://github.com/ethereum/vyper.git', dest: "~/vyper", version: 'v0.1.0-beta.7' } - name: Add lines to .bashrc lineinfile: @@ -41,3 +52,21 @@ - "/root/.ndenv/shims/npm install -g yarn" - "~/.ndenv/bin/ndenv exec yarn" - "~/.ndenv/bin/ndenv exec yarn exec truffle -- install" + +- name: Install and prepare modules for erc20-bridge + shell: "{{ item }}" + environment: + PYTHON: /usr/bin/python2.7 + args: + chdir: "{{ erc20_bridge_path }}" + with_items: + - "~/.ndenv/bin/ndenv install" + - "/root/.ndenv/shims/npm install -g yarn" + - "~/.ndenv/bin/ndenv exec yarn" + +- name: Install vyper for erc20-bridge + shell: "{{ item }}" + args: + chdir: "~/vyper" + with_items: + - "python3.6 setup.py install" diff --git a/deploy.sh b/deploy.sh index ab2ee60..63c14f9 100755 --- a/deploy.sh +++ b/deploy.sh @@ -15,4 +15,5 @@ aws cloudformation deploy \ ParityNodesVolumeSize=${SSM_PARAMS_PREFIX}ParityNodesVolumeSize \ PrivateChainMainSigner=${SSM_PARAMS_PREFIX}PrivateChainMainSigner \ PrivateChainAlisTokenAddress=${SSM_PARAMS_PREFIX}PrivateChainAlisTokenAddress \ + PrivateChainBridgeAddress=${SSM_PARAMS_PREFIX}PrivateChainBridgeAddress \ --stack-name ${ALIS_APP_ID}privatechain diff --git a/template.yaml b/template.yaml index f7582b5..3c59b00 100644 --- a/template.yaml +++ b/template.yaml @@ -16,6 +16,8 @@ Parameters: Type: 'AWS::SSM::Parameter::Value' PrivateChainAlisTokenAddress: Type: 'AWS::SSM::Parameter::Value' + PrivateChainBridgeAddress: + Type: 'AWS::SSM::Parameter::Value' ParityNodesInstanceType: Type: 'AWS::SSM::Parameter::Value' ParityNodesVolumeSize: @@ -284,6 +286,486 @@ Resources: "params": ["$input.json('transaction_hash').replaceAll('\"','')"], "id": 1 } + /wallet/allowance: + post: + description: 'allowance値の取得' + responses: + '200': + description: 'allowance値' + schema: + type: object + properties: + allowance: + type: 'string' + x-amazon-apigateway-integration: + responses: + default: + statusCode: '200' + uri: 'http://example.com:8545' # VPC Linkの場合は使用しないが定義する必要のある項目 + httpMethod: POST + type: http + connectionId: !Ref PrivateChainVpcLink + connectionType: VPC_LINK + requestTemplates: + application/json: + !Sub + - |- + { + "jsonrpc": "2.0", + "method": "eth_call", + "params": [ + { + "from": "$input.json('from_user_eth_address').replaceAll('\"','')", + "to": "${PrivateChainAlisTokenAddress}", + "data": "0xdd62ed3e000000000000000000000000$input.json('owner_eth_address').replaceAll('\"','')000000000000000000000000$input.json('spender_eth_address').replaceAll('\"','')" + }, + "latest" + ], + "id": 1 + } + - { + PrivateChainAlisTokenAddress: !Ref PrivateChainAlisTokenAddress + } + /wallet/approve: + post: + description: 'トークンの認可を行う' + responses: + '200': + description: 'トークンの認可結果' + schema: + type: object + properties: + transaction_hash: + type: 'string' + x-amazon-apigateway-integration: + responses: + default: + statusCode: '200' + uri: 'http://example.com:8545' # VPC Linkの場合は使用しないが定義する必要のある項目 + httpMethod: POST + type: http + connectionId: !Ref PrivateChainVpcLink + connectionType: VPC_LINK + requestTemplates: + application/json: + !Sub + - |- + { + "jsonrpc": "2.0", + "method": "personal_sendTransaction", + "params": [ + { + "from": "$input.json('from_user_eth_address').replaceAll('\"','')", + "to": "${PrivateChainAlisTokenAddress}", + "value": "0x0", + "nonce": "$input.json('nonce').replaceAll('\"','')", + "data": "0x095ea7b3000000000000000000000000$input.json('spender_eth_address').replaceAll('\"','')$input.json('value').replaceAll('\"','')" + }, + "${AccountsNewRequestPassword}" + ], + "id": 1 + } + - { + PrivateChainBridgeAddress: !Ref PrivateChainBridgeAddress, + PrivateChainAlisTokenAddress: !Ref PrivateChainAlisTokenAddress + } + /wallet/relay: + post: + description: 'トークンの引出しを行う' + responses: + '200': + description: 'トークンの引出し結果' + schema: + type: object + properties: + transaction_hash: + type: 'string' + x-amazon-apigateway-integration: + responses: + default: + statusCode: '200' + uri: 'http://example.com:8545' # VPC Linkの場合は使用しないが定義する必要のある項目 + httpMethod: POST + type: http + connectionId: !Ref PrivateChainVpcLink + connectionType: VPC_LINK + requestTemplates: + application/json: + !Sub + - |- + { + "jsonrpc": "2.0", + "method": "personal_sendTransaction", + "params": [ + { + "from": "$input.json('from_user_eth_address').replaceAll('\"','')", + "to": "${PrivateChainBridgeAddress}", + "value": "0x0", + "nonce": "$input.json('nonce').replaceAll('\"','')", + "data": "0xeeec0e24000000000000000000000000$input.json('recipient_eth_address').replaceAll('\"','')$input.json('amount').replaceAll('\"','')" + }, + "${AccountsNewRequestPassword}" + ], + "id": 1 + } + - { + PrivateChainBridgeAddress: !Ref PrivateChainBridgeAddress, + PrivateChainAlisTokenAddress: !Ref PrivateChainAlisTokenAddress + } + /wallet/relay_events: + post: + description: 'Relayイベントのログを取得' + responses: + '200': + description: 'Relayイベントのログ一覧' + schema: + type: object + properties: + events: + type: 'string' + x-amazon-apigateway-integration: + responses: + default: + statusCode: '200' + uri: 'http://example.com:8545' # VPC Linkの場合は使用しないが定義する必要のある項目 + httpMethod: POST + type: http + connectionId: !Ref PrivateChainVpcLink + connectionType: VPC_LINK + requestTemplates: + application/json: + !Sub + - |- + { + "jsonrpc": "2.0", + "method": "eth_getLogs", + "params": [ + { + "fromBlock": "$input.json('from_block').replaceAll('\"','')", + "toBlock": "$input.json('to_block').replaceAll('\"','')", + "address": "${PrivateChainBridgeAddress}", + "topics": [ + "0xb77c820b3a0ee4da03c984a58bfe43cb27cd3297d424e1025014ce0b7de08cc4", + "0x000000000000000000000000$input.json('sender_eth_address').replaceAll('\"','')" + ] + } + ], + "id": 1 + } + - { + PrivateChainBridgeAddress: !Ref PrivateChainBridgeAddress + } + /wallet/apply_relay_events: + post: + description: 'ApplyRelayイベントのログを取得' + responses: + '200': + description: 'ApplyRelayイベントのログ一覧' + schema: + type: object + properties: + events: + type: 'string' + x-amazon-apigateway-integration: + responses: + default: + statusCode: '200' + uri: 'http://example.com:8545' # VPC Linkの場合は使用しないが定義する必要のある項目 + httpMethod: POST + type: http + connectionId: !Ref PrivateChainVpcLink + connectionType: VPC_LINK + requestTemplates: + application/json: + !Sub + - |- + { + "jsonrpc": "2.0", + "method": "eth_getLogs", + "params": [ + { + "fromBlock": "$input.json('from_block').replaceAll('\"','')", + "toBlock": "$input.json('to_block').replaceAll('\"','')", + "address": "${PrivateChainBridgeAddress}", + "topics": [ + "0xb114698a397e5f7a7c78e5e58f6f59d2c329c988c585a930db7bb099b3d016d6", + null, + "0x000000000000000000000000$input.json('recipient_eth_address').replaceAll('\"','')" + ] + } + ], + "id": 1 + } + - { + PrivateChainBridgeAddress: !Ref PrivateChainBridgeAddress + } + /wallet/max_single_relay_amount: + post: + description: '出金額の最大値の取得' + responses: + '200': + description: '出金額の最大値' + schema: + type: object + properties: + amount: + type: 'string' + x-amazon-apigateway-integration: + responses: + default: + statusCode: '200' + uri: 'http://example.com:8545' # VPC Linkの場合は使用しないが定義する必要のある項目 + httpMethod: POST + type: http + connectionId: !Ref PrivateChainVpcLink + connectionType: VPC_LINK + requestTemplates: + application/json: + !Sub + - |- + { + "jsonrpc": "2.0", + "method": "eth_call", + "params": [ + { + "from": "${PrivateChainMainSigner}", + "to": "${PrivateChainBridgeAddress}", + "data": "0x34f89513" + }, + "latest" + ], + "id": 1 + } + - { + PrivateChainMainSigner: !Ref PrivateChainMainSigner, + PrivateChainBridgeAddress: !Ref PrivateChainBridgeAddress + } + /wallet/min_single_relay_amount: + post: + description: '出金額の最小値の取得' + responses: + '200': + description: '出金額の最小値' + schema: + type: object + properties: + amount: + type: 'string' + x-amazon-apigateway-integration: + responses: + default: + statusCode: '200' + uri: 'http://example.com:8545' # VPC Linkの場合は使用しないが定義する必要のある項目 + httpMethod: POST + type: http + connectionId: !Ref PrivateChainVpcLink + connectionType: VPC_LINK + requestTemplates: + application/json: + !Sub + - |- + { + "jsonrpc": "2.0", + "method": "eth_call", + "params": [ + { + "from": "${PrivateChainMainSigner}", + "to": "${PrivateChainBridgeAddress}", + "data": "0x9f29ffdf" + }, + "latest" + ], + "id": 1 + } + - { + PrivateChainMainSigner: !Ref PrivateChainMainSigner, + PrivateChainBridgeAddress: !Ref PrivateChainBridgeAddress + } + /wallet/relay_fee: + post: + description: '出金手数料の取得' + responses: + '200': + description: '出金手数料' + schema: + type: object + properties: + amount: + type: 'string' + x-amazon-apigateway-integration: + responses: + default: + statusCode: '200' + uri: 'http://example.com:8545' # VPC Linkの場合は使用しないが定義する必要のある項目 + httpMethod: POST + type: http + connectionId: !Ref PrivateChainVpcLink + connectionType: VPC_LINK + requestTemplates: + application/json: + !Sub + - |- + { + "jsonrpc": "2.0", + "method": "eth_call", + "params": [ + { + "from": "${PrivateChainMainSigner}", + "to": "${PrivateChainBridgeAddress}", + "data": "0x71d30863" + }, + "latest" + ], + "id": 1 + } + - { + PrivateChainMainSigner: !Ref PrivateChainMainSigner, + PrivateChainBridgeAddress: !Ref PrivateChainBridgeAddress + } + /wallet/relay_paused: + post: + description: '出金停止中フラグの取得' + responses: + '200': + description: '出金停止中フラグ' + schema: + type: object + properties: + paused: + type: 'string' + x-amazon-apigateway-integration: + responses: + default: + statusCode: '200' + uri: 'http://example.com:8545' # VPC Linkの場合は使用しないが定義する必要のある項目 + httpMethod: POST + type: http + connectionId: !Ref PrivateChainVpcLink + connectionType: VPC_LINK + requestTemplates: + application/json: + !Sub + - |- + { + "jsonrpc": "2.0", + "method": "eth_call", + "params": [ + { + "from": "${PrivateChainMainSigner}", + "to": "${PrivateChainBridgeAddress}", + "data": "0x69a08a26" + }, + "latest" + ], + "id": 1 + } + - { + PrivateChainMainSigner: !Ref PrivateChainMainSigner, + PrivateChainBridgeAddress: !Ref PrivateChainBridgeAddress + } + /eth/block_number: + post: + description: '現在のブロック数を取得' + responses: + '200': + description: '現在のブロック数' + schema: + type: object + properties: + block_number: + type: 'integer' + x-amazon-apigateway-integration: + responses: + default: + statusCode: '200' + uri: 'http://example.com:8545' # VPC Linkの場合は使用しないが定義する必要のある項目 + httpMethod: POST + type: http + connectionId: !Ref PrivateChainVpcLink + connectionType: VPC_LINK + requestTemplates: + application/json: + !Sub + - |- + { + "jsonrpc": "2.0", + "method": "eth_blockNumber", + "params": [ + ], + "id": 1 + } + - { + } + /eth/get_block_by_number: + post: + description: '指定したブロック数のブロック情報を取得' + responses: + '200': + description: 'ブロック情報' + schema: + type: object + properties: + block: + type: 'string' + x-amazon-apigateway-integration: + responses: + default: + statusCode: '200' + uri: 'http://example.com:8545' # VPC Linkの場合は使用しないが定義する必要のある項目 + httpMethod: POST + type: http + connectionId: !Ref PrivateChainVpcLink + connectionType: VPC_LINK + requestTemplates: + application/json: + !Sub + - |- + { + "jsonrpc": "2.0", + "method": "eth_getBlockByNumber", + "params": [ + "$input.json('block_num').replaceAll('\"','')", + false + ], + "id": 1 + } + - { + } + /eth/get_transaction_count: + post: + description: 'トランザクション数の取得' + responses: + '200': + description: 'トランザクション数' + schema: + type: object + properties: + transaction_count: + type: 'integer' + x-amazon-apigateway-integration: + responses: + default: + statusCode: '200' + uri: 'http://example.com:8545' # VPC Linkの場合は使用しないが定義する必要のある項目 + httpMethod: POST + type: http + connectionId: !Ref PrivateChainVpcLink + connectionType: VPC_LINK + requestTemplates: + application/json: + !Sub + - |- + { + "jsonrpc": "2.0", + "method": "eth_getTransactionCount", + "params": [ + "$input.json('from_user_eth_address').replaceAll('\"','')", + "latest" + ], + "id": 1 + } + - { + } PrivateSubNet1: Type: 'AWS::EC2::Subnet' Properties: @@ -338,6 +820,17 @@ Resources: Value: PrivateSecurityGroup - Key: Component Value: PrivateChain + PrivateLambdaSecurityGroup: + Type: 'AWS::EC2::SecurityGroup' + Properties: + VpcId: !Ref PrivateChain + GroupName: PrivateLambdaSecurityGroup + GroupDescription: Security Group for Private lambda. + Tags: + - Key: Name + Value: PrivateLambdaSecurityGroup + - Key: Component + Value: PrivateChain PCParityPoA1a: Type: 'AWS::EC2::Instance' Properties: