solidity API - Second-Earth/setchain GitHub Wiki

-[Add asset-related interface] (#Add asset-related interface) -issueasset -addasset -transfer -setassetowner -destoryasset -balanceex -getassetid -assetinfo -[New snapshot related interface] (#New snapshot related interface) -snapshottime -snapbalance -[Add new decryption interface] (#Add new decryption interface) -cryptocalc -[Add account related interface] (#Add account related interface) -getaccountid -getaccounttime -[Add related interface of handling fee] (#Add related interface of handling fee) -withdrawfee -deductgas -[Add DPOS related interface] (#Add DPOS related interface) -getepoch -getcandidatenum -getcandidate -getvoterstake -[Add new attribute](#Add new attribute) -assetid -recipient -[Unavailable Features](#Unavailable Features) -[Creating an account or contract in a contract is no longer supported] (#Creating an account or contract in a contract is no longer supported) -[Units such as ether and wei are no longer supported] (#Units such as etherwei are no longer supported)

Added asset-related interfaces

issueasset

Function description: issue assets

Parameter Description:

-string desc, asset information (concatenated by the following strings, separated by commas) -name asset name -symbol asset symbol name -total total issuance -decimal asset precision -owner asset owner -limit asset issuance limit -founder asset founder -contract agreement contract name (may be empty) -detail protocol description information (can be empty, the length does not exceed 255)

return value:

-uint256 assetId, asset ID (error return 0)

Function prototype: uint256 assetId = issueasset(string desc)

Example:

pragma solidity ^0.4.24;

contract Test {
    //string desc ="ethereum,eth,10000000000,10,owner,100,founder,contract,detail";
    function reg(string desc) public payable returns(uint256){
        return issueasset(desc);
    }
}

addasset

Function description: additional issuance of assets

Parameter Description:

-uint256 assetId, asset ID -address to, account ID (additional assets will be issued to this account) -uint256 value, additional issuance quantity

Return value: empty

Function prototype: addasset(uint256 assetId, address to, uint256 value)

Example:

pragma solidity ^0.4.24;

contract Test {
    function add(uint256 assetId, address to, uint256 value) public {
        addasset(assetId, to, value);
    }
}

transfer

Function description: transfer (this method will replace the original transfer method, and when this method is executed in the contract, the receiver's callback function will not be called, but a pure transfer operation)

Parameter Description:

-address to, account ID (transfer recipient) -uint256 assetId, asset ID -uint256 value, transfer amount

Return value: empty

Function prototype: to.transfer(uint256 assetId, uint256 value)

Example:

pragma solidity ^0.4.24;

contract Test {
    function transfer(uint256 assetId, address to, uint256 value) public {
        to.transfer(assetId, value);
    }
}

setassetowner

Function description: modify asset owner

Parameter Description:

-uint256 assetId, asset ID -address newowner, account ID (new asset owner)

Return value: empty

Function prototype: setassetowner(uint256 assetId, address newowner)

Example:

pragma solidity ^0.4.24;

contract Test {
    function setowner(uint256 assetId, address newowner) public {
        setassetowner(assetId, newowner);
    }
}

destoryasset

Function description: destroy assets

Parameter Description:

-uint256 assetId, asset ID -uint256 value, the amount of assets to be destroyed

return value:

-uint256 assetId, asset ID (error returns 0)

Function prototype: uint256 assetId = destroyasset(uint256 assetId, uint256 value)

Example:

pragma solidity ^0.4.24;

contract Test {
   function destroyAsset(uint256 assetId, uint256 value) public returns(uint256){
        return destroyasset(assetId, value);
    }
}

balanceex

Function description: query balance

Parameter Description:

-address to, account ID -uint256 assetId, asset ID

return value:

-uint256 balance, balance

Function prototype: uint256 balance = to.balanceex(uint256 assetId)

Example:

pragma solidity ^0.4.24;

contract Test {
    function getBalance(uint256 assetId, address to) public returns(uint256) {
        return to.balanceex(assetId);
    }
}

getassetid

Function description: query asset ID

Parameter Description:

-string name, asset name

return value:

-int64 assetID, asset ID

Function prototype: int64 assetID = getassetid(string name)

Example:

pragma solidity ^0.4.24;

contract Test {
    function getAssetID(string name) public returns(int64) {
        return getassetid(name);
    }
}

assetinfo

Function description: Get the total amount of assets and asset name at the moment of the snapshot

Parameter Description:

-uint256 assetId, asset ID -uint256 time, snapshot time -(bytes memory) assetName, asset name (passed as input parameter)

return value:

-uint256 amount, total assets

Function prototype: uint256 amount = assetinfo(uint256 assetId, uint256 time, bytes assetName)

Example:

pragma solidity ^0.4.24;

contract Test {
    function getAssetInfo(uint256 assetId, uint256 t) public returns (bytes,uint256){
        bytes memory assetName = new bytes(20);
        uint256 assetAmount = assetinfo(assetId, t, assetName);
        return (assetName, assetAmount);
    }
}

Add snapshot related interface

snapshottime

Function description: Get snapshot time

Parameter Description:

-uint256 typeId, when typeId is 0, get the latest snapshot time; when it is 1, get the previous snapshot time of time, when it is 2, get the next snapshot time of time -uint256 time, time

return value:

-uint256 snapshotTime, snapshot time

Function prototype: uint256 snapshotTime = snapshottime(uint256 typeId, uint256 time)

Example:

pragma solidity ^0.4.24;

contract Test {
    function getSnapshotTime(uint256 typeId, uint256 time) public returns (uint256){
        return snapshottime(typeId, time);
    }
}

snapbalance

Function description: Get snapshot time balance

Parameter Description:

-address to, account ID -uint256 assetId, asset ID -uint256 time, snapshot time -uint256 opt, when it is 0, get the balance of the main asset, when it is 1, get the balance of the main asset plus the balance of the pledge deposit, when it is 2, get the balance of the main asset plus sub-assets, which is 3 At the time, get the pledge deposit, balance of the main asset and the balance of the sub-assets

return value:

-uint256 balance, balance

Function prototype: uint256 balance = to.snapbalance(uint256 assetId, uint256 time, uint256 opt)

Example:

pragma solidity ^0.4.24;

contract Test {
    function getSnapBalance(address to, uint256 assetId, uint256 t, uint256 opt) public returns (uint256){
        return to.snapbalance(assetId, t, opt);
    }
}

Newly added decryption interface

cryptocalc

Function description: Encryption and decryption calculation

Parameter Description:

-(bytes memory) sourcecode, input bytes -(bytes memory) key, public key/private key -(bytes memory) destcode, output bytes -uint256 type, operation type: encryption 0, decryption 1

return value:

-uint256 len, output byte length

Function prototype: uint256 len = cryptocalc( bytes sourcecode, bytes key, bytes destcode, uint256 type);

Example:

pragma solidity ^0.4.24;

contract Test {
   function getcrypto(bytes sourcecode, bytes key) public returns(bytes) {
        bytes memory destcode = new bytes(20);
        uint256 len = cryptocalc(sourcecode, key, destcode, 0);
        return destcode;
    }
}

New account related interface

getaccountid

Function description: Get account ID

Parameter Description:

-string name, account name

return value:

-uint256 accountID, account ID (error returns 0)

Function prototype: uint256 accountID = getaccountid(string name)

Example:

pragma solidity ^0.4.24;

contract Test {
   function getAccountID(string name) public returns(uint256) {
        return getaccountid(name);
    }
}

getaccounttime

Function description: Get account creation time

Parameter Description:

-uint256 account, account ID

return value:

-uint256 time, time (error returns 0)

Function prototype: uint256 time = getaccounttime(address account)

Example:

pragma solidity ^0.4.24;

contract Test {
   function gettime(uint256 account) public returns(uint256) {
        return getaccounttime(account);
    }
}

New interface related to handling fees

withdrawfee

Function description: recovery fee

Parameter Description:

-uint256 id, can be asset ID, contract account name ID, miner account name ID -`uint256 typeId, used to indicate the type of the last parameter. When it is 0, id represents the asset ID. When it is 1, id represents the contract account ID. When it is 2, id represents the miner account ID.

Return value: None

Function prototype: withdrawfee(uint256 id,uint256 typeId)

Example:

pragma solidity ^0.4.24;

contract Test {
    function withdrawFee(uint256 id, uint256 typeId) public payable {
        withdrawfee(id, typeId);
    }
}

deductgas

Function description: deduct gas

Parameter Description:

-uint256 amount, the amount of gas to be deducted

return value:

-uint256 remain, remaining gas amount

Function prototype: uint256 remain = deductgas (uint256 amount);

Example:

pragma solidity ^0.4.24;

contract Test {
    function deductMoreGas(uint256 amount) public returns(uint256){
        return deductgas(amount);
    }
}

Added DPOS related interfaces

getepoch

Function description: Get production cycle

Parameter Description:

-uint256 arg, 0 means to get the latest period; non-zero, to get the previous period of the specified period

return value:

-uint256 epoch, period

Function prototype: uint256 epoch = getepoch( uint256 arg);

Example:

pragma solidity ^0.4.24;

contract Test {
    function getlatestEpochAndCertainEpoch(uint256 arg, uint256 epochID) public returns(uint256,uint256){
        uint256 latestEpoch = getepoch(0,epochID);
        uint256 certainEpoch = getepoch(arg,epochID);
        return (latestEpoch, certainEpoch);
    }
}

getcandidatenum

Function description: Get the number of producers in a specified period

Parameter Description:

-uint256 epoch, specified period

return value:

-uint256 num, the number of producers

Function prototype: uint256 num = getcandidatenum( uint256 epoch );

Example:

pragma solidity ^0.4.24;

contract Test {
    function getNum(uint256 epoch) public returns(uint256){
        uint256 num = getcandidatenum(epoch);
        return num;
    }
}

getcandidate

Function description: Get information about the producer of the specified period

Parameter Description:

-uint256 epoch, specified period -uint256 index, producer serial number -(bytes memory) name, producer name

return value:

-uint256 stake, mortgage equity -uint256 cunt, the number of blocks that should be produced -uint256 actcunt, the actual number of blocks produced -uint256 replace, alternate replacement index -uint256 len, the length of the producer name string

Function prototype: (uint256 stake, uint256 cunt, uint256 actcunt, uint256 replace, uint256 len) = getcandidate( uint256 epoch, uint256 index, bytes name);

Example:

pragma solidity ^0.4.24;

contract Test {
    function candidate(uint256 epoch, uint256 index) public returns(uint256,uint256,uint256,uint256){
        bytes memory asname = new bytes(20);
        (uint256 stake,uint256 cunt,uint256 actcunt ,uint256 replace, uint256 len) = getcandidate(epoch,index,asname);
        return (stake, cunt, actcunt, replace);
    }
}

getvoterstake

Function description: Obtain the rights and interests of voters in a specified period

Parameter Description:

-uint256 epoch, specified period -uint256 voterID, specify the voter account ID -uint256 candidateID, specify the producer account ID

return value:

-uint256 stake, voting rights

Function prototype: uint256 stake = getvoterstake( uint256 epoch, uint256 voterID, uint256 candidateID);

Example:

pragma solidity ^0.4.24;

contract Test {
    function voterStake(uint256 epoch, uint256 voterID, uint256 candidateID) public returns(uint256){
        return getvoterstake(epoch, voterID, candidateID);
    }
}

New attributes

assetid

Property introduction: Add msg.assetid, you can get the asset ID of the current contract transaction in the contract

recipient

Property introduction: newly added tx.recipient, you can get the recipient of the current outermost transaction in the contract

Unavailable Features

No longer supports creating accounts or contracts in contracts

Since the account name needs to be specified to create an account, it is no longer supported to create an account through the new method

No longer supports ether, wei and other units

Delete ether, wei and other units, corresponding to set, aset, please note that when writing the contract, the difference between the two is 10 to the 18th power