Skip to content
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

refactor: redpacket history #2374

Merged
merged 44 commits into from
Jun 7, 2021
Merged

Conversation

zhouhanseng
Copy link
Contributor

@zhouhanseng zhouhanseng commented Feb 8, 2021

  • deploy test-net contract
  • update front-end
  • review approved
  • test pass
  • deploy main-net contract
  • test pass
  • merge

@septs
Copy link
Contributor

septs commented Feb 9, 2021

After this PR merged, do i need to stop the older service?

https://service.r2d2.to/red-packet-history

CC @guanbinrui

@zhouhanseng zhouhanseng marked this pull request as ready for review February 10, 2021 07:53
@zhouhanseng zhouhanseng changed the title wip: redpacket history refactor: redpacket history Feb 10, 2021
@Tedko
Copy link
Member

Tedko commented Feb 13, 2021

After this PR merged, do i need to stop the older service?

https://service.r2d2.to/red-packet-history

CC @guanbinrui

keep it running for a while just in case

export async function getRedPacketsHistory(rpids: string[]) {
const records: RedPacketRecord[] = []
for await (const record of RedPacketDatabase.iterate('red-packet')) {
if (rpids.includes(record.payload.rpid)) records.push(RedPacketRecordOutDB(record))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to have multiple records with the same rpid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, each record has its only rpid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so why don't you get record by RedPacketDatabase.get?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the last question @zhouhanseng

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you can query via .get plz use it instead of iterate over the database. it's O1 (hash table)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packages/maskbook/src/plugins/RedPacket/services.ts Outdated Show resolved Hide resolved
export async function getRedPacketsHistory(rpids: string[]) {
const records: RedPacketRecord[] = []
for await (const record of RedPacketDatabase.iterate('red-packet')) {
if (rpids.includes(record.payload.rpid)) records.push(RedPacketRecordOutDB(record))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so why don't you get record by RedPacketDatabase.get?

Jack-Works
Jack-Works previously approved these changes Feb 18, 2021
Copy link
Member

@Jack-Works Jack-Works left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm on code style

@Jack-Works
Copy link
Member

oh wait

@Jack-Works
Copy link
Member

  1. here is confliction
  2. still have some old review not resolved

const redPacketsFromDB = await database.getRedPacketsHistory(redPacketsFromChain.map((x) => x.rpid))
return redPacketsFromChain.reduce((acc, history) => {
const record = redPacketsFromDB.find((y) => y.payload.rpid === history.rpid)
if (history.chain_id === chainId && record) {
Copy link
Member

@guanbinrui guanbinrui Feb 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check history.chain_id === chainId at first and if it's true the finding logic can be ommited.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be ommited since we need password.

@Tedko
Copy link
Member

Tedko commented Feb 27, 2021

How's it? @zhouhanseng @septs @Jack-Works

@zhouhanseng
Copy link
Contributor Author

@Tedko work on this today.

@zhouhanseng zhouhanseng force-pushed the hancheng/refactor-red-packet-history branch 2 times, most recently from 4cfae96 to 4706fdd Compare March 2, 2021 06:13
export interface RedPacketAvailability {
token_address: string
balance: string
total: string
claimed: string
expired: boolean
ifclaimed: boolean
claimed_amount: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, already handled it:

const isClaimed = availability.claimed_amount !== '0'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean how do you handle the old name ifclaimed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const isClaimed = availability.ifclaimed => const isClaimed = availability.claimed_amount !== '0'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So IIRC the field "ifclaimed" is actually used in the payload. did it changed too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ifclaimed does not exist in payload

@zhouhanseng zhouhanseng force-pushed the hancheng/refactor-red-packet-history branch from d01507a to 2f8c80e Compare March 5, 2021 08:16
@@ -14,6 +10,10 @@
"type": "string",
"title": "rpid"
},
"txid": {
Copy link
Contributor Author

@zhouhanseng zhouhanseng Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not breaking change, since additionalProperties is true and "contract_version" is removed from "required" field, old red-packet payload is compatible.

const redPacketsFromDB = await database.getRedPacketsHistory(redPacketsFromChain.map((x) => x.txid))
return redPacketsFromChain.reduce((acc, history) => {
const record = redPacketsFromDB.find((y) => y.id === history.txid)
const historys = await subgraph.getRedPacketHistory(address)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplify this logic

@zhouhanseng zhouhanseng force-pushed the hancheng/refactor-red-packet-history branch 2 times, most recently from b3e51a5 to 5e00a2a Compare March 11, 2021 05:07
Jack-Works
Jack-Works previously approved these changes Mar 12, 2021
Copy link
Member

@Jack-Works Jack-Works left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently lgtm

@Jack-Works
Copy link
Member

merge with master. might have some type errors in it

@zhouhanseng
Copy link
Contributor Author

zhouhanseng commented Mar 18, 2021

@Jack-Works Notice don't merge into master before mainnet contract deployed.

Jack-Works
Jack-Works previously approved these changes Mar 19, 2021
Copy link
Member

@Jack-Works Jack-Works left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm on style

@zhouhanseng zhouhanseng force-pushed the hancheng/refactor-red-packet-history branch from 76f6955 to 9c42f1b Compare June 6, 2021 09:38
@AinuX
Copy link
Collaborator

AinuX commented Jun 6, 2021

Test passed with ETH MainNet.

Comment on lines +148 to +149
state.error.code <= JSON_RPC_ErrorCode.SERVER_ERROR_RANGE_START &&
state.error.code >= JSON_RPC_ErrorCode.SERVER_ERROR_RANGE_END)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz extract this code snippet as tool function

@zhouhanseng zhouhanseng merged commit fb2c900 into master Jun 7, 2021
@zhouhanseng zhouhanseng deleted the hancheng/refactor-red-packet-history branch June 7, 2021 01:25
guanbinrui pushed a commit that referenced this pull request Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants