stdlib.txt
1 Builtin namespaces: 2 3 Address 4 5 Address.to_str(a: address): string - Base58 encoded string. 6 Address.to_bytes(a: address): bytes(32) - Binary representation of the address. 7 Address.is_contract(a: address): bool - Checks if the address is a contract. 8 Address.is_oracle(a: address): bool - Checks if the address is a registered oracle. 9 Address.is_payable(a: address): bool - Checks if the address can be spent to. 10 Address.to_contract(a: address): C - Casts address to contract type C. 11 12 AENS 13 14 Types: 15 name = Name(address, Chain.ttl, map(string, AENS.pointee)) 16 pointee = AccountPt(address) | OraclePt(address) | ContractPt(address) | ChannelPt(address) 17 18 AENSv2 19 20 Types: 21 name = Name(address, Chain.ttl, map(string, AENSv2.pointee)) 22 pointee = AccountPt(address) | OraclePt(address) | ContractPt(address) | ChannelPt(address) | DataPt(bytes()) 23 Functions: 24 AENSv2.resolve(name: string, key: string): option('a) - Name resolution. 25 AENSv2.lookup(name: string): option(AENSv2.name) - Returns a name object if the name is active. 26 AENSv2.preclaim(owner: address, commitment_hash: hash, <signature: signature>): unit - Preclaims a name. 27 AENSv2.claim(owner: address, name: string, salt: int, name_fee: int, <signature: signature>): unit - Claims a preclaimed name. 28 AENSv2.transfer(owner: address, new_owner: address, name: string, <signature: signature>): unit - Transfers a name to a new owner. 29 AENSv2.revoke(owner: address, name: string, <signature: signature>): unit - Revokes a name. 30 AENSv2.update(owner: address, name: string, expiry: option(Chain.ttl), client_ttl: option(int), new_ptrs: option(map(string, AENSv2.pointee)), <signature: signature>): unit - Updates a name's attributes. 31 32 Auth 33 34 Auth.tx: option(Chain.tx) - Gets the current transaction. 35 Auth.tx_hash: option(hash) - Gets the hash of the current transaction. 36 37 Bits 38 39 Bits.none: bits - A bit field with all bits cleared. 40 Bits.all: bits - A bit field with all bits set. 41 Bits.set(b: bits, i: int): bits - Sets bit i. 42 Bits.clear(b: bits, i: int): bits - Clears bit i. 43 Bits.test(b: bits, i: int): bool - Checks if bit i is set. 44 Bits.sum(b: bits): int - Counts the number of set bits. 45 Bits.union(a: bits, b: bits): bits - Bitwise disjunction. 46 Bits.intersection(a: bits, b: bits): bits - Bitwise conjunction. 47 Bits.difference(a: bits, b: bits): bits - Bitwise difference. 48 49 Bytes 50 51 Bytes.to_int(b: bytes(n)): int - Interprets the byte array as a big-endian integer. 52 Bytes.to_str(b: bytes(n)): string - Returns the hexadecimal representation of the byte array. 53 Bytes.concat(a: bytes(m), b: bytes(n)): bytes(m + n) - Concatenates two byte arrays. 54 Bytes.split(a: bytes(m + n)): bytes(m) * bytes(n) - Splits a byte array at a given index. 55 Bytes.split_any(a: bytes(), at: int): option(bytes() * bytes(n)) - Splits an arbitrary size byte array at index at. 56 Bytes.to_fixed_size(a: bytes()): option(bytes(n)) - Converts an arbitrary size byte array to a fixed size one. 57 Bytes.to_any_size(a: bytes(n)): bytes() - Converts a fixed size byte array to an arbitrary size one. 58 Bytes.size(a: bytes()): int - Computes the length of a byte array. 59 60 Call 61 62 Call.origin: address - Address of the account that signed the initial call transaction. 63 Call.caller: address - Address of the entity calling the contract. 64 Call.value: int - Amount of coins transferred to the contract in the call. 65 Call.gas_price: int - Gas price of the current call. 66 Call.fee: int - Fee of the current call. 67 Call.gas_left: int - Amount of gas left for the current call. 68 69 Chain 70 71 Types: 72 ttl = FixedTTL(int) | RelativeTTL(int) 73 tx = { paying_for : option(Chain.paying_for_tx), ga_metas : list(Chain.ga_meta_tx), actor : address, fee : int, ttl : int, tx : Chain.base_tx } 74 ga_meta_tx = GAMetaTx(address, int) 75 paying_for_tx = PayingForTx(address, int) 76 base_tx = SpendTx(...) | OracleRegisterTx | OracleQueryTx | OracleResponseTx | OracleExtendTx | NamePreclaimTx | NameClaimTx(hash) | NameUpdateTx(string) | NameRevokeTx(hash) | NameTransferTx(address, string) | ChannelCreateTx(address) | ChannelDepositTx(address, int) | ChannelWithdrawTx(address, int) | ChannelForceProgressTx(address) | ChannelCloseMutualTx(address) | ChannelCloseSoloTx(address) | ChannelSlashTx(address) | ChannelSettleTx(address) | ChannelSnapshotSoloTx(address) | ContractCreateTx(int) | ContractCallTx(address, int) | GAAttachTx 77 Functions: 78 Chain.balance(a: address): int - Gets the balance of account a. 79 Chain.block_hash(h: int): option(bytes(32)) - Gets the hash of the block at height h. 80 Chain.block_height: int - Gets the height of the current block. 81 Chain.bytecode_hash: 'c => option(hash) - Gets the hash of the contract's bytecode. 82 Chain.create(value: int, ...): 'c - Creates and deploys a new contract instance. 83 Chain.clone(ref: 'c, gas: int, value: int, protected: bool, ...): if(protected) option('c) else 'c - Clones an existing contract. 84 Chain.coinbase: address - Gets the address of the miner of the current block. 85 Chain.difficulty: int - Gets the difficulty of the current block. 86 Chain.event(e: event): unit - Emits an event. 87 Chain.gas_limit: int - Gets the gas limit of the current block. 88 Chain.network_id: string - Gets the network ID of the chain. 89 Chain.spend(to: address, amount: int): unit - Spends tokens to an address. 90 Chain.timestamp: int - Gets the timestamp of the current block. 91 92 Char 93 94 Char.to_int(c: char): int - Returns the UTF-8 codepoint of a character. 95 Char.from_int(i: int): option(char) - Returns the character corresponding to an integer codepoint. 96 97 Contract 98 99 Contract.creator: address - Address of the entity that created the contract. 100 Contract.address: address - Address of the current contract. 101 Contract.balance: int - Amount of coins in the contract account. 102 103 Crypto 104 105 Crypto.sha3(x: 'a): hash - Hashes any object to SHA3. 106 Crypto.sha256(x: 'a): hash - Hashes any object to SHA256. 107 Crypto.blake2b(x: 'a): hash - Hashes any object to blake2b. 108 Crypto.poseidon(x1: int, x2: int): int - Hashes two integers using the Poseidon hash function. 109 Crypto.verify_sig(msg: bytes(), pubkey: address, sig: signature): bool - Verifies a signature. 110 Crypto.ecverify_secp256k1(msg: hash, addr: bytes(20), sig: bytes(65)): bool - Verifies an Ethereum-style signature. 111 Crypto.ecrecover_secp256k1(msg: hash, sig: bytes(65)): option(bytes(20)) - Recovers an Ethereum-style address from a signature. 112 Crypto.verify_sig_secp256k1(msg: hash, pubkey: bytes(64), sig: bytes(64)): bool - Verifies a standard 64-byte ECDSA signature. 113 114 Int 115 116 Int.mulmod(a: int, b: int, q: int): int - Combined multiplication and modulus. 117 Int.to_str(n: int): string - Casts the integer to a string. 118 Int.to_bytes(n: int, size: int): bytes() - Casts the integer to a byte array. 119 120 Map 121 122 Map.lookup(k: 'k, m: map('k, 'v)): option('v) - Returns the value under a key. 123 Map.lookup_default(k: 'k, m: map('k, 'v), v: 'v): 'v - Returns the value under a key or a default value. 124 Map.member(k: 'k, m: map('k, 'v)): bool - Checks if a key is present in the map. 125 Map.delete(k: 'k, m: map('k, 'v)): map('k, 'v) - Removes a key from the map. 126 Map.size(m: map('k, 'v)): int - Returns the number of elements in the map. 127 Map.to_list(m: map('k, 'v)): list('k * 'v) - Returns a list of key-value pairs. 128 Map.from_list(m: list('k * 'v)): map('k, 'v) - Creates a map from a list of key-value pairs. 129 130 Oracle 131 132 Oracle.register(<signature: bytes(64)>, acct: address, qfee: int, ttl: Chain.ttl): oracle('a, 'b) - Registers a new oracle. 133 Oracle.get_question(o: oracle('a, 'b), q: oracle_query('a, 'b)): 'a - Gets the question of a query on an oracle. 134 Oracle.respond(<signature: bytes(64)>, o: oracle('a, 'b), q: oracle_query('a, 'b), 'b): unit - Responds to a question on an oracle. 135 Oracle.extend(<signature: bytes(64)>, o: oracle('a, 'b), ttl: Chain.ttl): unit - Extends the TTL of an oracle. 136 Oracle.query_fee(o: oracle('a, 'b)): int - Returns the query fee of an oracle. 137 Oracle.query(o: oracle('a, 'b), q: 'a, qfee: int, qttl: Chain.ttl, rttl: Chain.ttl): oracle_query('a, 'b) - Asks an oracle a question. 138 Oracle.get_answer(o: oracle('a, 'b), q: oracle_query('a, 'b)): option('b) - Gets the answer to a query on an oracle. 139 Oracle.expiry(o: oracle('a, 'b)): int - Gets the block height at which an oracle expires. 140 Oracle.check(o: oracle('a, 'b)): bool - Checks if an oracle exists and has the correct type. 141 Oracle.check_query(o: oracle('a, 'b), q: oracle_query('a, 'b)): bool - Checks if an oracle query exists and has the expected type. 142 143 Includable namespaces: 144 145 AENSCompat 146 147 AENSCompat.pointee_to_V2(p: AENS.pointee): AENSv2.pointee - Translates old pointee format to new. 148 AENSCompat.pointee_from_V2(p2: AENSv2.pointee): option(AENS.pointee) - Translates new pointee format to old. 149 150 BLS12_381 151 152 Types: fr, fp, fp2, g1, g2, gt 153 Functions: 154 BLS12_381.pairing_check(xs: list(g1), ys: list(g2)): bool - Performs a pairing check of a list of points. 155 BLS12_381.int_to_fr(x: int): fr - Converts an integer to an fr. 156 BLS12_381.int_to_fp(x: int): fp - Converts an integer to an fp. 157 BLS12_381.fr_to_int(x: fr): int - Converts an fr to an integer. 158 BLS12_381.fp_to_int(x: fp): int - Converts an fp to an integer. 159 BLS12_381.mk_g1(x: int, y: int, z: int): g1 - Constructs a g1 point. 160 BLS12_381.mk_g2(x1: int, x2: int, y1: int, y2: int, z1: int, z2: int): g2 - Constructs a g2 point. 161 BLS12_381.g1_neg(p: g1): g1 - Negates a g1 value. 162 BLS12_381.g1_norm(p: g1): g1 - Normalizes a g1 value. 163 BLS12_381.g1_valid(p: g1): bool - Checks if a g1 value is a group member. 164 BLS12_381.g1_is_zero(p: g1): bool - Checks if a g1 value is zero. 165 BLS12_381.g1_add(p: g1, q: g1): g1 - Adds two g1 values. 166 BLS12_381.g1_mul(k: fr, p: g1): g1 - Performs scalar multiplication for g1. 167 BLS12_381.g2_neg(p: g2): g2 - Negates a g2 value. 168 BLS12_381.g2_norm(p: g2): g2 - Normalizes a g2 value. 169 BLS12_381.g2_valid(p: g2): bool - Checks if a g2 value is a group member. 170 BLS12_381.g2_is_zero(p: g2): bool - Checks if a g2 value is zero. 171 BLS12_381.g2_add(p: g2, q: g2): g2 - Adds two g2 values. 172 BLS12_381.g2_mul(k: fr, p: g2): g2 - Performs scalar multiplication for g2. 173 BLS12_381.gt_inv(p: gt): gt - Inverts a gt value. 174 BLS12_381.gt_add(p: gt, q: gt): gt - Adds two gt values. 175 BLS12_381.gt_mul(p: gt, q: gt): gt - Multiplies two gt values. 176 BLS12_381.gt_pow(p: gt, k: fr): gt - Calculates exponentiation for gt. 177 BLS12_381.gt_is_one(p: gt): bool - Checks if a gt value is one. 178 BLS12_381.pairing(p: g1, q: g2): gt - Computes the pairing of g1 and g2. 179 BLS12_381.miller_loop(p: g1, q: g2): gt - Performs the Miller loop stage of pairing. 180 BLS12_381.final_exp(p: gt): gt - Performs the final exponentiation step of pairing. 181 182 Func 183 184 Func.id(x: 'a): 'a - Identity function. 185 Func.const(x: 'a): 'b => 'a - Constant function constructor. 186 Func.flip(f: ('a, 'b) => 'c): ('b, 'a) => 'c - Switches the order of arguments of a binary function. 187 Func.comp(f: 'b => 'c, g: 'a => 'b): 'a => 'c - Function composition. 188 Func.pipe(f: 'a => 'b, g: 'b => 'c): 'a => 'c - Flipped function composition. 189 Func.rapply(x: 'a, f: 'a => 'b): 'b - Reverse application. 190 Func.recur(f: ('arg => 'res, 'arg) => 'res): 'arg => 'res - The Z combinator for recursion.