Skip to content

Commit

Permalink
Update uploader task to work with release v0.1.0 (#134)
Browse files Browse the repository at this point in the history
* uploader task for assets and relationships

* adapted batch uploader

* Update README.md

* updated readme instructions

---------

Co-authored-by: Brent Ju <[email protected]>
Co-authored-by: Raul <[email protected]>
Co-authored-by: brentju <[email protected]>
  • Loading branch information
4 people committed Nov 21, 2023
1 parent 6e0897c commit f356d18
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 193 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,55 @@ Read Story Block
npx hardhat sp:read-ip-asset--network <network> <franchiseId> <IPAssetId>
```

Upload Story Blocks and Relationships

This section requires more detail to establish how to format an input JSON data file. In the file, the data should be separated under "ip-assets" and "relationships".

The IP Assets are stored in arrays and represented as JSON objects. For each story block, the following fields are required:
```
// example:
stories: [
// this is an individual story to be uploaded.
{
"id": null,
"ipAssetType": "STORY",
"name": "The Full Grain World Bible",
"description": "Lorem Ipsum",
"mediaURL": "https://www.youtube.com/watch?v=9bZkp7q19f0"
}
]
```

The ID is initially set to null to identify an IPAsset that is yet to be uploaded; the file will be rewritten once blocks are successfully uploaded. This means, once the script finished if some batch txs failed, running the script again will only try to upload the failed IP Assets (since it skips ids that are not null)

To upload relationships, the following fields are needed:

```
"relationships": [
{
"sourceContract": "same", // Address of the source contract, or "same" if it's the franchise passed as parameter
"sourceAssetType": "stories", // key for the source IPA data array in the JSON
"sourceAssetIndex": 0, // Index of the source IPA in the array correspondent to the key above
"destContract": "same", // Address of the destination contract, or "same" if it's the franchise passed as parameter
"destAssetType": "characters", // key for the destination IPA data array in the JSON
"destAssetIndex": 0, // Index of the destination IPA in the array correspondent to the key above
"data": "0x", // Hook params, if any
"name": "TEST_RELATIONSHIP", // Name of the relationship, as per SPIP
"ttl": 1, // Int, duration in seconds of the relationship, in case it can be time limited. Ignored otherwise
"sourceId": null, //null in the beginning since the IPAs are not uploaded, will be set by the script
"destId": null, //null in the beginning since the IPAs are not uploaded, will be set by the script
"relationshipId": null //null in the beginning since relationship is unset, it will be the hash of name.
}
]
```

[The full example JSON is in script/data/data_example.json](/script/data/data_example.json)

To call the task, use the following:
```
npx hardhat --network <network> -sp:uploader <franchiseId> <address that receives the IPAs> <pathname of JSON data> --batchSize <optional number of entried batched per tx>
```

### Working with a local network

Foundry comes with local network [anvil](https://book.getfoundry.sh/anvil/index.html) baked in, and allows us to deploy to our local network for quick testing locally.
Expand Down
7 changes: 4 additions & 3 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const createFranchise = require("./script/hardhat/createFranchise.js");
const createIPAsset = require("./script/hardhat/createIPAsset.js");
const getIPAssetRegistryAddress = require("./script/hardhat/getIPAssetRegistryAddress.js");
const getIPAsset = require("./script/hardhat/getIPAsset.js");
const sbUploader = require("./script/hardhat/sbUploader.js");
const batchUploader = require("./script/hardhat/batchUploader.js");
const namespacedStorageKey = require("./script/hardhat/namespacedStorageKey.js");
const { task } = require("hardhat/config");

Expand Down Expand Up @@ -59,17 +59,18 @@ task('sp:read-ip-asset')

task('sp:uploader')
.addPositionalParam('franchiseId', 'Id of the Franchise to create the IP Assets in, as given by FranchiseRegistry contract')
.addPositionalParam('receiver', 'Address that will receive the IP Assets')
.addPositionalParam('filePath', 'path to the Json data')
.addOptionalParam('batchSize', 'Number of blocks to upload in each batch', 100, types.int)
.setDescription('Mass upload IP Assets from a Json file')
.setAction(sbUploader);
.setAction(batchUploader);

task('sp:update-ip-assets')
.addPositionalParam('franchiseId', 'Id of the Franchise to create the IP Assets in, as given by FranchiseRegistry contract')
.addPositionalParam('tx', 'tx hash that created blocks')
.addPositionalParam('filePath', 'path to the Json data')
.setDescription('Update ids for blocks in the Json file')
.setAction(sbUploader.updateIds);
.setAction(batchUploader.updateIds);

task('sp:eip7201-key')
.addPositionalParam('namespace', 'Namespace, for example erc7201:example.main')
Expand Down
109 changes: 63 additions & 46 deletions script/data/data_example.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,65 @@
{
"blocks": {
"stories": [
{
"id": null,
"blockType": "STORY",
"name": "The Full Grain World Bible",
"description": "Lorem Ipsum",
"author": "Sebastian Sinclair",
"content": "Lorem ipsum dolor sit amet consectetur adipiscing elit ullamcorper venenatis, habitasse egestas luctus penatibus eleifend at litora iaculis risus, cum quis habitant facilisi vel eu sapien taciti. Imperdiet id tincidunt erat primis sociosqu odio, nullam fusce bibendum arcu class lacus, purus cum condimentum sem varius. Magna risus scelerisque ullamcorper himenaeos et maecenas nibh erat donec, tellus vivamus elementum leo nascetur dui in litora. Malesuada nascetur eu elementum urna placerat ridiculus, nisi phasellus faucibus penatibus vivamus, fermentum ut interdum volutpat mauris.\n\n Mi himenaeos massa netus lacinia ac platea penatibus quisque felis sapien, ante ad libero faucibus sed sagittis egestas odio inceptos ridiculus, primis metus nunc sociis eros eleifend ultricies tincidunt taciti. Eu litora cursus penatibus massa cubilia fames pellentesque, curabitur nascetur consequat placerat nulla viverra egestas, ridiculus tellus class in lacinia maecenas.\n \n Eros dignissim sollicitudin torquent posuere litora neque et dui rutrum metus eleifend, sociis facilisi in eget varius netus praesent potenti urna curae. Elementum tempus feugiat suscipit blandit hendrerit placerat cum aliquet curabitur ultrices tempor, tincidunt neque lobortis condimentum cras ad nisi consequat sagittis primis. Curae nullam magna semper himenaeos penatibus potenti vestibulum nostra, magnis venenatis scelerisque mi rhoncus condimentum urna, diam a curabitur aliquam fames sociosqu tincidunt.\n\nViverra lobortis rutrum eget erat ullamcorper vestibulum praesent vivamus torquent, laoreet curabitur aptent dui vel ad ac eu egestas pharetra, turpis bibendum libero faucibus lacinia sociosqu ultricies consequat. Per nec eget hendrerit gravida urna in semper, sociis accumsan facilisi laoreet scelerisque torquent, ad est pharetra faucibus luctus nisl. Urna sociis ut lacus pharetra dis ullamcorper ad arcu, erat aenean congue integer fames blandit purus. Suspendisse condimentum facilisi aliquam at varius velit quis, dictum ullamcorper dapibus cum posuere nec pellentesque, porta laoreet tempus cursus porttitor sollicitudin.\n\nAuctor senectus praesent nostra porttitor platea dapibus phasellus vitae enim tristique venenatis laoreet, vehicula eleifend fusce metus lectus massa facilisis fames class neque eros. Libero magna eros posuere velit faucibus laoreet suscipit nascetur, etiam montes consequat phasellus aptent porttitor ante platea, leo lacinia molestie justo congue malesuada netus. Blandit primis facilisi vivamus scelerisque iaculis sociosqu per quisque odio lacus auctor tempor, sodales mauris donec non magnis nisi sollicitudin nulla semper senectus.\n \n Vel cursus fringilla venenatis ligula ridiculus dictum est libero gravida pharetra, nulla interdum netus laoreet mus dictumst magna class dapibus. Vulputate mauris congue leo nec nisi cum fermentum platea, purus non dis varius erat curabitur dapibus ligula, curae eros tellus venenatis vestibulum fusce himenaeos. Consequat dictumst convallis natoque donec curabitur lacus malesuada, leo a suspendisse mi nostra phasellus quam iaculis, mattis eleifend vulputate ut mollis vehicula."
}
],
"groups": [
{
"id": null,
"blockType": "GROUP",
"name": "The Fresh",
"description": "Human Like",
"groupingBlockType": "GROUP",
"ids": []
}
],
"characters": [
{
"id": null,
"blockType": "CHARACTER",
"name": "Captain Crunch",
"description": "Lorem Ipsum"
}
],
"locations": [
{
"id": null,
"blockType": "LOCATION",
"name": "Weird Homeworld",
"description": "Lorem Lorem."
}
],
"items": [
{
"id": null,
"blockType": "ITEM",
"name": "The asdad",
"description": "asdd"
}
]
"ip-assets": {
"stories": [
{
"id": null,
"ipAssetType": "STORY",
"name": "The Full Grain World Bible",
"description": "Lorem Ipsum",
"mediaURL": "https://www.youtube.com/watch?v=9bZkp7q19f0"
}
],
"groups": [
{
"id": null,
"ipAssetType": "GROUP",
"name": "The Fresh",
"description": "Human Like",
"mediaURL": "https://www.youtube.com/watch?v=9bZkp7q19f0"
}
],
"characters": [
{
"id": null,
"ipAssetType": "CHARACTER",
"name": "Captain Crunch",
"description": "Lorem Ipsum",
"mediaURL": "https://www.youtube.com/watch?v=9bZkp7q19f0"
}
],
"locations": [
{
"id": null,
"ipAssetType": "LOCATION",
"name": "Weird Homeworld",
"description": "Lorem Lorem.",
"mediaURL": "https://www.youtube.com/watch?v=9bZkp7q19f0"
}
],
"items": [
{
"id": null,
"ipAssetType": "ITEM",
"name": "The asdad",
"description": "asdd",
"mediaURL": "https://www.youtube.com/watch?v=9bZkp7q19f0"
}
]
},
"relationships": [
{
"sourceContract": "same",
"sourceAssetType": "stories",
"sourceAssetIndex": 0,
"destContract": "same",
"destAssetType": "characters",
"destAssetIndex": 0,
"data": "0x",
"name": "TEST_RELATIONSHIP",
"ttl": 1,
"sourceId": null,
"destId": null,
"relationshipId": null
}
}
]
}
Loading

0 comments on commit f356d18

Please sign in to comment.