-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Multi Wallet Support (#1296) * Validate CN for associated_wallest in user metadata * Add associated wallets to Discovery DB * Add assocaited wallet to discovery schema * Update discovery indexing for user associated wallets * Add discovery endpoints for wallet - id * Add wallets schema to libs user validation * Update schema and user balance for associated wallet (#1299) * Update associated_wallet schema and update disc. user balance on wallet update * Update schema in libs for associated wallets * Update validate metadata in creator for assciated wallet * Fix CN test * Add another check to CN metadata upload * Lint discovery * Update user schema validator in discovery and libs * Feature collectibles metadata multihash (#1292) * Support collectibles in libs * Support metadata multihash for collectibles in discovery * Add has_collectibles indexed field to user object * Fix wallet object check * Clean up * Do not check metadata from ipfs every time * Fix alembic collisions * Handle the null cases in user metadata indexing * Forgo image size changes * Fix clean metadata for new fields Co-authored-by: Joseph Lee <joeylee0925@gmail.com> Co-authored-by: Raymond Jacobson <ray@audius.co> Co-authored-by: Saliou Diallo <saliou@audius.co>
- Loading branch information
1 parent
c5cbb06
commit df56278
Showing
18 changed files
with
560 additions
and
56 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const Web3 = require('web3') | ||
const web3 = new Web3() | ||
|
||
/** | ||
* Validates that the user id was signed by the associated wallets | ||
*/ | ||
const validateAssociatedWallets = (metadataJSON) => { | ||
if ('user_id' in metadataJSON && 'associated_wallets' in metadataJSON) { | ||
const userId = metadataJSON['user_id'] | ||
const walletMappings = metadataJSON['associated_wallets'] | ||
if (!walletMappings) return true | ||
if (typeof walletMappings !== 'object') return true | ||
const message = `AudiusUserID:${userId}` | ||
return Object.keys(walletMappings).every(wallet => { | ||
if ( | ||
typeof walletMappings[wallet] !== 'object' || | ||
walletMappings[wallet] === null || | ||
!('signature' in walletMappings[wallet]) | ||
) return false | ||
const signature = walletMappings[wallet].signature | ||
const recoveredWallet = web3.eth.accounts.recover(message, signature) | ||
return recoveredWallet === wallet | ||
}) | ||
} | ||
return true | ||
} | ||
|
||
const validateMetadata = (req, metadataJSON) => { | ||
// Check associated wallets | ||
if (typeof metadataJSON !== 'object' || metadataJSON === null) { | ||
return false | ||
} else if (!validateAssociatedWallets(metadataJSON)) { | ||
req.logger.info('Associated Wallets do not match signatures') | ||
return false | ||
} | ||
|
||
// TODO: Add more validation checks | ||
return true | ||
} | ||
|
||
module.exports = validateMetadata | ||
module.exports.validateAssociatedWallets = validateAssociatedWallets |
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
24 changes: 24 additions & 0 deletions
24
discovery-provider/alembic/versions/5a2f90f7def1_add_has_collectibles.py
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,24 @@ | ||
"""add_has_collectibles | ||
Revision ID: 5a2f90f7def1 | ||
Revises: f0a108d978ed | ||
Create Date: 2021-03-11 17:58:56.428933 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '5a2f90f7def1' | ||
down_revision = 'f0a108d978ed' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.add_column('users', sa.Column('has_collectibles', sa.Boolean(), server_default='false', nullable=False)) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column('users', 'has_collectibles') |
34 changes: 34 additions & 0 deletions
34
discovery-provider/alembic/versions/f0a108d978ed_add_associated_wallets.py
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,34 @@ | ||
"""add associated wallets | ||
Revision ID: f0a108d978ed | ||
Revises: c967ae0fcaf6 | ||
Create Date: 2021-03-09 15:34:32.229219 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'f0a108d978ed' | ||
down_revision = 'c967ae0fcaf6' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.create_table('associated_wallets', | ||
sa.Column('id', sa.Integer(), nullable=False, autoincrement=True), | ||
sa.Column('user_id', sa.Integer(), nullable=False), | ||
sa.Column('wallet', sa.String(), nullable=False), | ||
sa.Column('blockhash', sa.String(), nullable=False), | ||
sa.Column('blocknumber', sa.Integer(), nullable=False), | ||
sa.Column('is_current', sa.Boolean(), nullable=False), | ||
sa.Column('is_delete', sa.Boolean(), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_index(op.f('ix_associated_wallets_user_id'), 'associated_wallets', ['user_id', 'is_current'], unique=False) | ||
op.create_index(op.f('ix_associated_wallets_wallet'), 'associated_wallets', ['wallet', 'is_current'], unique=False) | ||
|
||
def downgrade(): | ||
op.drop_table('associated_wallets') |
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,28 @@ | ||
import logging | ||
|
||
from src.models import AssociatedWallet | ||
from src.utils import db_session | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def get_associated_user_id(args): | ||
""" | ||
Returns a user_id the associated wallet | ||
Args: | ||
args: dict The parsed args from the request | ||
args.wallet: string The wallet to find associated with an user id | ||
Returns: | ||
number representing the user id | ||
""" | ||
db = db_session.get_db_read_replica() | ||
with db.scoped_session() as session: | ||
user_id = ( | ||
session.query(AssociatedWallet.user_id) | ||
.filter(AssociatedWallet.is_current == True) | ||
.filter(AssociatedWallet.is_delete == False) | ||
.filter(AssociatedWallet.wallet == args.get('wallet')) | ||
.first() | ||
) | ||
return user_id[0] if user_id else None |
29 changes: 29 additions & 0 deletions
29
discovery-provider/src/queries/get_associated_user_wallet.py
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,29 @@ | ||
import logging | ||
|
||
from src.models import AssociatedWallet | ||
from src.utils import db_session | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_associated_user_wallet(args): | ||
""" | ||
Returns a list of associated wallets | ||
Args: | ||
args: dict The parsed args from the request | ||
args.user_id: number The blockchain user id | ||
Returns: | ||
Array of strings representing the user's associated wallets | ||
""" | ||
db = db_session.get_db_read_replica() | ||
with db.scoped_session() as session: | ||
user_wallet = ( | ||
session.query(AssociatedWallet.wallet) | ||
.filter(AssociatedWallet.is_current == True) | ||
.filter(AssociatedWallet.is_delete == False) | ||
.filter(AssociatedWallet.user_id == args.get('user_id')) | ||
.all() | ||
) | ||
return [wallet for [wallet] in user_wallet] |
Oops, something went wrong.