-
Notifications
You must be signed in to change notification settings - Fork 23
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: WM on Test wallet #1427
feat: WM on Test wallet #1427
Changes from all commits
01d9084
ee0bb17
da749f5
261ce75
a06af49
2078190
c14b686
fb4986d
bb35ecf
eea0694
c01d1a6
b3429ac
07a1ea3
9eeeec9
0cbdf04
22c77a5
ac3be50
4876690
4caaaa4
83ed0c5
b2b14ce
2626bfc
e52bd16
6c5d9a3
4c0de74
1768d9e
3aa2ce8
70fb990
e5f6cc8
ac844d1
7c5eee5
7cd87d4
3733fa6
3c410d8
ff4b64e
2bad249
6e6b7f4
7e6c73b
3d2189d
317d2a3
e450145
7fdb4fe
b78f24d
308306e
dfbf7f3
021c9b8
b920316
4601b42
1593a26
ed44242
ba0ff7b
29cc5e9
8b1f95f
1f81cc6
db4de9c
df198f3
9723429
27f32c3
3925b62
e81c0f5
650a72f
119e4da
b78cf23
79fd71a
d9e4d9a
939b7f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,20 @@ module.exports = { | |
} | ||
}, | ||
|
||
rafiki_backend: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this added? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this so that I can migrate assets to scale 9 in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an env variable instead with the connection string |
||
client: 'postgresql', | ||
connection: { | ||
host: 'postgres', | ||
user: 'postgres', | ||
password: 'password', | ||
database: 'rafiki_backend' | ||
}, | ||
pool: { | ||
min: 2, | ||
max: 10 | ||
} | ||
}, | ||
|
||
testing: { | ||
client: 'postgresql', | ||
connection: { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
const Knex = require('knex') | ||
const knexConfig = require('../knexfile') | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.up = async function (knex) { | ||
if (process.env.NODE_ENV !== 'test') { | ||
const rafikiKnex = Knex(knexConfig.rafiki_backend) | ||
|
||
try { | ||
const assets = await rafikiKnex('assets').distinct('code') | ||
|
||
for (const asset of assets) { | ||
const { code } = asset | ||
|
||
const existingAssetWithScale9 = await rafikiKnex('assets') | ||
.where({ code, scale: 9 }) | ||
.first() | ||
|
||
if (existingAssetWithScale9) { | ||
await knex('accounts') | ||
.where({ assetCode: code, assetScale: 2 }) | ||
.update({ | ||
assetId: existingAssetWithScale9.id, | ||
assetScale: 9 | ||
}) | ||
} else { | ||
await rafikiKnex('assets') | ||
.where({ code, scale: 2 }) | ||
.update({ scale: 9 }) | ||
} | ||
} | ||
} finally { | ||
await rafikiKnex.destroy() | ||
} | ||
} | ||
|
||
const walletAddresses = await knex('walletAddresses').select( | ||
'id', | ||
'accountId' | ||
) | ||
for (const walletAddress of walletAddresses) { | ||
const account = await knex('accounts') | ||
.where('id', walletAddress.accountId) | ||
.first() | ||
if (account) { | ||
await knex('walletAddresses') | ||
.where('id', walletAddress.id) | ||
.update({ assetCode: account.assetCode }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why would asset code change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This happens because |
||
} | ||
} | ||
|
||
await knex('walletAddresses').update({ assetScale: 9 }) | ||
await knex('accounts').update({ assetScale: 9 }) | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = async function (knex) { | ||
if (process.env.NODE_ENV !== 'test') { | ||
const rafikiKnex = Knex(knexConfig.rafiki_backend) | ||
|
||
try { | ||
const assets = await rafikiKnex('assets').distinct('code') | ||
|
||
for (const asset of assets) { | ||
const { code } = asset | ||
|
||
const existingAssetWithScale2 = await rafikiKnex('assets') | ||
.where({ code, scale: 2 }) | ||
.first() | ||
|
||
if (existingAssetWithScale2) { | ||
await knex('accounts') | ||
.where({ assetCode: code, assetScale: 9 }) | ||
.update({ | ||
assetId: existingAssetWithScale2.id, | ||
assetScale: 2 | ||
}) | ||
} else { | ||
await rafikiKnex('assets') | ||
.where({ code, scale: 9 }) | ||
.update({ scale: 2 }) | ||
} | ||
} | ||
} finally { | ||
await rafikiKnex.destroy() | ||
} | ||
} | ||
|
||
const walletAddresses = await knex('walletAddresses').select( | ||
'id', | ||
'accountId' | ||
) | ||
for (const walletAddress of walletAddresses) { | ||
const account = await knex('accounts') | ||
.where('id', walletAddress.accountId) | ||
.first() | ||
if (account) { | ||
await knex('walletAddresses') | ||
.where('id', walletAddress.id) | ||
.update({ assetCode: account.assetCode }) | ||
} | ||
} | ||
|
||
await knex('walletAddresses').update({ assetScale: 2 }) | ||
await knex('accounts').update({ assetScale: 2 }) | ||
} |
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.
I modified this to
0.01
(which is the lowest non-zero amount representable in asset scale 2) instead of0.1
. Any reason to change it back?