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

allow delegated payer on hub init #1135

Merged
merged 2 commits into from
Nov 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/hubs/components/HubsModal.js
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ const HubsModal = (props) => {
>
<StyledPaper>
<Header>
<Typography fontWeight="700">{`Hubs featuring: ${metadata.properties.artist.substring(
<Typography fontWeight="700">{`Hubs featuring: ${metadata.properties.artist?.substring(
0,
100
)} - "${metadata.properties.title.substring(0, 100)}"`}</Typography>
2 changes: 1 addition & 1 deletion js/sdk/src/contexts/Audio/audio.js
Original file line number Diff line number Diff line change
@@ -296,7 +296,7 @@ const audioPlayerContextHelper = ({
if (playlistEntry) {
setPlaylist([...playlist, playlistEntry])
return {
msg: `${playlistEntry.artist.substring(
msg: `${playlistEntry.artist?.substring(
0,
100
)} - ${playlistEntry.title.substring(0, 100)} added to queue`,
2 changes: 1 addition & 1 deletion js/web/components/CollectorModal.js
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ const CollectorModal = (props) => {
>
<StyledPaper>
<Header>
<Typography fontWeight="700">{`${metadata.properties.artist.substring(
<Typography fontWeight="700">{`${metadata.properties.artist?.substring(
0,
100
)} - "${metadata.properties.title.substring(
2 changes: 1 addition & 1 deletion js/web/components/HubsModal.js
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ const HubsModal = (props) => {
>
<StyledPaper>
<Header>
<Typography fontWeight="700">{`Hubs featuring: ${metadata.properties.artist.substring(
<Typography fontWeight="700">{`Hubs featuring: ${metadata.properties.artist?.substring(
0,
100
)} - "${metadata.properties.title.substring(
6 changes: 3 additions & 3 deletions js/web/components/ReleaseCard.js
Original file line number Diff line number Diff line change
@@ -172,8 +172,8 @@ const ReleaseCard = (props) => {
</Link>
</Typography>
<Typography variant="h4" color="white" align="left">
{metadata?.properties?.artist.substring(0, 100) ||
metadata?.artist.substring(0, 100)}{' '}
{metadata?.properties?.artist?.substring(0, 100) ||
metadata?.artist?.substring(0, 100)}{' '}
- <i>{title}</i>
</Typography>
</>
@@ -186,7 +186,7 @@ const ReleaseCard = (props) => {
src={
artwork?.meta.status === undefined ? '' : artwork.meta.previewUrl
}
alt={metadata.artist}
alt={metadata.artist | 'alt'}
layout="responsive"
height={350}
width={350}
4 changes: 3 additions & 1 deletion programs/nina/src/errors.rs
Original file line number Diff line number Diff line change
@@ -103,5 +103,7 @@ pub enum ErrorCode {
#[msg("Post Update Via Hub Delegated Payer Mismatch")]
PostUpdateViaHubPostDelegatePayerMismatch,
#[msg("Post Init Via Hub Delegated Payer Mismatch")]
PostInitViaHubDelegatePayerMismatch
PostInitViaHubDelegatePayerMismatch,
#[msg("Hub Init Delegated Payer Mismatch")]
HubInitDelegatePayerMismatch,
}
18 changes: 14 additions & 4 deletions programs/nina/src/instructions/hub_init.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use anchor_lang::prelude::*;
use anchor_spl::token::{self, Token};
use crate::state::*;
use crate::utils::{wrapped_sol};
use crate::utils::{wrapped_sol,file_service_account};
use crate::errors::ErrorCode;

#[derive(Accounts)]
#[instruction(params: HubInitParams)]
pub struct HubInit<'info> {
#[account(mut)]
pub authority: Signer<'info>,
pub payer: Signer<'info>,
/// CHECK: This is safe because we check in the handler that authority === payer
/// or that payer is nina operated file-service wallet
pub authority: UncheckedAccount<'info>,
#[account(
init,
seeds = [b"nina-hub".as_ref(), params.handle.as_bytes()],
bump,
payer = authority,
payer = payer,
space = 337
)]
pub hub: AccountLoader<'info, Hub>,
@@ -26,7 +30,7 @@ pub struct HubInit<'info> {
init,
seeds = [b"nina-hub-collaborator".as_ref(), hub.key().as_ref(), authority.key().as_ref()],
bump,
payer = authority,
payer = payer,
space = 147,
)]
pub hub_collaborator: Account<'info, HubCollaborator>,
@@ -40,6 +44,12 @@ pub fn handler (
ctx: Context<HubInit>,
params: HubInitParams,
) -> Result<()> {
if ctx.accounts.payer.key() != ctx.accounts.authority.key() {
if ctx.accounts.payer.key() != file_service_account::ID {
return Err(ErrorCode::HubInitDelegatePayerMismatch.into());
}
}

Hub::check_hub_fees(
params.publish_fee,
params.referral_fee
2 changes: 2 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
@@ -3757,6 +3757,7 @@ describe('Hub', async () => {
await nina.rpc.hubInit(
hubParams, {
accounts: {
payer: provider.wallet.publicKey,
authority: provider.wallet.publicKey,
hub,
hubSigner,
@@ -3819,6 +3820,7 @@ describe('Hub', async () => {
await nina.rpc.hubInit(
hubParams, {
accounts: {
payer: provider.wallet.publicKey,
authority: provider.wallet.publicKey,
hub,
hubSigner,