@nina-protocol/nina-db 0.0.90 → 0.0.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/knexfile.js +38 -3
- package/src/migrations/20250423215722_hubs_collaborators_permissions.js +21 -0
- package/src/migrations/20250424215722_hubs_collaborators_added_by.js +19 -0
- package/yarn-error.log +6817 -0
- package/dist/index.js +0 -30
- package/dist/knexfile.js +0 -43
- package/dist/migrations/20220815134115_initial_migration.js +0 -211
- package/dist/migrations/20220930214430_add_subscriptions.js +0 -23
- package/dist/migrations/20221010170539_add_hub_data_uri.js +0 -15
- package/dist/migrations/20221010185734_add_transactions.js +0 -58
- package/dist/migrations/20221012230835_add_verifications.js +0 -31
- package/dist/migrations/20221201221013_add_hub_releases_visible.js +0 -15
- package/dist/migrations/20221206184748_add_gate.js +0 -29
- package/dist/migrations/20230104184351_add_verification_active.js +0 -15
- package/dist/migrations/20230306215838_add_hub_updated_at.js +0 -15
- package/dist/migrations/20231011163511_add_release_slug.js +0 -15
- package/dist/migrations/20231031200532_add_profile.js +0 -18
- package/dist/migrations/20231112031914_post_version.js +0 -15
- package/dist/migrations/20231116215117_add_tags.js +0 -40
- package/dist/migrations/20240131143626_release_price.js +0 -16
- package/dist/migrations/20240304143626_fix_tags_content.js +0 -31
- package/dist/migrations/20240321155034_hide_release.js +0 -15
- package/dist/migrations/20240821155034_release_hidden_to_archived.js +0 -18
- package/dist/migrations/20241121155034_subscription_public_key_nullable.js +0 -15
- package/dist/migrations/20250120215722_add_ref_columns.js +0 -18
- package/dist/models/Account.js +0 -122
- package/dist/models/Exchange.js +0 -62
- package/dist/models/Hub.js +0 -86
- package/dist/models/Post.js +0 -84
- package/dist/models/Release.js +0 -282
- package/dist/models/Subscription.js +0 -57
- package/dist/models/Tag.js +0 -39
- package/dist/models/TagsReleases.js +0 -17
- package/dist/models/Transaction.js +0 -148
- package/dist/models/Verification.js +0 -50
- package/dist/models/index.js +0 -21
- package/dist/seeds/1_accounts_profile.js +0 -22
- package/dist/utils/index.js +0 -45
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param { import("knex").Knex } knex
|
|
3
|
-
* @returns { Promise<void> }
|
|
4
|
-
*/
|
|
5
|
-
export const up = function (knex) {
|
|
6
|
-
return knex.schema.alterTable('subscriptions', table => {
|
|
7
|
-
table.dropColumn('publicKey');
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* @param { import("knex").Knex } knex
|
|
12
|
-
* @returns { Promise<void> }
|
|
13
|
-
*/
|
|
14
|
-
export const down = function (knex) {
|
|
15
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param { import("knex").Knex } knex
|
|
3
|
-
* @returns { Promise<void> }
|
|
4
|
-
*/
|
|
5
|
-
export const up = function (knex) {
|
|
6
|
-
return knex.schema.table('subscriptions', table => {
|
|
7
|
-
table.string('ref').nullable();
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* @param { import("knex").Knex } knex
|
|
12
|
-
* @returns { Promise<void> }
|
|
13
|
-
*/
|
|
14
|
-
export const down = function (knex) {
|
|
15
|
-
return knex.schema.table('subscriptions', table => {
|
|
16
|
-
table.dropColumn('ref');
|
|
17
|
-
});
|
|
18
|
-
};
|
package/dist/models/Account.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { Model } from 'objection';
|
|
2
|
-
import Exchange from './Exchange.js';
|
|
3
|
-
import Hub from './Hub.js';
|
|
4
|
-
import Post from './Post.js';
|
|
5
|
-
import Release from './Release.js';
|
|
6
|
-
import Verification from './Verification.js';
|
|
7
|
-
import Subscription from './Subscription.js';
|
|
8
|
-
export default class Account extends Model {
|
|
9
|
-
static tableName = 'accounts';
|
|
10
|
-
static idColumn = 'id';
|
|
11
|
-
static jsonSchema = {
|
|
12
|
-
type: 'object',
|
|
13
|
-
required: ['publicKey'],
|
|
14
|
-
properties: {
|
|
15
|
-
publicKey: { type: 'string' },
|
|
16
|
-
image: { type: 'string' },
|
|
17
|
-
description: { type: 'string' },
|
|
18
|
-
displayName: { type: 'string' },
|
|
19
|
-
handle: { type: 'string' },
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
static findOrCreate = async (publicKey) => {
|
|
23
|
-
let account = await Account.query().findOne({ publicKey });
|
|
24
|
-
if (account) {
|
|
25
|
-
return account;
|
|
26
|
-
}
|
|
27
|
-
account = await Account.query().insert({ publicKey });
|
|
28
|
-
console.log('Inserted Account: ', publicKey);
|
|
29
|
-
return account;
|
|
30
|
-
};
|
|
31
|
-
format = async () => {
|
|
32
|
-
const verifications = await this.$relatedQuery('verifications').where('active', true);
|
|
33
|
-
if (verifications) {
|
|
34
|
-
for await (let verification of verifications) {
|
|
35
|
-
await verification.format();
|
|
36
|
-
}
|
|
37
|
-
this.verifications = verifications;
|
|
38
|
-
}
|
|
39
|
-
delete this.id;
|
|
40
|
-
const followers = await Subscription.query().where('to', this.publicKey).range(0, 0);
|
|
41
|
-
this.followers = followers.total;
|
|
42
|
-
};
|
|
43
|
-
static relationMappings = () => ({
|
|
44
|
-
published: {
|
|
45
|
-
relation: Model.HasManyRelation,
|
|
46
|
-
modelClass: Release,
|
|
47
|
-
join: {
|
|
48
|
-
from: 'accounts.id',
|
|
49
|
-
to: 'releases.publisherId'
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
collected: {
|
|
53
|
-
relation: Model.ManyToManyRelation,
|
|
54
|
-
modelClass: Release,
|
|
55
|
-
join: {
|
|
56
|
-
from: 'accounts.id',
|
|
57
|
-
through: {
|
|
58
|
-
from: 'releases_collected.accountId',
|
|
59
|
-
to: 'releases_collected.releaseId',
|
|
60
|
-
},
|
|
61
|
-
to: 'releases.id'
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
exchangesInitialized: {
|
|
65
|
-
relation: Model.HasManyRelation,
|
|
66
|
-
modelClass: Exchange,
|
|
67
|
-
join: {
|
|
68
|
-
from: 'accounts.id',
|
|
69
|
-
to: 'exchanges.initializerId',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
exchangesCompleted: {
|
|
73
|
-
relation: Model.HasManyRelation,
|
|
74
|
-
modelClass: Exchange,
|
|
75
|
-
join: {
|
|
76
|
-
from: 'accounts.id',
|
|
77
|
-
to: 'exchanges.completedById',
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
hubs: {
|
|
81
|
-
relation: Model.ManyToManyRelation,
|
|
82
|
-
modelClass: Hub,
|
|
83
|
-
join: {
|
|
84
|
-
from: 'accounts.id',
|
|
85
|
-
through: {
|
|
86
|
-
from: 'hubs_collaborators.accountId',
|
|
87
|
-
to: 'hubs_collaborators.hubId',
|
|
88
|
-
extra: ['hubCollaboratorPublicKey'],
|
|
89
|
-
},
|
|
90
|
-
to: 'hubs.id',
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
posts: {
|
|
94
|
-
relation: Model.HasManyRelation,
|
|
95
|
-
modelClass: Post,
|
|
96
|
-
join: {
|
|
97
|
-
from: 'accounts.id',
|
|
98
|
-
to: 'posts.publisherId',
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
revenueShares: {
|
|
102
|
-
relation: Model.ManyToManyRelation,
|
|
103
|
-
modelClass: Release,
|
|
104
|
-
join: {
|
|
105
|
-
from: 'accounts.id',
|
|
106
|
-
through: {
|
|
107
|
-
from: 'releases_revenue_share.accountId',
|
|
108
|
-
to: 'releases_revenue_share.releaseId',
|
|
109
|
-
},
|
|
110
|
-
to: 'releases.id',
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
verifications: {
|
|
114
|
-
relation: Model.HasManyRelation,
|
|
115
|
-
modelClass: Verification,
|
|
116
|
-
join: {
|
|
117
|
-
from: 'accounts.id',
|
|
118
|
-
to: 'verifications.accountId',
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
}
|
package/dist/models/Exchange.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Model } from 'objection';
|
|
2
|
-
import Account from './Account.js';
|
|
3
|
-
import Release from './Release.js';
|
|
4
|
-
export default class Exchange extends Model {
|
|
5
|
-
static tableName = 'exchanges';
|
|
6
|
-
static idColum = 'id';
|
|
7
|
-
static jsonSchema = {
|
|
8
|
-
type: 'object',
|
|
9
|
-
required: ['publicKey', 'isSale', 'initializerAmount', 'expectedAmount', 'cancelled', 'createdAt'],
|
|
10
|
-
properties: {
|
|
11
|
-
publicKey: { type: 'string' },
|
|
12
|
-
isSale: { type: 'boolean' },
|
|
13
|
-
initializerAmount: { type: 'number' },
|
|
14
|
-
expectedAmount: { type: 'number' },
|
|
15
|
-
cancelled: { type: 'boolean' },
|
|
16
|
-
createdAt: { type: 'string' },
|
|
17
|
-
updatedAt: { type: 'string' },
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
format = async () => {
|
|
21
|
-
const initializer = await this.$relatedQuery('initializer');
|
|
22
|
-
const completedBy = await this.$relatedQuery('completedBy');
|
|
23
|
-
const release = await this.$relatedQuery('release').select('publicKey');
|
|
24
|
-
if (completedBy) {
|
|
25
|
-
await completedBy.format();
|
|
26
|
-
this.completedBy = completedBy;
|
|
27
|
-
}
|
|
28
|
-
this.release = release.publicKey;
|
|
29
|
-
await initializer.format();
|
|
30
|
-
this.initializer = initializer;
|
|
31
|
-
delete this.id;
|
|
32
|
-
delete this.initializerId;
|
|
33
|
-
delete this.completedById;
|
|
34
|
-
delete this.releaseId;
|
|
35
|
-
};
|
|
36
|
-
static relationMappings = () => ({
|
|
37
|
-
initializer: {
|
|
38
|
-
relation: Model.HasOneRelation,
|
|
39
|
-
modelClass: Account,
|
|
40
|
-
join: {
|
|
41
|
-
from: 'exchanges.initializerId',
|
|
42
|
-
to: 'accounts.id',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
completedBy: {
|
|
46
|
-
relation: Model.HasOneRelation,
|
|
47
|
-
modelClass: Account,
|
|
48
|
-
join: {
|
|
49
|
-
from: 'exchanges.completedById',
|
|
50
|
-
to: 'accounts.id',
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
release: {
|
|
54
|
-
relation: Model.HasOneRelation,
|
|
55
|
-
modelClass: Release,
|
|
56
|
-
join: {
|
|
57
|
-
from: 'exchanges.releaseId',
|
|
58
|
-
to: 'releases.id',
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
}
|
package/dist/models/Hub.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { Model } from 'objection';
|
|
2
|
-
import { stripHtmlIfNeeded } from '../utils/index.js';
|
|
3
|
-
import Account from './Account.js';
|
|
4
|
-
import Release from './Release.js';
|
|
5
|
-
import Post from './Post.js';
|
|
6
|
-
import Subscription from './Subscription.js';
|
|
7
|
-
export default class Hub extends Model {
|
|
8
|
-
static get tableName() {
|
|
9
|
-
return 'hubs';
|
|
10
|
-
}
|
|
11
|
-
static get idColumn() {
|
|
12
|
-
return 'id';
|
|
13
|
-
}
|
|
14
|
-
static get jsonSchema() {
|
|
15
|
-
return {
|
|
16
|
-
type: 'object',
|
|
17
|
-
required: ['publicKey', 'handle', 'data', 'dataUri', 'datetime'],
|
|
18
|
-
properties: {
|
|
19
|
-
publicKey: { type: 'string' },
|
|
20
|
-
handle: { type: 'string' },
|
|
21
|
-
data: { type: 'object' },
|
|
22
|
-
dataUri: { type: 'string' },
|
|
23
|
-
datetime: { type: 'string' },
|
|
24
|
-
updatedAt: { type: 'string' },
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
async format() {
|
|
29
|
-
const authority = await this.$relatedQuery('authority').select('publicKey');
|
|
30
|
-
this.authority = authority.publicKey;
|
|
31
|
-
delete this.authorityId;
|
|
32
|
-
delete this.id;
|
|
33
|
-
stripHtmlIfNeeded(this.data, 'description');
|
|
34
|
-
const followers = await Subscription.query().where('to', this.publicKey).range(0, 0);
|
|
35
|
-
this.followers = followers.total;
|
|
36
|
-
}
|
|
37
|
-
static relationMappings = () => ({
|
|
38
|
-
authority: {
|
|
39
|
-
relation: Model.HasOneRelation,
|
|
40
|
-
modelClass: Account,
|
|
41
|
-
join: {
|
|
42
|
-
from: 'hubs.authorityId',
|
|
43
|
-
to: 'accounts.id',
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
collaborators: {
|
|
47
|
-
relation: Model.ManyToManyRelation,
|
|
48
|
-
modelClass: Account,
|
|
49
|
-
join: {
|
|
50
|
-
from: 'hubs.id',
|
|
51
|
-
through: {
|
|
52
|
-
from: 'hubs_collaborators.hubId',
|
|
53
|
-
to: 'hubs_collaborators.accountId',
|
|
54
|
-
extra: ['hubCollaboratorPublicKey'],
|
|
55
|
-
},
|
|
56
|
-
to: 'accounts.id',
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
posts: {
|
|
60
|
-
relation: Model.ManyToManyRelation,
|
|
61
|
-
modelClass: Post,
|
|
62
|
-
join: {
|
|
63
|
-
from: 'hubs.id',
|
|
64
|
-
through: {
|
|
65
|
-
from: 'hubs_posts.hubId',
|
|
66
|
-
to: 'hubs_posts.postId',
|
|
67
|
-
extra: ['hubPostPublicKey'],
|
|
68
|
-
},
|
|
69
|
-
to: 'posts.id',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
releases: {
|
|
73
|
-
relation: Model.ManyToManyRelation,
|
|
74
|
-
modelClass: Release,
|
|
75
|
-
join: {
|
|
76
|
-
from: 'hubs.id',
|
|
77
|
-
through: {
|
|
78
|
-
from: 'hubs_releases.hubId',
|
|
79
|
-
to: 'hubs_releases.releaseId',
|
|
80
|
-
extra: ['hubReleasePublicKey', 'visible'],
|
|
81
|
-
},
|
|
82
|
-
to: 'releases.id',
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
}
|
package/dist/models/Post.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Model } from 'objection';
|
|
2
|
-
import { stripHtmlIfNeeded } from '../utils/index.js';
|
|
3
|
-
import Account from './Account.js';
|
|
4
|
-
import Hub from './Hub.js';
|
|
5
|
-
import Release from './Release.js';
|
|
6
|
-
class Post extends Model {
|
|
7
|
-
static get tableName() {
|
|
8
|
-
return 'posts';
|
|
9
|
-
}
|
|
10
|
-
static get idColumn() {
|
|
11
|
-
return 'id';
|
|
12
|
-
}
|
|
13
|
-
static get jsonSchema() {
|
|
14
|
-
return {
|
|
15
|
-
type: 'object',
|
|
16
|
-
required: ['publicKey', 'data', 'datetime', 'version'],
|
|
17
|
-
properties: {
|
|
18
|
-
publicKey: { type: 'string' },
|
|
19
|
-
data: { type: 'object' },
|
|
20
|
-
datetime: { type: 'string' },
|
|
21
|
-
version: { type: 'string' },
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
async format() {
|
|
26
|
-
const publisher = await this.$relatedQuery('publisher').select('publicKey');
|
|
27
|
-
const publishedThroughHub = await this.$relatedQuery('publishedThroughHub');
|
|
28
|
-
this.publisher = publisher.publicKey;
|
|
29
|
-
if (publishedThroughHub) {
|
|
30
|
-
this.publishedThroughHub = publishedThroughHub.publicKey;
|
|
31
|
-
this.hub = publishedThroughHub;
|
|
32
|
-
delete this.hub.id;
|
|
33
|
-
delete this.hub.authorityId;
|
|
34
|
-
}
|
|
35
|
-
delete this.publisherId;
|
|
36
|
-
delete this.id;
|
|
37
|
-
delete this.hubId;
|
|
38
|
-
stripHtmlIfNeeded(this.data, 'body');
|
|
39
|
-
}
|
|
40
|
-
static relationMappings = () => ({
|
|
41
|
-
publishedThroughHub: {
|
|
42
|
-
relation: Model.BelongsToOneRelation,
|
|
43
|
-
modelClass: Hub,
|
|
44
|
-
join: {
|
|
45
|
-
from: 'posts.hubId',
|
|
46
|
-
to: 'hubs.id',
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
publisher: {
|
|
50
|
-
relation: Model.HasOneRelation,
|
|
51
|
-
modelClass: Account,
|
|
52
|
-
join: {
|
|
53
|
-
from: 'posts.publisherId',
|
|
54
|
-
to: 'accounts.id',
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
hubs: {
|
|
58
|
-
relation: Model.ManyToManyRelation,
|
|
59
|
-
modelClass: Hub,
|
|
60
|
-
join: {
|
|
61
|
-
from: 'posts.id',
|
|
62
|
-
through: {
|
|
63
|
-
from: 'hubs_posts.postId',
|
|
64
|
-
to: 'hubs_posts.hubId',
|
|
65
|
-
extra: ['hubPostPublicKey'],
|
|
66
|
-
},
|
|
67
|
-
to: 'hubs.id',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
releases: {
|
|
71
|
-
relation: Model.ManyToManyRelation,
|
|
72
|
-
modelClass: Release,
|
|
73
|
-
join: {
|
|
74
|
-
from: 'posts.id',
|
|
75
|
-
through: {
|
|
76
|
-
from: 'posts_releases.postId',
|
|
77
|
-
to: 'posts_releases.releaseId',
|
|
78
|
-
},
|
|
79
|
-
to: 'releases.id',
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
export default Post;
|
package/dist/models/Release.js
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import anchor from '@project-serum/anchor';
|
|
2
|
-
import { Metaplex } from '@metaplex-foundation/js';
|
|
3
|
-
import { Model } from 'objection';
|
|
4
|
-
import { stripHtmlIfNeeded, tweetNewRelease } from '../utils/index.js';
|
|
5
|
-
import Account from './Account.js';
|
|
6
|
-
import Exchange from './Exchange.js';
|
|
7
|
-
import Hub from './Hub.js';
|
|
8
|
-
import Post from './Post.js';
|
|
9
|
-
import Tag from './Tag.js';
|
|
10
|
-
import axios from 'axios';
|
|
11
|
-
import promiseRetry from 'promise-retry';
|
|
12
|
-
import { customAlphabet } from 'nanoid';
|
|
13
|
-
const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
14
|
-
const randomStringGenerator = customAlphabet(alphabet, 12);
|
|
15
|
-
export default class Release extends Model {
|
|
16
|
-
static tableName = 'releases';
|
|
17
|
-
static idColumn = 'id';
|
|
18
|
-
static jsonSchema = {
|
|
19
|
-
type: 'object',
|
|
20
|
-
required: ['publicKey', 'mint', 'metadata', 'datetime', 'slug', 'price'],
|
|
21
|
-
properties: {
|
|
22
|
-
publicKey: { type: 'string' },
|
|
23
|
-
mint: { type: 'string' },
|
|
24
|
-
slug: { type: 'string' },
|
|
25
|
-
metadata: {
|
|
26
|
-
type: 'object',
|
|
27
|
-
required: ['name', 'symbol', 'description', 'image', 'properties',],
|
|
28
|
-
properties: {
|
|
29
|
-
name: { type: 'string' },
|
|
30
|
-
symbol: { type: 'string' },
|
|
31
|
-
description: { type: 'string' },
|
|
32
|
-
properties: {
|
|
33
|
-
type: 'object',
|
|
34
|
-
properties: {
|
|
35
|
-
artist: { type: 'string' },
|
|
36
|
-
title: { type: 'string' },
|
|
37
|
-
date: { type: 'string' },
|
|
38
|
-
files: { type: 'array' },
|
|
39
|
-
category: { type: 'string' },
|
|
40
|
-
creators: { type: 'array' },
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
price: { type: 'string' },
|
|
46
|
-
archived: { type: 'boolean' },
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
static findOrCreate = async (publicKey, hubPublicKey = null) => {
|
|
50
|
-
try {
|
|
51
|
-
let release = await Release.query().findOne({ publicKey });
|
|
52
|
-
if (release) {
|
|
53
|
-
return release;
|
|
54
|
-
}
|
|
55
|
-
const connection = new anchor.web3.Connection(process.env.SOLANA_CLUSTER_URL);
|
|
56
|
-
const provider = new anchor.AnchorProvider(connection, {}, { commitment: 'confirmed' });
|
|
57
|
-
const program = await anchor.Program.at(process.env.NINA_PROGRAM_ID, provider);
|
|
58
|
-
const metaplex = new Metaplex(connection);
|
|
59
|
-
let attempts = 0;
|
|
60
|
-
const releaseAccount = await promiseRetry(async (retry) => {
|
|
61
|
-
try {
|
|
62
|
-
attempts += 1;
|
|
63
|
-
const result = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed');
|
|
64
|
-
return result;
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.log('error fetching release account', error);
|
|
68
|
-
retry(error);
|
|
69
|
-
}
|
|
70
|
-
}, {
|
|
71
|
-
retries: 50,
|
|
72
|
-
minTimeout: 500,
|
|
73
|
-
maxTimeout: 1500,
|
|
74
|
-
});
|
|
75
|
-
let metadataAccount = (await metaplex.nfts().findAllByMintList({ mints: [releaseAccount.releaseMint] }, { commitment: 'confirmed' }))[0];
|
|
76
|
-
if (!metadataAccount) {
|
|
77
|
-
throw new Error('No metadata account found for release - is not a complete release');
|
|
78
|
-
}
|
|
79
|
-
let json;
|
|
80
|
-
try {
|
|
81
|
-
json = (await axios.get(metadataAccount.uri.replace('www.', '').replace('arweave.net', 'gateway.irys.xyz'))).data;
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
json = (await axios.get(metadataAccount.uri.replace('gateway.irys.xyz', 'arweave.net'))).data;
|
|
85
|
-
}
|
|
86
|
-
const slug = await this.generateSlug(json);
|
|
87
|
-
let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
|
|
88
|
-
release = await this.createRelease({
|
|
89
|
-
publicKey,
|
|
90
|
-
mint: releaseAccount.releaseMint.toBase58(),
|
|
91
|
-
metadata: json,
|
|
92
|
-
datetime: new Date(releaseAccount.releaseDatetime.toNumber() * 1000).toISOString(),
|
|
93
|
-
slug,
|
|
94
|
-
publisherId: publisher.id,
|
|
95
|
-
releaseAccount
|
|
96
|
-
});
|
|
97
|
-
if (hubPublicKey) {
|
|
98
|
-
const hub = await Hub.query().findOne({ publicKey: hubPublicKey });
|
|
99
|
-
await release.$query().patch({ hubId: hub.id });
|
|
100
|
-
await Hub.relatedQuery('releases').for(hub.id).patch({
|
|
101
|
-
visible: true,
|
|
102
|
-
}).where({ id: release.id });
|
|
103
|
-
}
|
|
104
|
-
return release;
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
console.log('error finding or creating release: ', error);
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
static createRelease = async ({ publicKey, mint, metadata, datetime, publisherId, releaseAccount }) => {
|
|
112
|
-
const slug = await this.generateSlug(metadata);
|
|
113
|
-
const price = releaseAccount.account?.price?.toNumber() || releaseAccount?.price?.toNumber() || 0;
|
|
114
|
-
const paymentMint = releaseAccount.account?.paymentMint.toBase58() || releaseAccount?.paymentMint.toBase58();
|
|
115
|
-
const release = await Release.query().insertGraph({
|
|
116
|
-
publicKey,
|
|
117
|
-
mint,
|
|
118
|
-
metadata,
|
|
119
|
-
slug,
|
|
120
|
-
datetime,
|
|
121
|
-
publisherId,
|
|
122
|
-
price: `${price}`,
|
|
123
|
-
paymentMint,
|
|
124
|
-
archived: false
|
|
125
|
-
});
|
|
126
|
-
if (metadata.properties.tags) {
|
|
127
|
-
for await (let tag of metadata.properties.tags) {
|
|
128
|
-
const tagRecord = await Tag.findOrCreate(tag);
|
|
129
|
-
await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id).onConflict(['tagId', 'releaseId']).ignore();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
await this.processRevenueShares(releaseAccount, release);
|
|
133
|
-
tweetNewRelease(metadata, publisherId, slug);
|
|
134
|
-
return release;
|
|
135
|
-
};
|
|
136
|
-
static processRevenueShares = async (releaseData, releaseRecord) => {
|
|
137
|
-
const royaltyRecipients = releaseData.account?.royaltyRecipients || releaseData.royaltyRecipients;
|
|
138
|
-
for await (let recipient of royaltyRecipients) {
|
|
139
|
-
try {
|
|
140
|
-
if (recipient.recipientAuthority.toBase58() !== "11111111111111111111111111111111") {
|
|
141
|
-
const recipientAccount = await Account.findOrCreate(recipient.recipientAuthority.toBase58());
|
|
142
|
-
const revenueShares = (await recipientAccount.$relatedQuery('revenueShares')).map(revenueShare => revenueShare.id);
|
|
143
|
-
if (!revenueShares.includes(releaseRecord.id) && recipient.percentShare.toNumber() > 0) {
|
|
144
|
-
await Account.relatedQuery('revenueShares').for(recipientAccount.id).relate(releaseRecord.id);
|
|
145
|
-
}
|
|
146
|
-
else if (revenueShares.includes(releaseRecord.id) && recipient.percentShare.toNumber() === 0) {
|
|
147
|
-
await Account.relatedQuery('revenueShares').for(recipientAccount.id).unrelate().where('id', releaseRecord.id);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
console.log('error processing royaltyRecipients: ', error);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
static generateSlug = async (metadata) => {
|
|
157
|
-
let string = metadata.name;
|
|
158
|
-
if (string.length > 200) {
|
|
159
|
-
string = string.substring(0, 200);
|
|
160
|
-
}
|
|
161
|
-
const slug = string
|
|
162
|
-
.normalize('NFKD').replace(/[\u0300-\u036F]/g, '') // remove accents and convert to closest ascii equivalent
|
|
163
|
-
.toLowerCase() // convert to lowercase
|
|
164
|
-
.replace('-', '') // remove hyphens
|
|
165
|
-
.replace(/ +/g, ' ') // remove spaces
|
|
166
|
-
.replace(/ /g, '-') // replace spaces with hyphens
|
|
167
|
-
.replace(/[^a-zA-Z0-9-]/g, '-') // replace non-alphanumeric characters with hyphens
|
|
168
|
-
.replace(/-+/g, '-') // replace multiple hyphens with single hyphen
|
|
169
|
-
.replace(/-$/, ''); // remove trailing hyphens
|
|
170
|
-
const existingRelease = await Release.query().findOne({ slug });
|
|
171
|
-
if (existingRelease) {
|
|
172
|
-
return `${slug}-${randomStringGenerator()}`;
|
|
173
|
-
}
|
|
174
|
-
return slug;
|
|
175
|
-
};
|
|
176
|
-
format = async () => {
|
|
177
|
-
const publisher = await this.$relatedQuery('publisher');
|
|
178
|
-
const publishedThroughHub = await this.$relatedQuery('publishedThroughHub');
|
|
179
|
-
if (publishedThroughHub) {
|
|
180
|
-
this.publishedThroughHub = publishedThroughHub.publicKey;
|
|
181
|
-
this.hub = publishedThroughHub;
|
|
182
|
-
delete this.hub.id;
|
|
183
|
-
const authority = await this.hub.$relatedQuery('authority').select('publicKey');
|
|
184
|
-
this.hub.authority = authority.publicKey;
|
|
185
|
-
delete this.hub.authorityId;
|
|
186
|
-
}
|
|
187
|
-
await publisher.format();
|
|
188
|
-
this.publisher = publisher.publicKey;
|
|
189
|
-
this.publisherAccount = publisher;
|
|
190
|
-
delete this.publisherId;
|
|
191
|
-
delete this.hubId;
|
|
192
|
-
delete this.id;
|
|
193
|
-
stripHtmlIfNeeded(this.metadata, 'description');
|
|
194
|
-
};
|
|
195
|
-
static relationMappings = () => ({
|
|
196
|
-
publishedThroughHub: {
|
|
197
|
-
relation: Model.BelongsToOneRelation,
|
|
198
|
-
modelClass: Hub,
|
|
199
|
-
join: {
|
|
200
|
-
from: 'releases.hubId',
|
|
201
|
-
to: 'hubs.id',
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
publisher: {
|
|
205
|
-
relation: Model.HasOneRelation,
|
|
206
|
-
modelClass: Account,
|
|
207
|
-
join: {
|
|
208
|
-
from: 'releases.publisherId',
|
|
209
|
-
to: 'accounts.id',
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
collectors: {
|
|
213
|
-
relation: Model.ManyToManyRelation,
|
|
214
|
-
modelClass: Account,
|
|
215
|
-
join: {
|
|
216
|
-
from: 'releases.id',
|
|
217
|
-
through: {
|
|
218
|
-
from: 'releases_collected.releaseId',
|
|
219
|
-
to: 'releases_collected.accountId',
|
|
220
|
-
},
|
|
221
|
-
to: 'accounts.id',
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
exchanges: {
|
|
225
|
-
relation: Model.HasManyRelation,
|
|
226
|
-
modelClass: Exchange,
|
|
227
|
-
join: {
|
|
228
|
-
from: 'releases.id',
|
|
229
|
-
to: 'exchanges.releaseId',
|
|
230
|
-
},
|
|
231
|
-
},
|
|
232
|
-
hubs: {
|
|
233
|
-
relation: Model.ManyToManyRelation,
|
|
234
|
-
modelClass: Hub,
|
|
235
|
-
join: {
|
|
236
|
-
from: 'releases.id',
|
|
237
|
-
through: {
|
|
238
|
-
from: 'hubs_releases.releaseId',
|
|
239
|
-
to: 'hubs_releases.hubId',
|
|
240
|
-
extra: ['hubReleasePublicKey'],
|
|
241
|
-
},
|
|
242
|
-
to: 'hubs.id',
|
|
243
|
-
},
|
|
244
|
-
},
|
|
245
|
-
posts: {
|
|
246
|
-
relation: Model.ManyToManyRelation,
|
|
247
|
-
modelClass: Post,
|
|
248
|
-
join: {
|
|
249
|
-
from: 'releases.id',
|
|
250
|
-
through: {
|
|
251
|
-
from: 'posts_releases.releaseId',
|
|
252
|
-
to: 'posts_releases.postId',
|
|
253
|
-
},
|
|
254
|
-
to: 'posts.id',
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
revenueShareRecipients: {
|
|
258
|
-
relation: Model.ManyToManyRelation,
|
|
259
|
-
modelClass: Account,
|
|
260
|
-
join: {
|
|
261
|
-
from: 'releases.id',
|
|
262
|
-
through: {
|
|
263
|
-
from: 'releases_revenue_share.releaseId',
|
|
264
|
-
to: 'releases_revenue_share.accountId',
|
|
265
|
-
},
|
|
266
|
-
to: 'accounts.id',
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
tags: {
|
|
270
|
-
relation: Model.ManyToManyRelation,
|
|
271
|
-
modelClass: Tag,
|
|
272
|
-
join: {
|
|
273
|
-
from: 'releases.id',
|
|
274
|
-
through: {
|
|
275
|
-
from: 'tags_releases.releaseId',
|
|
276
|
-
to: 'tags_releases.tagId',
|
|
277
|
-
},
|
|
278
|
-
to: 'tags.id',
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
|
-
});
|
|
282
|
-
}
|