chainline-contracts / chainline.contracts / HubContract

HubContract

object HubContract : SmartContract (source)

Properties

CARRY_SPACE_SIZE

const val CARRY_SPACE_SIZE: Int

DEMAND_INFO_SIZE

const val DEMAND_INFO_SIZE: Int

DEMAND_SIZE

const val DEMAND_SIZE: Int

FEE_DEMAND_REWARD

const val FEE_DEMAND_REWARD: Long

FEE_TRAVEL_DEPOSIT

const val FEE_TRAVEL_DEPOSIT: Long

LOG_LEVEL

const val LOG_LEVEL: Int

MAX_GAS_ITEM_VALUE

const val MAX_GAS_ITEM_VALUE: Long

MIN_GAS_ITEM_VALUE

const val MIN_GAS_ITEM_VALUE: Long

REP_REQUIRED_SIZE

const val REP_REQUIRED_SIZE: Int

RESERVATION_SIZE

const val RESERVATION_SIZE: Int

SCRIPT_HASH_SIZE

const val SCRIPT_HASH_SIZE: Int

STATS_ENABLED

const val STATS_ENABLED: Boolean

STORAGE_KEY_INITIALIZED

const val STORAGE_KEY_INITIALIZED: String

STORAGE_KEY_INIT_WALLET_P1

const val STORAGE_KEY_INIT_WALLET_P1: String

STORAGE_KEY_INIT_WALLET_P2

const val STORAGE_KEY_INIT_WALLET_P2: String

STORAGE_KEY_INIT_WALLET_P3

const val STORAGE_KEY_INIT_WALLET_P3: String

STORAGE_KEY_STATS_DEMANDS

const val STORAGE_KEY_STATS_DEMANDS: String

STORAGE_KEY_STATS_FUNDS

const val STORAGE_KEY_STATS_FUNDS: String

STORAGE_KEY_STATS_ROUTES

const val STORAGE_KEY_STATS_ROUTES: String

STORAGE_KEY_SUFFIX_DEMAND

const val STORAGE_KEY_SUFFIX_DEMAND: Byte

STORAGE_KEY_SUFFIX_REP

const val STORAGE_KEY_SUFFIX_REP: Byte

STORAGE_KEY_SUFFIX_RESERVATIONS

const val STORAGE_KEY_SUFFIX_RESERVATIONS: Byte

STORAGE_KEY_SUFFIX_TRAVEL

const val STORAGE_KEY_SUFFIX_TRAVEL: Byte

TESTS_ENABLED

const val TESTS_ENABLED: Boolean

TIMESTAMP_SIZE

const val TIMESTAMP_SIZE: Int

TRAVEL_EXTRA_EXPIRY_ON_MATCH

const val TRAVEL_EXTRA_EXPIRY_ON_MATCH: Long

TRAVEL_SIZE

const val TRAVEL_SIZE: Int

TX_HASH_SIZE

const val TX_HASH_SIZE: Int

VALUE_SIZE

const val VALUE_SIZE: Int

Functions

Main

fun Main(operation: String, vararg args: ByteArray): Any

The entry point of the smart contract.

concat

fun ByteArray.concat(b2: ByteArray): ByteArray

Concatenates two ByteArray together.

demand_create

fun demand_create(owner: ScriptHash, expiry: BigInteger, repRequired: BigInteger, itemSize: BigInteger, itemValue: BigInteger, infoBlob: ByteArray, nowTime: Int): Demand

Creates a new Demand object.

demand_getExpiry

fun Demand.demand_getExpiry(): BigInteger

Gets the expiry timestamp of a Demand.

demand_getInfoBlob

fun Demand.demand_getInfoBlob(): ByteArray

Gets the info string for a Demand.

demand_getItemSize

fun Demand.demand_getItemSize(): BigInteger

Gets the size of the desired item.

demand_getItemValue

fun Demand.demand_getItemValue(): BigInteger

Gets the desired item's value.

demand_getLookupKey

fun Demand.demand_getLookupKey(cityPairHash: Hash160, nowTime: Int): ByteArray

Gets the key used to store the demand for tracking lookup. Tracking requires knowledge of the "identifier" and city pair.

demand_getMatchKey

fun Demand.demand_getMatchKey(): ByteArray

Gets the storage key to store a Travel match for this Demand.

demand_getMatchedAtTime

fun Demand.demand_getMatchedAtTime(): BigInteger

Gets the time at which this Demand was matched with a Travel.

demand_getOwnerScriptHash

fun Demand.demand_getOwnerScriptHash(): ScriptHash

Gets the owner of the Demand.

demand_getRepRequired

fun Demand.demand_getRepRequired(): BigInteger

Gets the reputation score required of a Travel in order to match this Demand.

demand_getStorageKey

fun Hash160.demand_getStorageKey(): ByteArray

Gets the storage key for a Demand, which is essentially just the city pair hash with a suffix. This is called on the city pair hash.

demand_getTotalValue

fun Demand.demand_getTotalValue(): BigInteger

Gets the Demand's total value (item value + reward fee).

demand_isMatched

fun Demand.demand_isMatched(): Boolean

Determines whether the given Demand has been matched with a Travel object.

demand_reserveValueAndFee

fun Demand.demand_reserveValueAndFee(owner: ScriptHash): Unit

Reserves the item's value and reward fee for a new demand.

demand_reserveValueAndFee2

fun Demand.demand_reserveValueAndFee2(owner: ScriptHash, matchedTravel: Travel): Unit

Reserves the item's value and reward fee for a new demand. This form of the method is used when a Travel was found to be matched with the Demand.

demand_storeAndMatch

fun Demand.demand_storeAndMatch(owner: ScriptHash, cityPairHash: Hash160, nowTime: Int): Boolean

Performs all the legwork necessary to store and match a Demand with a Travel.

demands_findMatchableDemand

fun DemandList.demands_findMatchableDemand(repRequired: BigInteger, carrySpaceAvailable: BigInteger, expiresAfter: BigInteger, nowTime: Int): Demand

Finds a Demand in a DemandList that fits the given attributes.

demands_getAt

fun DemandList.demands_getAt(index: Int): Travel

Gets the Demand at the given index in a DemandList.

getBalance

external fun getBalance(account: Account, asset_id: ByteArray): Long

Calls "Neo.Account.GetBalance".

getGasAssetId

fun getGasAssetId(): ByteArray

Returns the GAS asset ID as a byte array.

getWalletScriptP1

fun getWalletScriptP1(): ByteArray

Gets part 1 of the wallet script code (code before the public key), set at init time.

getWalletScriptP2

fun getWalletScriptP2(): ByteArray

Gets part 2 of the wallet script code (code after the public key, before the script hash), set at init time.

getWalletScriptP3

fun getWalletScriptP3(): ByteArray

Gets part 3 of the wallet script code (code after the script hash), set at init time.

initialize

fun initialize(walletScriptP1: ByteArray, walletScriptP2: ByteArray, walletScriptP3: ByteArray): Boolean

Initializes the smart contract. This takes the three parts of the wallet script as arguments. These parts are stored and then used to verify the integrity of user wallets in the system.

isInitialized

fun isInitialized(): Boolean

Checks whether the contract has been initialized.

log_debug

fun log_debug(msg: String): Unit

Dispatches a Runtime.notify with the specified arg at the DEBUG level (3).

log_debug2

fun log_debug2(msg: String, arg: Any): Unit

Dispatches a Runtime.notify with the specified args at the DEBUG level (3).

log_err

fun log_err(msg: String): Unit

Dispatches a Runtime.notify with the specified arg at the ERROR level (1).

log_info

fun log_info(msg: String): Unit

Dispatches a Runtime.notify with the specified arg at INFO level (2).

log_info2

fun log_info2(msg: String, arg: Any): Unit

Dispatches a Runtime.notify with the specified args at INFO level (2).

log_info3

fun log_info3(msg: String, arg0: Any, arg1: Any): Unit

Dispatches a Runtime.notify with the specified args at INFO level (2).

pad

fun ByteArray.pad(count: Int): ByteArray

Pads a BigInteger that has been converted to a ByteArray to a specified byte length.

range

fun ByteArray.range(index: Int, count: Int): ByteArray

Extracts a range of bytes from a ByteArray.

res_findByValue

fun ReservationList.res_findByValue(value: BigInteger): Int

Finds the reserved funds object with the given value in a ReservationList.

res_findByValueAndRecipient

fun ReservationList.res_findByValueAndRecipient(value: BigInteger, recipient: ScriptHash): Int

Finds the reserved funds object with the given value and recipient in a ReservationList.

res_getAt

fun ReservationList.res_getAt(index: Int): Reservation

Gets the reserved funds object at the given index in a ReservationList.

res_getExpiry

fun Reservation.res_getExpiry(): BigInteger

Gets the expiry timestamp for an individual Reservation.

res_getRecipient

fun Reservation.res_getRecipient(): ScriptHash

Gets the intended recipient of reserved funds.

res_getTotalOnHoldGasValue

fun ReservationList.res_getTotalOnHoldGasValue(excludeRecipient: ScriptHash, nowTime: Int): Long

Calculates the total value of GAS that a list of reserved funds is holding, considering expiry times and whether funds were already paid out to the intended recipient.

res_getValue

fun Reservation.res_getValue(): BigInteger

Gets the GAS value of an individual Reservation.

res_replaceRecipientAt

fun ReservationList.res_replaceRecipientAt(idx: Int, recipient: ScriptHash): ReservationList

Finds the reserved funds object at the given idx and replaces its recipient with the one given.

res_wasPaidToRecipient

fun Reservation.res_wasPaidToRecipient(): Boolean

Determines whether the reserved funds were paid out to the recipient.

reservation_create

fun reservation_create(expiry: BigInteger, value: BigInteger, recipient: ScriptHash): Reservation

Creates a reserved funds object.

stats_getDemandsCount

fun stats_getDemandsCount(): BigInteger

Returns the number of demands created over time.

stats_getReservedFundsCount

fun stats_getReservedFundsCount(): BigInteger

Returns the amount of funds reserved over time as a fixed8 int.

stats_getRouteUsageCount

fun stats_getRouteUsageCount(): BigInteger

Returns the number of unique routes used over time.

stats_recordDemandCreation

fun stats_recordDemandCreation(): Unit

Increments the counter that keeps the number of Demands created over time.

stats_recordReservedFunds

fun stats_recordReservedFunds(value: BigInteger): Unit

Increments the counter that keeps a count of all funds reserved over time.

stats_recordRouteUsage

fun stats_recordRouteUsage(cityPairHash: Hash160): Boolean

Increments the counter that keeps the number of unique routes used over time.

take

fun ByteArray.take(count: Int): ByteArray

Takes a number of bytes from the start of a ByteArray.

toByteArray

fun BigInteger.toByteArray(padToSize: Int = 0): ByteArray

Converts a BigInteger to a padded ByteArray.

travel_create

fun travel_create(owner: ScriptHash, expiry: BigInteger, repRequired: BigInteger, carrySpace: BigInteger, nowTime: Int): Travel

Creates a new Travel object.

travel_getCarrySpace

fun Travel.travel_getCarrySpace(): BigInteger

Gets the item carry space available.

travel_getExpiry

fun Travel.travel_getExpiry(): BigInteger

Gets the expiry timestamp of a Travel.

travel_getLookupKey

fun Travel.travel_getLookupKey(cityPairHash: Hash160, nowTime: Int): ByteArray

Gets the key used to store the demand for tracking lookup. Tracking requires knowledge of the "identifier" and city pair.

travel_getMatchKey

fun Travel.travel_getMatchKey(): ByteArray

Gets the storage key to store a Demand match for this Travel.

travel_getMatchedAtTime

fun Travel.travel_getMatchedAtTime(): BigInteger

Gets the time at which this Travel was matched with a Demand.

travel_getOwnerScriptHash

fun Travel.travel_getOwnerScriptHash(): ScriptHash

Gets the owner of the Travel.

travel_getRepRequired

fun Travel.travel_getRepRequired(): BigInteger

Gets the reputation score required of a Demand in order to match this Travel.

travel_getStorageKey

fun Hash160.travel_getStorageKey(): ByteArray

Gets the storage key for a Travel, which is essentially just the city pair hash with a suffix. This is called on the city pair hash.

travel_isMatched

fun Travel.travel_isMatched(): Boolean

Determines whether the given Travel has been matched with a Demand object.

travel_overwriteExpiry

fun Travel.travel_overwriteExpiry(owner: ScriptHash, expiry: BigInteger): Unit

Re-reserves the deposit due by a traveller when they create a Travel with a revised expiry time. This method also updates a wallet's "state lock" with the new expiry time.

travel_reserveDeposit

fun Travel.travel_reserveDeposit(owner: ScriptHash): Unit

Reserves the deposit due by a traveller when they create a Travel.

travel_storeAndMatch

fun Travel.travel_storeAndMatch(owner: ScriptHash, cityPairHash: Hash160, nowTime: Int): Boolean

Performs all the legwork necessary to store and match a Travel with a Demand.

travels_findMatchableTravel

fun TravelList.travels_findMatchableTravel(repRequired: BigInteger, carrySpaceRequired: BigInteger, expiryLimit: BigInteger, nowTime: Int): Travel

Finds a Travel in a TravelList that fits the given attributes.

travels_getAt

fun TravelList.travels_getAt(index: Int): Travel

Gets the Travel at the given index in a TravelList.

tx_getOutgoingGasValue

fun tx_getOutgoingGasValue(originator: ScriptHash): Long

Finds the outgoing GAS value of the current transaction. This is useful for calculating whether the wallet can cover system fees when funds are going to be reserved in the invocation.

vm_booland

external fun vm_booland(arg0: Any, arg1: Any): Boolean

Inserts the "BOOLAND" OpCode. Returns true if the given args are both true.

vm_throw

external fun vm_throw(): Unit

Inserts the "THROW" OpCode. Aborts execution.

vm_throwIfNot

external fun vm_throwIfNot(arg: Any): Unit

Inserts the "THROWIFNOT" OpCode. Aborts execution if the supplied arg is not true.

wallet_canOpenDemandOrTravel

fun ScriptHash.wallet_canOpenDemandOrTravel(nowTime: Int): Boolean

Indicates whether a wallet is in a state that allows it to open a demand or travel. At the moment this contract supports one active transaction per user wallet at any one time.

wallet_checkWitness

fun ScriptHash.wallet_checkWitness(): Boolean

Calls Runtime.checkWitness on the provided script hash. Avoids making the call if the current ScriptContainer is null, which is the case when rpc "invokescript" is used.

wallet_clearFundReservations

fun ScriptHash.wallet_clearFundReservations(): Unit

Deletes a wallet's reserved funds from storage.

wallet_clearState

fun ScriptHash.wallet_clearState(): Unit

Clears all wallet system state, allowing for new Chain Line transactions.

wallet_getFundReservations

fun ScriptHash.wallet_getFundReservations(): ReservationList

Gets the list of reserved funds for the given wallet.

wallet_getFundReservationsStorageKey

fun ScriptHash.wallet_getFundReservationsStorageKey(): ByteArray

Gets the storage key used to store/lookup reserved funds for a wallet.

wallet_getGasBalance

fun ScriptHash.wallet_getGasBalance(): Long

Gets the GAS balance of a user wallet.

wallet_getReputationScore

fun ScriptHash.wallet_getReputationScore(): BigInteger

Gets the reputation score for a user wallet.

wallet_getReputationStorageKey

fun ScriptHash.wallet_getReputationStorageKey(): ByteArray

Gets the storage key used to store/lookup user reputation for a wallet.

wallet_hasFunds

fun ScriptHash.wallet_hasFunds(requiredBalance: Long, excludeRecipient: ScriptHash, nowTime: Int, countOutputs: Boolean): Boolean

Check if the wallet has enough funds to perform a transaction after reserved funds and tx outputs are considered. Note: Please ensure that the script has been through wallet_validate before this is called.

wallet_incrementReputationScore

fun ScriptHash.wallet_incrementReputationScore(): Unit

Increments the reputation score for the user wallet by 1.

wallet_requestTxOut

fun ScriptHash.wallet_requestTxOut(nowTime: Int): Boolean

Requests permission to perform a withdrawal from a user wallet using the value in tx outputs. Note: Please ensure that the script has been through wallet_validate before this is called.

wallet_reserveFunds

fun ScriptHash.wallet_reserveFunds(expiry: BigInteger, value: BigInteger, recipient: ScriptHash): Unit

Reserves funds in a previously validated user wallet. Overwrites any existing fund reservations.

wallet_setFundsPaidToRecipientTxHash

fun ScriptHash.wallet_setFundsPaidToRecipientTxHash(recipient: ScriptHash, value: BigInteger, txHash: Hash256): Boolean

Sets the transaction hash of funds that have been transferred to the recipient of reserved funds.

wallet_storeFundReservations

fun ScriptHash.wallet_storeFundReservations(resList: ReservationList): Unit

Stores reserved funds for the given wallet.

wallet_storeReputationScore

fun ScriptHash.wallet_storeReputationScore(rep: BigInteger): Unit

Stores a reputation score for a user wallet.

wallet_validate

fun ScriptHash.wallet_validate(pubKey: PublicKey): Boolean

Calls wallet_checkWitness on and validates the integrity of the provided script hash.