Skip to content

Commit

Permalink
Merge pull request #415 from keillera/ALIS-5187
Browse files Browse the repository at this point in the history
Alis 5187
  • Loading branch information
hayago authored Apr 27, 2020
2 parents f6ac904 + 10d843f commit d0ebe4b
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 94 deletions.
9 changes: 9 additions & 0 deletions api-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ Parameters:
Type: 'AWS::SSM::Parameter::Value<String>'
AuthleteApiSecret:
Type: 'AWS::SSM::Parameter::Value<String>'
UserConfigurationsTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
PrivateChainAlisTokenAddress:
Type: 'AWS::SSM::Parameter::Value<String>'
PrivateChainBridgeAddress:
Type: 'AWS::SSM::Parameter::Value<String>'
BurnAddress:
Type: 'AWS::SSM::Parameter::Value<String>'

Expand Down Expand Up @@ -145,6 +151,7 @@ Globals:
TIP_TABLE_NAME: !Ref TipTableName
SUCCEEDED_TIP_TABLE_NAME: !Ref SucceededTipTableName
EXTERNAL_PROVIDER_USERS_TABLE_NAME: !Ref ExternalProviderUsersTableName
USER_CONFIGURATIONS_TABLE_NAME: !Ref UserConfigurationsTableName
DOMAIN: !Ref AlisAppDomain
PRIVATE_CHAIN_AWS_ACCESS_KEY: !Ref PrivateChainAwsAccessKey
PRIVATE_CHAIN_AWS_SECRET_ACCESS_KEY: !Ref PrivateChainAwsSecretAccessKey
Expand All @@ -154,6 +161,8 @@ Globals:
ELASTIC_SEARCH_ENDPOINT: !Ref ElasticSearchEndpoint
PAID_ARTICLES_TABLE_NAME: !Ref PaidArticlesTableName
PAID_STATUS_TABLE_NAME: !Ref PaidStatusTableName
PRIVATE_CHAIN_ALIS_TOKEN_ADDRESS: !Ref PrivateChainAlisTokenAddress
PRIVATE_CHAIN_BRIDGE_ADDRESS: !Ref PrivateChainBridgeAddress
BURN_ADDRESS: !Ref BurnAddress

Resources:
Expand Down
55 changes: 12 additions & 43 deletions function-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,27 @@ Parameters:
Type: 'AWS::SSM::Parameter::Value<String>'
ArticleHistoryTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
ArticleContentEditTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
ArticleEvaluatedManageTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
ArticleAlisTokenTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
ArticleLikedUserTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
ArticleFraudUserTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
ArticlePvUserTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
ArticleScoreTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
UsersTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
BetaUsersTableName:
UserConfigurationsTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
ExternalProviderUsersTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
NotificationTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
UnreadNotificationManagerTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
CommentTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
CommentLikedUserTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
DeletedCommentTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
UserFraudTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
ScreenedArticleTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
TokenDistributionTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
UserFirstExperienceTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
ElasticSearchEndpoint:
Type: 'AWS::SSM::Parameter::Value<String>'
TopicTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
TagTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
TipTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
AlisAppDomain:
Type: 'AWS::SSM::Parameter::Value<String>'
PrivateChainAwsAccessKey:
Type: 'AWS::SSM::Parameter::Value<String>'
PrivateChainAwsSecretAccessKey:
Type: 'AWS::SSM::Parameter::Value<String>'
PrivateChainExecuteApiHost:
Type: 'AWS::SSM::Parameter::Value<String>'
BetaModeFlag:
PrivateChainAlisTokenAddress:
Type: 'AWS::SSM::Parameter::Value<String>'
PrivateChainBridgeAddress:
Type: 'AWS::SSM::Parameter::Value<String>'
DistS3BucketName:
BurnAddress:
Type: 'AWS::SSM::Parameter::Value<String>'
CognitoUserPoolId:
Type: 'AWS::SSM::Parameter::Value<String>'
Expand Down Expand Up @@ -110,8 +74,6 @@ Parameters:
Type: 'AWS::SSM::Parameter::Value<String>'
FacebookAppToken:
Type: 'AWS::SSM::Parameter::Value<String>'
PrivateChainBridgeAddress:
Type: 'AWS::SSM::Parameter::Value<String>'
PaidArticlesTableName:
Type: 'AWS::SSM::Parameter::Value<String>'
PaidStatusTableName:
Expand Down Expand Up @@ -287,9 +249,13 @@ Resources:
PRIVATE_CHAIN_AWS_ACCESS_KEY: !Ref PrivateChainAwsAccessKey
PRIVATE_CHAIN_AWS_SECRET_ACCESS_KEY: !Ref PrivateChainAwsSecretAccessKey
PRIVATE_CHAIN_EXECUTE_API_HOST: !Ref PrivateChainExecuteApiHost
PRIVATE_CHAIN_ALIS_TOKEN_ADDRESS: !Ref PrivateChainAlisTokenAddress
PRIVATE_CHAIN_BRIDGE_ADDRESS: !Ref PrivateChainBridgeAddress
BURN_ADDRESS: !Ref BurnAddress
COGNITO_USER_POOL_ID: !Ref CognitoUserPoolId
COGNITO_USER_POOL_APP_ID: !Ref CognitoUserPoolAppId
PAID_STATUS_TABLE_NAME: !Ref PaidStatusTableName
USER_CONFIGURATIONS_TABLE_NAME: !Ref UserConfigurationsTableName
Handler: handler.lambda_handler
MemorySize: 3008
Role: !GetAtt LambdaRole.Arn
Expand Down Expand Up @@ -322,8 +288,11 @@ Resources:
PRIVATE_CHAIN_AWS_ACCESS_KEY: !Ref PrivateChainAwsAccessKey
PRIVATE_CHAIN_AWS_SECRET_ACCESS_KEY: !Ref PrivateChainAwsSecretAccessKey
PRIVATE_CHAIN_EXECUTE_API_HOST: !Ref PrivateChainExecuteApiHost
PRIVATE_CHAIN_ALIS_TOKEN_ADDRESS: !Ref PrivateChainAlisTokenAddress
BURN_ADDRESS: !Ref BurnAddress
TOKEN_SEND_TABLE_NAME: !Ref TokenSendTableName
DAILY_LIMIT_TOKEN_SEND_VALUE: !Ref DailyLimitTokenSendValue
USER_CONFIGURATIONS_TABLE_NAME: !Ref UserConfigurationsTableName
Handler: handler.lambda_handler
MemorySize: 3008
Role: !GetAtt LambdaRole.Arn
Expand Down
10 changes: 5 additions & 5 deletions function02-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ Resources:
Timeout: 900
TracingConfig:
Mode: "Active"
UserWalletAddressShow:
UsersWalletAddressShow:
Type: "AWS::Lambda::Function"
Properties:
Code: ./deploy/user_wallet_address_show.zip
Code: ./deploy/users_wallet_address_show.zip
Environment:
Variables:
COGNITO_USER_POOL_ID: !Ref CognitoUserPoolId
Expand Down Expand Up @@ -311,7 +311,7 @@ Outputs:
Value: !GetAtt MeWalletNonceShow.Arn
Export:
Name: !Sub "${AlisAppId}-MeWalletNonceShow"
UserWalletAddressShow:
Value: !GetAtt UserWalletAddressShow.Arn
UsersWalletAddressShow:
Value: !GetAtt UsersWalletAddressShow.Arn
Export:
Name: !Sub "${AlisAppId}-UserWalletAddressShow"
Name: !Sub "${AlisAppId}-UsersWalletAddressShow"
45 changes: 45 additions & 0 deletions permission-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,48 @@ Resources:
Fn::Sub: "${AlisAppId}-MeConfigurationsMuteUsersIndex"
Principal: "apigateway.amazonaws.com"
SourceArn: !Sub ${RestApiArn}/*/GET/me/configurations/mute_users
MeConfigurationsWalletShowApiGatewayInvoke:
Type: "AWS::Lambda::Permission"
Properties:
Action: "lambda:InvokeFunction"
FunctionName:
Fn::ImportValue:
Fn::Sub: "${AlisAppId}-MeConfigurationsWalletShow"
Principal: "apigateway.amazonaws.com"
SourceArn: !Sub ${RestApiArn}/*/GET/me/configurations/wallet
MeConfigurationsWalletAddApiGatewayInvoke:
Type: "AWS::Lambda::Permission"
Properties:
Action: "lambda:InvokeFunction"
FunctionName:
Fn::ImportValue:
Fn::Sub: "${AlisAppId}-MeConfigurationsWalletAdd"
Principal: "apigateway.amazonaws.com"
SourceArn: !Sub ${RestApiArn}/*/POST/me/configurations/wallet
UsersWalletAddressShowApiGatewayInvoke:
Type: "AWS::Lambda::Permission"
Properties:
Action: "lambda:InvokeFunction"
FunctionName:
Fn::ImportValue:
Fn::Sub: "${AlisAppId}-UsersWalletAddressShow"
Principal: "apigateway.amazonaws.com"
SourceArn: !Sub ${RestApiArn}/*/GET/users/*/wallet/address
MeWalletAllowanceShowApiGatewayInvoke:
Type: "AWS::Lambda::Permission"
Properties:
Action: "lambda:InvokeFunction"
FunctionName:
Fn::ImportValue:
Fn::Sub: "${AlisAppId}-MeWalletAllowanceShow"
Principal: "apigateway.amazonaws.com"
SourceArn: !Sub ${RestApiArn}/*/GET/me/wallet/allowance
MeWalletNonceShowApiGatewayInvoke:
Type: "AWS::Lambda::Permission"
Properties:
Action: "lambda:InvokeFunction"
FunctionName:
Fn::ImportValue:
Fn::Sub: "${AlisAppId}-MeWalletNonceShow"
Principal: "apigateway.amazonaws.com"
SourceArn: !Sub ${RestApiArn}/*/GET/me/wallet/nonce
24 changes: 18 additions & 6 deletions src/common/private_chain_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def get_data_from_raw_transaction(cls, raw_transaction, transaction_count):
# 0:nonce(transaction_count)
# 1:gasPrice(0)
# 2:gasLimit(0)
# 3:to_address(今回の場合は alis トークンのコントラクトアドレス)
# 3:to_address
# 4:value(0)
# 5:data
# 6:v(検証で利用。但し、内部で chain_id が利用されているため確認対象)
Expand All @@ -153,14 +153,26 @@ def get_data_from_raw_transaction(cls, raw_transaction, transaction_count):
# 発生しない想定だが念の為個数を確認
if len(byte_data_list) != 9:
raise ValidationError('raw_transaction is invalid')
if int(byte_data_list[0].hex(), 16) != int(transaction_count, 16):
# nonce
if byte_data_list[0].hex() != '' and int(byte_data_list[0].hex(), 16) != int(transaction_count, 16):
raise ValidationError('nonce is invalid')
if byte_data_list[0].hex() == '' and int(transaction_count, 16) != 0:
raise ValidationError('nonce is invalid')
# gasPrice
if byte_data_list[1].hex() != '':
raise ValidationError('gasPrice is invalid')
if byte_data_list[2].hex() != '':
# gasLimit
if byte_data_list[2].hex() != '0186a0':
raise ValidationError('gasLimit is invalid')
if byte_data_list[3].hex() != os.environ['PRIVATE_CHAIN_ALIS_TOKEN_ADDRESS'][2:]:
# to_address
# relay method の場合は to_address は PRIVATE_CHAIN_BRIDGE_ADDRESS
if byte_data_list[5].hex()[0:8] == 'eeec0e24':
to_address = os.environ['PRIVATE_CHAIN_BRIDGE_ADDRESS']
else:
to_address = os.environ['PRIVATE_CHAIN_ALIS_TOKEN_ADDRESS']
if byte_data_list[3].hex().lower() != to_address[2:].lower():
raise ValidationError('private_chain_alis_token_address is invalid')
# value
if byte_data_list[4].hex() != '':
raise ValidationError('value is invalid')
# v は検証パラメータだが、chain_id を含んでいるため確認する
Expand All @@ -181,7 +193,7 @@ def validate_erc20_transfer_data(cls, data, to_address):
if data[0:8] != 'a9059cbb':
raise ValidationError('method is invalid')
# to_address
if data[8:72][24:] != to_address[2:]:
if data[8:72][24:].lower() != to_address[2:].lower():
raise ValidationError('to_address is invalid')
# tip_value
validate(
Expand All @@ -204,7 +216,7 @@ def validate_erc20_approve_data(cls, data):
if data[0:8] != '095ea7b3':
raise ValidationError('method is invalid')
# spender_eth_address
if data[8:72][24:] != os.environ['PRIVATE_CHAIN_BRIDGE_ADDRESS'][2:]:
if data[8:72][24:].lower() != os.environ['PRIVATE_CHAIN_BRIDGE_ADDRESS'][2:].lower():
raise ValidationError('spender_eth_address is invalid')
# value
if int(data[72:], 16) != 0:
Expand Down
13 changes: 6 additions & 7 deletions src/handlers/cognito_trigger/custommessage/custom_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ def exec_main_proc(self):
# トークンを保持していた場合は例外を出力
def __validate_has_not_token(self, params):
address = params.get('custom:private_eth_address')
if address is None:
raise ValidationError('Not exists private_eth_address. user_id: ' + self.event['userName'])
url = 'https://' + os.environ['PRIVATE_CHAIN_EXECUTE_API_HOST'] + '/production/wallet/balance'
payload = {'private_eth_address': address[2:]}
token = PrivateChainUtil.send_transaction(request_url=url, payload_dict=payload)
if token is not None and token != '0x0000000000000000000000000000000000000000000000000000000000000000':
raise ValidationError("Do not allow phone number updates")
if address is not None:
url = 'https://' + os.environ['PRIVATE_CHAIN_EXECUTE_API_HOST'] + '/production/wallet/balance'
payload = {'private_eth_address': address[2:]}
token = PrivateChainUtil.send_transaction(request_url=url, payload_dict=payload)
if token is not None and token != '0x0000000000000000000000000000000000000000000000000000000000000000':
raise ValidationError("Do not allow phone number updates")
6 changes: 3 additions & 3 deletions src/handlers/me/wallet/token/send/me_wallet_token_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def exec_main_proc(self):
################
# validate raw_transaction
# init_approve_signed_transaction
if allowance != '0x0':
if int(allowance, 16) != 0:
# allowance が設定されている場合は必須
if self.params.get('init_approve_signed_transaction') is None:
raise ValidationError('init_approve_signed_transaction is invalid.')
Expand Down Expand Up @@ -112,8 +112,8 @@ def exec_main_proc(self):
#######################
# send_raw_transaction
#######################
# 既に approve されている場合(allowance の戻り値が "0x0" ではない場合)、該当の approve を削除する(0 で更新)
if allowance != '0x0':
# 既に approve されている場合(allowance の戻り値が 0 ではない場合)、該当の approve を削除する(0 で更新)
if int(allowance, 16) != 0:
PrivateChainUtil.send_raw_transaction(self.params.get('init_approve_signed_transaction'))

# approve 実施
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/users/wallet/address/show/handler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import boto3
from user_wallet_address_show import UserWalletAddressShow
from users_wallet_address_show import UsersWalletAddressShow

cognito = boto3.client('cognito-idp')


def lambda_handler(event, context):
user_wallet_address_show = UserWalletAddressShow(event, context, cognito=cognito)
return user_wallet_address_show.main()
users_wallet_address_show = UsersWalletAddressShow(event, context, cognito=cognito)
return users_wallet_address_show.main()
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from jsonschema import validate


class UserWalletAddressShow(LambdaBase):
class UsersWalletAddressShow(LambdaBase):
def get_schema(self):
return {
'type': 'object',
Expand Down
21 changes: 18 additions & 3 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,12 @@ paths:
default:
statusCode: '200'
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${UserWalletAddressShow.Arn}/invocations
Fn::Join:
- ''
- - Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/"
- Fn::ImportValue:
Fn::Sub: "${AlisAppId}-UsersWalletAddressShow"
- "/invocations"
passthroughBehavior: when_no_templates
httpMethod: POST
type: aws_proxy
Expand All @@ -2368,7 +2373,12 @@ paths:
default:
statusCode: "200"
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MeWalletAllowance.Arn}/invocations
Fn::Join:
- ''
- - Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/"
- Fn::ImportValue:
Fn::Sub: "${AlisAppId}-MeWalletAllowanceShow"
- "/invocations"
passthroughBehavior: when_no_templates
httpMethod: POST
type: aws_proxy
Expand All @@ -2387,7 +2397,12 @@ paths:
default:
statusCode: "200"
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MeWalletNonce.Arn}/invocations
Fn::Join:
- ''
- - Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/"
- Fn::ImportValue:
Fn::Sub: "${AlisAppId}-MeWalletNonceShow"
- "/invocations"
passthroughBehavior: when_no_templates
httpMethod: POST
type: aws_proxy
Expand Down
Loading

0 comments on commit d0ebe4b

Please sign in to comment.