-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/woojae/model controller #42
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0227acc
util
akastercomcom bbe4147
Merge branch 'develop' into feat/woojae/modelController
akastercomcom 48672b2
modelController
akastercomcom 9734673
modelController
akastercomcom e93ca76
refactor: ops
akastercomcom 9bb9a86
feat: deposit Type
akastercomcom bfe339f
fix: isDefaultAccountExist
akastercomcom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { SetOperation } from "@ainblockchain/ain-js/lib/types"; | ||
import { Request } from "express"; | ||
import { getChangeBalanceOp, getResponseOp, getWriteHistoryOp } from "./utils/operator"; | ||
import { HISTORY_TYPE, RESPONSE_STATUS, deposit, request, response } from "./types/type"; | ||
import { buildTxBody } from "./utils/builder"; | ||
import AinModule from "./ain"; | ||
|
||
export default class internal { | ||
private ain = AinModule.getInstance(); | ||
async handleDeposit(req: Request) { | ||
const { requesterAddress, appName, transferKey, transferValue } = this.getDataFromDepositRequest(req); | ||
const ops: SetOperation[] = []; | ||
const changeBalanceOp = await getChangeBalanceOp(appName, requesterAddress, "INC_VALUE", transferValue); | ||
const writeHistoryOp = await getWriteHistoryOp(appName, requesterAddress, HISTORY_TYPE.DEPOSIT, transferValue, transferKey); | ||
ops.push(changeBalanceOp); | ||
ops.push(writeHistoryOp); | ||
const txBody = buildTxBody(ops); | ||
return await this.ain.sendTransaction(txBody); | ||
} | ||
|
||
async handleRequest(req: Request, cost: number, status: RESPONSE_STATUS, responseData: string) { | ||
const { requesterAddress, requestKey, appName } = this.getDataFromServiceRequest(req); | ||
const ops:SetOperation[] = []; | ||
const responseOp = getResponseOp(appName, requesterAddress, requestKey, status, responseData, cost); | ||
ops.push(responseOp); | ||
if(cost > 0) { | ||
const changeBalanceOp = getChangeBalanceOp(appName, requesterAddress, 'DEC_VALUE', cost); | ||
const writeHistoryOp = getWriteHistoryOp(appName, requesterAddress, HISTORY_TYPE.USAGE, cost, requestKey); | ||
ops.push(changeBalanceOp); | ||
ops.push(writeHistoryOp); | ||
} | ||
const txBody = buildTxBody(ops); | ||
return await this.ain.sendTransaction(txBody); | ||
} | ||
|
||
getDataFromServiceRequest(req: Request) { | ||
if(!req.body.valuePath[1] || !req.body.valuePath[3] || !req.body.valuePath[4] || !req.body.value.prompt) { | ||
throw new Error("Not from service request"); | ||
} | ||
const requestData: request = { | ||
appName: req.body.valuePath[1], | ||
requesterAddress: req.body.auth.addr, | ||
requestKey: req.body.valuePath[4], | ||
requestData: req.body.value.prompt, | ||
} | ||
return requestData; | ||
} | ||
|
||
private getDataFromDepositRequest(req: Request) { | ||
if(!req.body.valuePath[1] || !req.body.valuePath[4] || !req.body.value) { | ||
throw new Error("Not from deposit request"); | ||
} | ||
const depositData: deposit = { | ||
transferKey: req.body.valuePath[4], | ||
transferValue: req.body.value, | ||
appName: req.body.valuePath[1], | ||
requesterAddress: req.body.auth.addr, | ||
} | ||
return depositData; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ain init 되어도 defaultAccount가 없을 수도 있습니다.
this.isDefaultAccountExist로 true | false 체크 하면 좋을 것 같습니다.
(제가 올릴 때 true, false 반대로 올려서, 같이 고쳐주세용 😢 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 그렇네요
수정했습니다!