def _rollANumber(): blockHash = GetCurrentBlockHash() tx = GetScriptContainer() txhash = GetTransactionHash(tx) theNumber = abs(blockHash ^ txhash) % 100 theNumber = Add(abs(theNumber), 1) return theNumber
def get_sender_address(): tx = GetScriptContainer() references = tx.References reference = references[0] sender_addr = reference.ScriptHash return sender_addr
def get_asset_attachments(): """ Gets information about NEO and Gas attached to an invocation TX :return: list: A list with information about attached neo and gas """ tx = GetScriptContainer() references = tx.References receiver_addr = GetExecutingScriptHash() print(receiver_addr) sender_addr = None sent_amount_neo = 0 sent_amount_gas = 0 if len(references) > 0: reference = references[0] sender_addr = reference.ScriptHash print(sender_addr) for output in tx.Outputs: if output.ScriptHash == receiver_addr: if output.AssetId == neo_asset_id: sent_amount_neo += output.Value print(sent_amount_neo) if output.AssetId == gas_asset_id: sent_amount_gas += output.Value print(sent_amount_gas) return [receiver_addr, sender_addr, sent_amount_neo, sent_amount_gas]
def GetMintInfo(ctx): """ Gets information about acception coin attached to an invocation TX :return: list: A list with information about attached the acception coin ref:https://github.com/CityOfZion/neo-boa/blob/master/boa_test/example/demo/nex/txio.py """ tx = GetScriptContainer() references = tx.References receiver_addr = GetExecutingScriptHash() sender_addr = None sent_amount_ac = 0 ac = Get(ctx, "ACCEPTCOIN") if len(ac) == 32: if len(references) > 0: reference = references[0] sender_addr = reference.ScriptHash for output in tx.Outputs: if output.ScriptHash == receiver_addr: if output.AssetId == ac: sent_amount_ac += output.Value return [receiver_addr, sender_addr, sent_amount_ac]
def process_withdrawal(): my_container = GetScriptContainer() my_hash = GetExecutingScriptHash() withdrawl_stage = WithdrawStage(my_container) if withdrawl_stage is None: return False withdrawingaddr = getWithdrawAddress(mycontainer, withdrawlstage) assetID = getWithdrawlAsset(mycontainer) if len(assetID) == 20: iswithdrawingNEP5 = True else: iswithdrawingNEP5 = False # inputs = mycontainer.getInputs() # outputs = mycontainer.getOutputs() if withdrawlstage == 'Mark': amount = getbalance(withdrawingaddr, assetID) # Here you can add withdraw fees and things like that markwithdrawal(withdrawingaddr, assetID, amount) byteArray = ['0'] if iswithdrawingNEP5: put(myhash + byteArray, withdrawingaddr) # else: # value = 0 # for output in outputs: # value += outputs[output]['Value'] withdrawing(withdrawingaddr, assetID, amount) return True
def vote(args): """ Vote for a proposal :param args: list of arguments [PROPOSAL_ID, VOTE] :return: bool, result of the execution """ if len(args) != 2: return False # get proposal from storage proposal_id = args[0] proposal_storage = Get(ctx, proposal_id) # check proposal existence if not proposal_storage: print("Proposal not found") return False # get caller address references = GetScriptContainer().References if len(references) < 1: return False caller_addr = references[0].ScriptHash # check if address already voted if Get(ctx, concat(proposal_id, caller_addr)): print('Already voted') return False # Deserialize proposal array proposal = Deserialize(proposal_storage) # iterate authorized address index = 0 while index < len(proposal[3]): if proposal[3][index] == caller_addr: authorized = True break index += 1 if not authorized: print('Not allowed to vote') return False # increment vote counter if args[1] == 1: print('Yes!') proposal[1] = proposal[1] + 1 else: print('No!') proposal[2] = proposal[2] + 1 # serialize proposal and write to storage proposal_storage = Serialize(proposal) Put(ctx, proposal_id, proposal_storage) # mark address as voted Put(ctx, concat(proposal_id, caller_addr), True) return True
def get_asset_attachments(): """ Gets information about Gas attached to an invocation TX :return: list: A list with information about attached gas """ tx = GetScriptContainer() references = tx.References receiver_addr = GetExecutingScriptHash() sender_addr = None sent_amount_gas = 0 if len(references) > 0: reference = references[0] sender_addr = reference.ScriptHash for output in tx.Outputs: if output.ScriptHash == receiver_addr: #Only stick with GAS in this Hackathon #if output.AssetId == neo_asset_id: #sent_amount_neo += output.Value if output.AssetId == gas_asset_id: sent_amount_gas += output.Value return [receiver_addr, sender_addr, sent_amount_gas]
def get_asset_attachments_for_prev(): attachment = create_attachment() tx = GetScriptContainer() # type:Transaction sent_amount_neo = 0 sent_amount_gas = 0 attachment["receiver_addr"] = GetExecutingScriptHash() for ins in tx.Inputs: prev_tx = GetTransaction(ins.Hash) references = prev_tx.References if len(references) > 0: reference = references[0] attachment["sender_addr"] = reference.ScriptHash prev_output = prev_tx.Outputs[ins.Index] if prev_output.ScriptHash == attachment["receiver_addr"] and prev_output.AssetId == attachment["neo_asset_id"]: sent_amount_neo += prev_output.Value if prev_output.ScriptHash == attachment["receiver_addr"] and prev_output.AssetId == attachment["gas_asset_id"]: sent_amount_gas += prev_output.Value attachment.neo_attached = sent_amount_neo attachment.gas_attached = sent_amount_gas return attachment
def GetTransactionHash(): """Fetches the hash of the current transaction. Return: (str): hash of current transaction. """ transaction = GetScriptContainer() hash = GetTransactionHash(transaction) return hash
def random(min,max,salt):# min>=x and x<=max txid = GetTransactionHash(GetScriptContainer()) blockTime = GetTime() blockHash = GetCurrentBlockHash() sysseed = [txid,blockHash, salt, blockTime] sysseed = sha256(Serialize(sysseed)) res = abs(sysseed) number = res % (max-min+1) number = number + min return number
def getExplodePoint(): """ :return: a random number in the range of 1 to 1 000 000 """ blockHash = GetCurrentBlockHash() tx = GetScriptContainer() txhash = GetTransactionHash(tx) randomNumber = abs(blockHash ^ txhash) % 1000000 explodePoint = Add(abs(randomNumber), 1) return explodePoint
def callOracle(date): _require(CheckWitness(operaterAddress) or CheckWitness(adminAddress)) req = getOracleReq(date) key = _concatKey(OraclePrefix, date) txhash = GetTransactionHash(GetScriptContainer()) Put(ctx, key, txhash) oracleContract('CreateOracleRequest', [req, selfAddr]) Notify([txhash]) return True
def perform_exchange(ctx): """ :param token:Token The token object with NEP5/sale settings :return: bool: Whether the exchange was successful """ last_tx = Get(ctx, LAST_TX_KEY) current_tx = GetScriptContainer().Hash if last_tx == current_tx: return False Put(ctx, LAST_TX_KEY, current_tx) attachments = get_asset_attachments() # [receiver, sender, neo, gas] # this looks up whether the exchange can proceed exchange_ok = can_exchange(ctx, attachments, False) sender = attachments['sender'] if not exchange_ok: # This should only happen in the case that there are a lot of TX on the final # block before the total amount is reached. An amount of TX will get through # the verification phase because the total amount cannot be updated during that phase # because of this, there should be a process in place to manually refund tokens if attachments['sent_neo'] > 0: OnRefund(sender, attachments['sent_neo'], neo_asset_id) if attachments['sent_gas'] > 0: OnRefund(sender, attachments['sent_gas'], gas_asset_id) return False balance_key = get_balance_key(sender) # lookup the current balance of the address current_balance = Get(ctx, balance_key) new_nex_tokens = calculate_exchange_amount(attachments) # add it to the the exchanged tokens and persist in storage new_total = new_nex_tokens + current_balance Put(ctx, balance_key, new_total) # update the in circulation amount result = add_to_circulation(ctx, new_nex_tokens) # dispatch transfer event OnTransfer(False, sender, new_nex_tokens) return True
def PurchaseData(order_id, pub_key): order = GetOrder(order_id) if not order: Log("Order doesn't exist") return False if order[3] != '': Log("Already purchased") return False if pub_key == '': Log("Empty public key") return False tx = GetScriptContainer() references = tx.References if len(references) < 1: Log("No NEO attached") return False receiver_addr = GetExecutingScriptHash() received_NEO = 0 for output in tx.Outputs: if output.ScriptHash == receiver_addr: if output.AssetId == NEO_ASSET_ID: received_NEO += output.Value received_NEO /= 100000000 Log("Received total NEO:") Log(received_NEO) price = order[2] if received_NEO < price: Log("Not enough NEO") return False Log("Rewriting order to new public key") context = GetContext() order[3] = pub_key order_data_serialized = serialize_array(order) order_key = concat(ORDER_ID_PREFIX, order_id) Put(context, order_key, order_data_serialized) Log("Payment to user") reference = references[0] sender = GetScriptHash(reference) usr_adr = order[0] DispatchTransferEvent(sender, usr_adr, price) return True
def perform_exchange(ctx): """ :param token:Token The token object with NEP5/sale settings :return: bool: Whether the exchange was successful """ last_tx = Get(ctx, LAST_TX_KEY) current_tx = GetScriptContainer().Hash if last_tx == current_tx: return False Put(ctx, LAST_TX_KEY, current_tx) attachments = get_asset_attachments() # [receiver, sender, neo, gas] # this looks up whether the exchange can proceed exchange_ok = can_exchange(ctx, attachments) if not exchange_ok: print("You cannot exchange! Contact Nodis for refunds!") if attachments[2] > 0: OnRefund(attachments[1], attachments[2], 'neo') if attachments[3] > 0: OnRefund(attachments[1], attachments[3], 'gas') return False print("We will proceed with the exchange of tokens now.") # lookup the current balance of the address current_balance = Get(ctx, attachments[1]) exchanged_tokens = attachments[3] * TOKENS_PER_GAS_SERIES_A / 100000000 # add it to the exchanged tokens and persist in storage new_total = exchanged_tokens + current_balance Put(ctx, attachments[1], new_total) # update the in circulation amount result = add_to_circulation(ctx, exchanged_tokens) # dispatch transfer event OnTransfer(attachments[0], attachments[1], exchanged_tokens) return True
def GeneratorRandom(id): txid = GetTransactionHash(GetScriptContainer()) blockHeigt = GetHeight() + 1 blockTime = GetTime() blockHash = GetCurrentBlockHash() sysseed = [0, id, blockHeigt, blockTime, blockHash] sysseed = sha256(Serialize(sysseed)) resseed = sha256(Serialize([txid, sysseed])) resseed = sha256(Serialize([resseed, resseed])) res = abs(resseed) number = res % 100 number = number + 1 return number
def get_asset_attachments(): """ Gets information about NEO and Gas attached to an invocation TX :return: Attachments: An object with information about attached neo and gas """ attachment = create_attachment() tx = GetScriptContainer() # type:Transaction references = tx.References attachment["receiver_addr"] = GetExecutingScriptHash() if len(references) > 0: reference = references[0] attachment["sender_addr"] = reference.ScriptHash sent_amount_neo = 0 sent_amount_gas = 0 received_amount_neo = 0 received_amount_gas = 0 for output in tx.Outputs: if output.ScriptHash == attachment["receiver_addr"] and output.AssetId == attachment["neo_asset_id"]: sent_amount_neo += output.Value if output.ScriptHash == attachment["receiver_addr"] and output.AssetId == attachment["gas_asset_id"]: sent_amount_gas += output.Value if output.ScriptHash == attachment["sender_addr"] and output.AssetId == attachment["neo_asset_id"]: received_amount_neo += output.Value if output.ScriptHash == attachment["sender_addr"] and output.AssetId == attachment["gas_asset_id"]: received_amount_gas += output.Value attachment.neo_attached = sent_amount_neo attachment.gas_attached = sent_amount_gas attachment.neo_attached_received = received_amount_neo attachment.gas_attached_received = received_amount_gas return attachment
def CreateOracleRequest(request, address): #check witness RequireWitness(address) fee = Get(GetContext(), Fee) #transfer ong to oracle Admin address res = TransferONG(address, Admin, fee) Require(res) #get transaction hash txHash = GetTransactionHash(GetScriptContainer()) #update undoRequestMap undoRequestMap = GetUndoRequestMap() undoRequestMap[txHash] = request b = Serialize(undoRequestMap) Put(GetContext(), UndoRequestKey, b) Notify(["createOracleRequest", request, address]) return True
def registerDomain(executionerPublickey, domainName): if not CheckWitness(executionerPublickey): return False #check domain length if len(domainName) > 80: return False #check if domain exists if existDomain(domainName): return False tx = GetScriptContainer() refs = tx.References if len(refs) < 1: return False ref = refs[0] sentAsset = GetAssetId(ref) if sentAsset is not GAS_ASSET_ID: False receiver = GetExecutingScriptHash() totalReceived = 0 for output in tx.Outputs: scriptHashReceiver = GetScriptHash(output) if scriptHashReceiver == receiver: totalReceived = totalReceived + output.Value if (totalReceived < FEE): return False ctx = GetContext() #save owner Put(ctx, domainName, executionerPublickey) #save first transaction id Put(ctx, createLastTransactionKey(domainName), ("n" - 0x01)) #save score Put(ctx, createScoreKey(domainName), 0x30) tr = concat("m:", domainName) addDomainToStorage(executionerPublickey, tr) return True
def get_asset_attachments(): """ Gets information about NEO and Gas attached to an invocation TX :return: list: A list with information about attached neo and gas """ tx = GetScriptContainer() inputs = tx.References receiver_addr = GetExecutingScriptHash() sender_addr = False sent_amount_neo = 0 sent_amount_gas = 0 sent_from_contract_addr = False if len(inputs) > 0: for input in inputs: if input.ScriptHash == receiver_addr: sent_from_contract_addr = True else: if not sender_addr: sender_addr = input.ScriptHash for output in tx.Outputs: if output.ScriptHash == receiver_addr: if output.AssetId == neo_asset_id: sent_amount_neo += output.Value if output.AssetId == gas_asset_id: sent_amount_gas += output.Value attachments = { 'receiver': receiver_addr, 'sender': sender_addr, 'sent_neo': sent_amount_neo, 'sent_gas': sent_amount_gas, 'sent_from_contract_addr': sent_from_contract_addr } return attachments
def exchange_token(): tx = GetScriptContainer() references = tx.References sender_addr = None receiver_addr = GetExecutingScriptHash() sent_amount_neo = 0 sender_addr = 1 neo_amount = 0 if len(references) > 0: reference = references[0] sender_addr = reference.ScriptHash for output in tx.Outputs: if output.ScriptHash == receiver_addr: neo_amount += output.Value if neo_amount == 0: return false exchanged_amount = neo_amount * 10 current_balance = Get(ctx, sender_addr) Put(ctx, sender_addr, current_balance + exchanged_amount) return True
def get_asset_attachments(): tx = GetScriptContainer() references = tx.References receiver_addr = GetExecutingScriptHash() sender_addr = None sent_amount_neo = 0 sent_amount_gas = 0 if len(references) > 0: reference = references[0] sender_addr = reference.ScriptHash for output in tx.Outputs: if output.ScriptHash == receiver_addr: if output.AssetId == NEO_ASSET_ID: sent_amount_neo += output.Value if output.AssetId == GAS_ASSET_ID: sent_amount_gas += output.Value return [receiver_addr, sender_addr, sent_amount_neo, sent_amount_gas]
def get_asset_attachments(args): """ Gets information about NEO and Gas attached to an invocation TX :return: list: A list with information about the tranzaction """ tx = GetScriptContainer() references = tx.References receiver_addr = GetExecutingScriptHash() sender_addr = None tokenAmount = args[1] * 100000000 if len(references) > 0: reference = references[0] sender_addr = args[0] return [receiver_addr, sender_addr, tokenAmount]
def Main(operation, args): if operation == "vote": if len(args) != 2: return False kaiSmc = args[0] candidateName = args[1] tx = GetScriptContainer() references = tx.References reference = references[0] voter = GetScriptHash(reference) context = GetContext() voterKey = kaiSmc + voter print(voterKey) isVote = Get(context, voterKey) if isVote == 1: print("already Voted") return False Put(context, voterKey, 1) key = kaiSmc + candidateName print(key) currentCount = Get(context, key) print(currentCount) if currentCount is None: currentCount = currentCount + 1 else: currentCount = 0 Put(context, key, currentCount) OnVote(kaiSmc, voter, candidateName) return True print("nothing matches") return False
def sendReqToOracle(jsonIndex): """ call oracle to get format or info of Games, including the gameId, diskId """ RequireWitness(Operater) req = getOracleReq(jsonIndex) txhash = GetTransactionHash(GetScriptContainer()) if Get(GetContext(), concatKey(SENTREQHASH_FORMGAME_PREFIX, jsonIndex)): Put(GetContext(), concatKey(SENTREQHASH_SAVERES_PREFIX, jsonIndex), txhash) else: Put(GetContext(), concatKey(SENTREQHASH_FORMGAME_PREFIX, jsonIndex), txhash) res = OracleContract('CreateOracleRequest', [req, Operater]) # if res == False: # Notify(['callOracle failed']) # return False Notify(["sendReqToOracle", txhash, res]) return True
def MintTokens(): """ Method for an address to call in order to deposit NEO into the NEP5 token owner's address in exchange for a calculated amount of NEP5 tokens :return: whether the token minting was successful :rtype: bool """ print("minting tokens!") tx = GetScriptContainer() references = tx.References print("helol1") if len(references) < 1: print("no neo attached") return False print("hello2") reference = references[0] print("hello2") # sender = reference.ScriptHash sender = GetScriptHash(reference) print("hello4") value = 0 print("hello5") output_asset_id = GetAssetId(reference) if output_asset_id == NEO_ASSET_ID: print("hello6") receiver = GetExecutingScriptHash() print("hello7") for output in tx.Outputs: shash = GetScriptHash(output) print("getting shash..") if shash == receiver: print("adding value?") output_val = GetValue(output) value = value + output_val print("getting rate") rate = CurrentSwapRate() print("got rate") if rate == 0: OnRefund(sender, value) return False num_tokens = value * rate / 100000000 context = GetContext() balance = Get(context, sender) new_total = num_tokens + balance Put(context, sender, new_total) total_supply = Get(context, 'totalSupply') new_total_supply = total_supply + num_tokens Put(context, 'totalSupply', new_total_supply) OnTransfer(0, sender, num_tokens) return True return False
def main(operation, args): trigger = GetTrigger() if trigger == Verification(): ''' Validate inputs Check that valid self send Validate is withdrawing nep5 Validate utxo has been reserved Validate withdraw destination Validate amount withdrawn ''' if get("state") != 'Active': return False tx_data = get_asset_attachments() prev_tx_data = get_asset_attachments_for_prev() # THIS WILL NEED TO BE CALLING A FUNCTION LATER withdrawal_stage = 'Mark' if withdrawal_stage == 'Mark': if not CheckWitness(tx_data["sender_addr"]): return False ''' if not verify_withdrawal(tx_data): return False // Validate inputs as well foreach (var i in inputs) { if (Storage.Get(Context(), i.PrevHash.Concat(IndexAsByteArray(i.PrevIndex))).Length > 0) return false; } ''' tx = GetScriptContainer() inputs = GetInputs(tx) outputs = GetOutputs(tx) if CheckWitness(OWNER): return True return False elif trigger == Application(): if operation == 'initialize': if not CheckWitness(OWNER): print("initialize error") return False if len(args) != 3: print("To few args") return False return initialize() # Get functions if operation == 'getstate': return get("state") # ARGS: asset_id if operation == 'getMakerFee': return get_maker_fee(args[0]) # ARGS: asset_id if operation == 'getTakerFee': return get_taker_fee(args[0]) # ARGS: asset_id if operation == 'getExchangeRate': return get_exchange_rate(args[0]) # ARGS: trading_pair if operation == 'getOffers': return get_offers(args[0]) # ARGS: originator, asset_id if operation == 'getBalance': return get_balance(args[0], args[1]) # Execute functions # ARGS: address, asset_id, amount if operation == 'deposit': if get("state") != 'Active': return False if len(args) != 3: return False if not verify_sent_amount(args[0], args[1], args[2]): return False if not transfer_asset_to(args[0], args[1], args[2]): return False return True # ARGS: maker_address, offer_asset_id, offer_amount, want_asset_id, want_amount, avail_amount, nonce if operation == 'makeOffer': if get("state") != 'Active': return False if len(args) != 7: return False offer = new_offer(args[0], args[1], args[2], args[3], args[4], args[5], args[6]) return make_offer(offer) # ARGS: filler_address, trading_pair, offer_hash, amount_to_fill, use_native_token) if operation == 'fillOffer': if get("state") != 'Active': return False if len(args) != 5: return False return fill_offer(args[0], args[1], args[2], args[3], args[4]) # ARGS: trading_pair, offer_hash if operation == 'cancelOffer': if get("state") != 'Active': return False if len(args) != 2: return False return cancel_offer(args[0], args[1]) if operation == 'withdraw': return process_withdrawal() # Owner Operations if not CheckWitness(OWNER): return False if operation == 'freezeTrading': return freeze_trading() if operation == 'unfreezeTrading': return unfreeze_trading() if operation == 'terminateTrading': return terminate_trading() if operation == 'addToWhitelist': return add_to_whitelist() if operation == 'removeFromWhitelist': return remove_from_whitelist() # ARGS: amount if operation == 'ownerWithdraw': if not CheckWitness(OWNER): print( 'Only the contract owner can withdraw MCT from the contract' ) return False if len(args) != 1: print('withdraw amount not specified') return False t_amount = args[0] my_hash = GetExecutingScriptHash() return transfer(my_hash, t_amount) return False
def Main(operation, txid): tx = GetTransaction(txid) if not tx: return False if operation == 'get_hash': return tx.Hash elif operation == 'get_type': return tx.Type elif operation == 'get_attrs': return tx.Attributes elif operation == 'get_inputs': return tx.Inputs elif operation == 'get_outputs': return tx.Outputs elif operation == 'get_references': return tx.References elif operation == 'get_unspent': return tx.UnspentCoins elif operation == 'get_output_details': res = [] for item in tx.Outputs: subres = [] subres.append(item.Value) subres.append(item.AssetId) subres.append(item.ScriptHash) res.append(subres) return res elif operation == 'get_reference_details': res = [] refs = tx.References for item in refs: subres = [] subres.append(item.Value) subres.append(item.AssetId) subres.append(item.ScriptHash) res.append(subres) return res elif operation == 'get_witnesses': res = [] witnesses = tx.Witnesses for item in witnesses: witness = {'verification': item.VerificationScript} res.append(witness) return res elif operation == 'get_witness_scripthashes': tx = GetScriptContainer() witnesses = tx.Witnesses res = [] for item in witnesses: verification = item.VerificationScript script_hash = hash160(verification) res.append(script_hash) return res # name clash with Input.GetHash and Transaction.GetHash elif operation == 'get_input_details': res = [] inputs = tx.Inputs input1 = inputs[0] inputhash = GetInputHash(input1) inputIndex = input1.Index return [inputhash, inputIndex] return 'unknown operation'
def handle_token_received(chash, args): assert chash == MCT_HASH, 'transactions must use MCT' if t_from == OWNER: # just staking MCT tokens for storage, nothing else to do here return True arglen = len(args) assert arglen == 4, 'incorrect arg length' # parameters of MCT transfer t_from = args[0] t_to = args[1] t_amount = args[2] * 1 p_args = args[3] # 4th argument passed by MCT transfer() assert len(t_from) == 20, 'invalid address' assert len(t_to) == 20, 'invalid address' assert t_to == GetExecutingScriptHash(), 'destination error' assert t_amount > 0, 'no funds transferred' p_len = len(p_args) assert p_len > 1, 'incorrect secondary arg length' p_operation = p_args[0] if p_operation == 'createSale': assert p_len == 4, 'incorrect arguments to createSale' buyer_addr = p_args[1] price = p_args[2] * 1 description = p_args[3] assert price > 0, 'must set a price > 0' assert t_amount == price * 2, 'seller deposit must be 2x price' tx = GetScriptContainer() sale = {} sale['id'] = tx.Hash sale['seller'] = t_from sale['buyer'] = buyer_addr # if empty, any buyer may pay sale['description'] = description # optional sale['price'] = price sale['state'] = 'new' r = Put(concat('sales/', tx.Hash), Serialize(sale)) return True elif p_operation == 'buyerDeposit': assert p_len == 2, 'incorrect arguments to buyerDeposit' sale_id = p_args[1] sale = loadSale(sale_id) assert sale['state'] == 'new', 'sale state incorrect' assert sale['price'] > 0, 'sale price incorrect' assert t_amount == sale['price'] * 2, 'buyer deposit must be 2x price' buyer = sale['buyer'] if len(buyer) == 20: assert CheckWitness(buyer), 'must be listed buyer to place deposit' else: sale['buyer'] = t_from # any-buyer sale claimed sale['state'] = 'awaiting shipment' r = Put(concat('sales/', sale_id), Serialize(sale)) return True
def _getRandomNumber(interval): blockHash = GetCurrentBlockHash() tx = GetScriptContainer() txhash = GetTransactionHash(tx) randomNumber = abs(blockHash ^ txhash) % Add(interval, 1) return randomNumber