DCore application case: purchasing content

Purchase Content

Purchasing content requires several steps. To buy and access content, you need the content ID and the appropriate decryption key (AES key)

Let's find what we want to download first.

List valid content

By using the following methods, you can get a list of all currently valid content. Lists are dynamic, and expired or hidden items are not in the list.

METHODS:
search_content - Gets an alphabetical list of content by searching for content items

vector<content_summary> search_content(string term,
                                       string order,
                                       string user,
                                       string region_code,
                                       string id,
                                       string type,
                                       uint32_t count);

Parameters:

  • term - Search for content items
  • order-ordered domain
  • user - Content Owner
  • region_code - Two-letter region code
  • ID - Open the content target ID of the search
  • type - Applications to be screened and content types
  • count - Maximum number of accessible content (no more than 100)

Return value:

  • Selected items (content)

Examples are given to illustrate:

search_content "flower" "" accountname "AE" "" "" 3

Respond:

search_content "flower" "" accountname "AE" "" "" 3
[{
    "id": "2.13.72",
    "author": "publisher-account",
    "price": {
      "amount": 100000000,
      "asset_id": "1.3.0"
    },
    "synopsis": "{\"content_type_id\":\"0\",\"title\":\"Apllejuiceflower\",\"description\":\"test descriptin for the test flower \"}",
    "status": "Uploaded",
    "URI": "ipfs:QmRHS5siC3bTY6hDAdD5ELagZfpLkbYbudaeoV211YJ2FU",
    "_hash": "822c778d5d33d24a0d661d3249d2b9a3efc8f66f",
    "AVG_rating": 0,
    "size": 5,
    "expiration": "2017-11-17T23:59:59",
    "created": "2017-11-14T09:22:15",
    "times_bought": 0
  }
]

API Developer Documents for Searching Content

Purchase Content

In the previous step, we obtained asset information for a content using a Unified Resource Identifier (URI). According to URI, the purchasing content function will help you get the exact information about the content you are purchasing.

There are two ways to buy content. If the content downloader chooses automatic download (Auto-download), it is impossible to modify the price of the assets payable set by the author. If you choose to purchase content without automatic download (Not automatically downloaded), other payment assets may be set up.

Content Auto Download

By automatically downloading content, you can save some time and call fewer command lines. However, you cannot pay for content through assets that are not set up by the uploader.

METHODS:

download_content - Download encrypted specified content by providing URI s

void download_content(string consumer,
                      string URI,
                      string region_code_from,
                      bool broadcast = false);

Parameters:

  • consumer - Content consumer
  • URI - URI of content
  • region_code_from-A two-letter region code
  • broadcast - true - To broadcast transactions over the network, display as true

Examples are given to illustrate:

download_content mickey "ipfs:QmRHS5siC3bTY6hDAdD5ELagZfpLkbYbudaeoV211YJ2FU" "AE" true

Result:

null

Please follow the instructions Purchase Part List Descriptive operation in.

API Developer Documents for Downloading Contents

Manual download of content

This step consists of two operations. The first step is to use the request_to_buy purchase purchase request command to access, and the second step is to download_package.

METHODS:
request_to_buy - This function is used to send requests for purchased content. The seeder will receive this demand.

signed_transaction request_to_buy(string consumer,
                                  string URI,
                                  string price_asset_name,
                                  string price_amount,
                                  string str_region_code_from,
                                  bool broadcast);

Parameters:

  • consumer - Content consumer
  • URI - Content URI
  • price_asset_name - Asset Ticker symbol for purchasing content
    - price_amount-content price
  • str_region_code_from-two-letter area code
  • Broadcast - To broadcast transactions over the network, display as true

Return value:
Signed transactions requesting purchase content

Examples are given to illustrate:

request_to_buy andrew "ipfs:QmRHS5siC3bTY6hDAdD5ELagZfpLkbYbudaeoV211YJ2FU" DCT 2 "AE" true

Respond:

{
  "ref_block_num": 54202,
  "ref_block_prefix": 2346282037,
  "expiration": "2017-11-15T11:20:20",
  "operations": [[
      21,{
      "fee": {
          "amount": 0,
          "asset_id": "1.3.0"
        },
         "URI": "ipfs:QmRHS5siC3bTY6hDAdD5ELagZfpLkbYbudaeoV211YJ2FU",
        "consumer": "1.2.75",
        "price": {
          "amount": 200000000,
          "asset_id": "1.3.0"
        },
        "region_code_from": 4,
        "pubKey": {
          "s": "4303628372841098204725325886169480368712308731846406620978518465243755034949712651980700780736242269928176997284623659672330921098152069204211868999952586."
        }
      }
    ]
  ],
  "extensions": [],
  "signatures": [
  "202a710e6222b4b28efeef1d287be8483c8fd49de6b3a436a3b7eafcbb28c88b0125a022facb6b6881520ea6745488f37666697c5b4e69a23a55af4ed943b3e9bf"
  ]
  }

Purchase Request API Developer Document

Step 2

METHODS:

  • download_package - Download the specified content package
void download_package(string url);

Parameters:

  • url - Content Pack Links

Examples are given to illustrate:

download_package "ipfs:QmYKkYWABMNiX8Mt1VHPSqm9pVz2gAN4KTfYz81idpfBzR"

Result:

download_package "ipfs:QmYKkYWABMNiX8Mt1VHPSqm9pVz2gAN4KTfYz81idpfBzR"
null

API Developer Documents for Downloading Content Packages

List Content Purchase Records

The correct operation requires knowing the buyer's account ID or name (the first parameter).

METHODS:
search_my_purchases - Obtain historical purchase target items by consumers matching search items

vector<buying_object_ex> search_my_purchases(account_id_or_name,
                                             term,
                                             order,
                                             id,
                                             uint32_t count);

Parameters:

  • account_id_or_name - Returned purchasing content consumer
  • term - Search items found in Title and Description
  • order - Sorting data by field
  • ID - Open the target ID of the search (Object_id)
  • count - Maximum number of accessible content (no more than 100)

Return value:

  • The historical purchase target item matching the provided consumer and the matching content item (term).

Examples are given to illustrate:

search_my_purchases mickey "" "" "" 2

Respond:

[{
    "id": "2.12.67",
    "consumer": "1.2.73",
    "URI": "ipfs:QmRHS5siC3bTY6hDAdD5ELagZfpLkbYbudaeoV211YJ2FU",
    "synopsis": "{\"content_type_id\":\"0\",\"title\":\"Apllejuiceflower\",\"description\":\"test descriptin for the test flower \"}",
    "price": {
      "amount": 100000000,
      "asset_id": "1.3.0"
    },
     "paid_price_before_exchange": {
      "amount": 100000000,
      "asset_id": "1.3.0"
    },
    "paid_price_after_exchange": {
      "amount": 100000000,
      "asset_id": "1.3.0"
    },
    "seeders_answered": [
      "1.2.18",
      "1.2.17"
    ],
    "size": 5,
    "rating": 0,
    "comment": "",
    "expiration_time": "2017-11-15T12:27:30",
    "pubKey": {
      "s": "10384416749140257128583102389624607251654392586672946391438154410634414297114005655788618266551181783174334468876296512914387596163700640306113614522603976."
    },
    "key_particles": [{
        "C1": {
          "s": "7713541882884265737001144964407618286238469746991155829237368493864906459364159840366328822361837163546845186666114160890902773989019773380701434654220048."
        },
        "D1": {
          "s": "2692769396320662590732095382046790594075004387215914992857698150956473426023071796292163107553139158816276027313452036566715084008768822495671492946343936."
        }
      },{
        "C1": {
          "s": "6773119226898217031462006811313926243329502497094879661060451283455969563980673100681433599331398298113160613787560192551976238315248808417231992172920752."
        },
        "D1": {
          "s": "4654198223728504093980753883811654976741761019946052282686348856710255155548774806614798135855247295621547714324832986380763167537020809512198958238385012."
        }
      }
    ],
    "expired": false,
    "delivered": true,
    "expiration_or_delivery_time": "2017-11-14T12:27:40",
    "rated_or_commented": false,
    "created": "2017-11-14T09:22:15",
    "region_code_from": 4,
    "total_key_parts": 2,
    "received_key_parts": 2,
    "total_download_bytes": 0,
    "received_download_bytes": 0,
    "status_text": "Unknown",
    "author_account": "accountname",
    "AVG_rating": 0,
    "times_bought": 1,
    "hash": "822c778d5d33d24a0d661d3249d2b9a3efc8f66f"
}]

Search API Developer Documents for Purchased Contents

Request for an encryption key

METHODS:

  • restore_encryption_key - Restore AES keys (used to encrypt and decrypt content) from the particle system stored in the purchase target item
DInteger restore_encryption_key(std::string account,
                                buying_id_type buying);

Parameters:

  • account - Consumer account ID or Name
  • Buy - contains key particles to purchase target items

Return value:

  • Restore AES keys from particles.

Examples are given to illustrate:

restore_encryption_key mickey "2.12.67"

Result:

restore_encryption_key mickey "2.12.67"
"90119978168686416626538113977783330590824857160509159322627126482134770984565."

Recovery of API Developer Documents for Encrypted Keys

Getting Encrypted Content

METHODS:

extract_package - Extract the selected content package

void extract_package(string& package_hash,
                     string& output_dir,
                     DInteger& aes_key);

Parameters:

  • package_hash - Hash to be extracted from content packages
  • output_dir - Create a directory for extracting files
  • aes_key - AES key for decryption

Examples are given to illustrate:

extract_package "822c778d5d33d24a0d661d3249d2b9a3efc8f66f" /path/to/download/the/ content/
"90119978168686416626538113977783330590824857160509159322627126482134770984565."

Result:

extract_package "822c778d5d33d24a0d661d3249d2b9a3efc8f66f" /path/to/download/the/ content/
"90119978168686416626538113977783330590824857160509159322627126482134770984565."
null

API Developer Documents for Extracting Content Packages

Tags: network

Posted on Mon, 26 Aug 2019 01:39:32 -0700 by skroks609