Skip to content

Drive Closure

Tan Xiu Haw edited this page Nov 10, 2023 · 3 revisions

Drive Closure

  • Following parameters required:
    • Drive Key
    • Maximum Fee
    • Deadline
    • Network ID
#include <xpxchaincpp/sdk.h>
#include <iostream>
#include <vector>

using namespace xpx_chain_sdk;

int main() 
{
  xpx_chain_sdk::Config config = xpx_chain_sdk::GetConfig();
  config.nodeAddress = "127.0.0.1";
  config.port = "3000";

  uint64_t driveSize = 1024;
  uint64_t replicatorsCount = 5;
  xpx_chain_sdk::Amount verificationFeeAmount = 100;
  xpx_chain_sdk::NetworkIdentifier networkIdentifier = xpx_chain_sdk::NetworkIdentifier::Mijin_Test;
  auto client = xpx_chain_sdk::getClient(config);

  xpx_chain_sdk::Key driveKey;
  // GET/bcdrives
  xpx_chain_sdk::ParseHexStringIntoContainer("39C762672C55EF0DAE7365553CF235E6AB7BB41058E1DC2469E28FDCA97AA990", 64, driveKey);
  
  auto driveClosureTransaction = xpx_chain_sdk::CreateDriveClosureTransaction
  (
    driveKey,
    std::nullopt,
    std::nullopt,
    networkIdentifier
  );

  std::string privateKey = "819F72066B17FFD71B8B4142C5AEAE4B997B0882ABDF2C263B02869382BD93A0";
  auto account = std::make_shared<xpx_chain_sdk::Account>([privateKey](xpx_chain_sdk::PrivateKeySupplierReason reason, xpx_chain_sdk::PrivateKeySupplierParam param)
  {
    xpx_chain_sdk::Key key;
    ParseHexStringIntoContainer(privateKey.c_str(), privateKey.size(), key);
    return xpx_chain_sdk::PrivateKey(key.data(), key.size());
  }, networkIdentifier);

  account->signTransaction(driveClosureTransaction.get());
  xpx_chain_sdk::Hash256 hash = driveClosureTransaction->hash();
  auto bin = driveClosureTransaction->binary();
  client->transactions()->announceNewTransaction(bin);
 
  for (int i = 0; i < sizeof(hash); i++)
  {
    std::cout << ToHex(hash[i]);
  }
  std::cout << std::endl;
  return 0;
}
Clone this wiki locally