├── How to Use with PHP Frameworks ├── README.md └── images │ ├── codeigniter file structure.png │ ├── laravel file structure.png │ ├── lumen file structure.png │ ├── symfony.png │ └── yii file structure.png ├── LICENSE ├── README.md ├── algod.php ├── algokey.php ├── examples ├── asset-manager-gui │ ├── Readme.md │ ├── css │ │ └── main.css │ ├── file-structure.png │ ├── index.html │ ├── js │ │ ├── jquery.min.js │ │ └── main.js │ ├── php │ │ ├── controller.php │ │ └── wallet.class.php │ └── preview.png ├── explorer-gui │ ├── Readme.md │ ├── css │ │ └── main.css │ ├── file-structure.png │ ├── index.html │ ├── js │ │ ├── jquery.min.js │ │ └── main.js │ ├── php │ │ ├── controller.php │ │ └── explorer.class.php │ └── preview.png └── wallet-gui │ ├── Readme.md │ ├── css │ └── main.css │ ├── file-structure.png │ ├── index.html │ ├── js │ ├── jquery.min.js │ └── main.js │ ├── php │ ├── controller.php │ └── wallet.class.php │ └── preview.png ├── indexer.php ├── kmd.php ├── sdk ├── _namespace_based │ └── Algorand │ │ ├── algokey.php │ │ ├── algorand.php │ │ ├── b32.php │ │ ├── msgpack.php │ │ └── transactions.php ├── algokey.php ├── algorand.php ├── codeigniter setup │ └── app │ │ ├── Algorand │ │ ├── algokey.php │ │ ├── algorand.php │ │ ├── b32.php │ │ ├── msgpack.php │ │ └── transactions.php │ │ ├── Config │ │ └── Routes.php │ │ └── Controllers │ │ ├── AlgodController.php │ │ ├── Home.php │ │ ├── IndexerController.php │ │ └── KmdController.php ├── laravel setup │ ├── app │ │ ├── Algorand │ │ │ ├── algokey.php │ │ │ ├── algorand.php │ │ │ ├── b32.php │ │ │ ├── msgpack.php │ │ │ └── transactions.php │ │ └── Http │ │ │ └── Controllers │ │ │ ├── AlgodController.php │ │ │ ├── IndexerController.php │ │ │ └── KmdController.php │ └── routes │ │ └── web.php ├── lumen setup │ ├── app │ │ ├── Algorand │ │ │ ├── algokey.php │ │ │ ├── algorand.php │ │ │ ├── b32.php │ │ │ ├── msgpack.php │ │ │ └── transactions.php │ │ └── Http │ │ │ └── Controllers │ │ │ ├── AlgodController.php │ │ │ ├── IndexerController.php │ │ │ └── KmdController.php │ └── routes │ │ └── web.php ├── symfony setup │ └── src │ │ ├── Algorand │ │ ├── algokey.php │ │ ├── algorand.php │ │ ├── b32.php │ │ ├── msgpack.php │ │ └── transactions.php │ │ ├── Controller │ │ └── DefaultController.php │ │ └── config │ │ └── routes.yaml └── yii setup │ ├── Algorand │ ├── algokey.php │ ├── algorand.php │ ├── b32.php │ ├── msgpack.php │ └── transactions.php │ └── controllers │ └── SiteController.php └── transactions.php /How to Use with PHP Frameworks/images/codeigniter file structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffsolutions/php-algorand-sdk/b9fecf66dc7964cc18f689efcf9a0a2bf0c430bf/How to Use with PHP Frameworks/images/codeigniter file structure.png -------------------------------------------------------------------------------- /How to Use with PHP Frameworks/images/laravel file structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffsolutions/php-algorand-sdk/b9fecf66dc7964cc18f689efcf9a0a2bf0c430bf/How to Use with PHP Frameworks/images/laravel file structure.png -------------------------------------------------------------------------------- /How to Use with PHP Frameworks/images/lumen file structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffsolutions/php-algorand-sdk/b9fecf66dc7964cc18f689efcf9a0a2bf0c430bf/How to Use with PHP Frameworks/images/lumen file structure.png -------------------------------------------------------------------------------- /How to Use with PHP Frameworks/images/symfony.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffsolutions/php-algorand-sdk/b9fecf66dc7964cc18f689efcf9a0a2bf0c430bf/How to Use with PHP Frameworks/images/symfony.png -------------------------------------------------------------------------------- /How to Use with PHP Frameworks/images/yii file structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffsolutions/php-algorand-sdk/b9fecf66dc7964cc18f689efcf9a0a2bf0c430bf/How to Use with PHP Frameworks/images/yii file structure.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 FF Solutions 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /algod.php: -------------------------------------------------------------------------------- 1 | debug(1); 8 | 9 | //algorand->setSSL('/home/felipe/certificate.cert'); //Optional 10 | 11 | #Just uncomment to try all avaliable functions 12 | 13 | #Get the versions 14 | //$return=$algorand->get("versions"); 15 | 16 | #Gets the current node status. 17 | //$return=$algorand->get("v2","status"); 18 | 19 | #Gets the node status after waiting for the given round. 20 | //$return=$algorand->get("v2","status","wait-for-block-after",{block}); 21 | 22 | #Gets the genesis information. 23 | //$return=$algorand->get("genesis"); 24 | 25 | #Returns 200 (OK) if healthy. 26 | //$return=$algorand->get("health"); 27 | 28 | #Return metrics about algod functioning. 29 | //$return=$algorand->get("metrics"); 30 | 31 | #Gets the current swagger spec. 32 | //$return=$algorand->get("swagger.json"); 33 | 34 | #Get account information and balances. 35 | //$return=$algorand->get("v2","accounts","{address}","?exclude=none&?format=json"); //?exclude=none or all. When set to all will exclude asset holdings, &format=json or msgpack (opcional, default json) 36 | 37 | #Get account information about a given app. 38 | //$return=$algorand->get("v2","accounts","{address}","applications","{application-id}"); 39 | 40 | #Get account information about a given asset. 41 | //$return=$algorand->get("v2","accounts","{address}","assets","{asset-id}"); 42 | 43 | #Get a list of unconfirmed transactions currently in the transaction pool by address. 44 | //$return=$algorand->get("v2","accounts","{address}","transactions","pending","?format=json&max=2"); 45 | 46 | #Get application information. 47 | //$return=$algorand->get("v2","applications","{application-id}"); 48 | 49 | #Get box information for a given application. 50 | //$return=$algorand->get("v2","applications","{application-id}","box","?name="); 51 | 52 | #Get all box names for a given application. 53 | //$return=$algorand->get("v2","applications","{application-id}","boxes","?max="); 54 | 55 | #Get asset information. 56 | //$return=$algorand->get("v2","assets","{asset-id}"); 57 | 58 | #Get the block for the given round. 59 | //$return=$algorand->get("v2","blocks","{block}"); 60 | 61 | #Get the block hash for the block on the given round. 62 | //$return=$algorand->get("v2","blocks","{block}","hash"); 63 | 64 | #Gets a proof for a given light block header inside a state proof commitment 65 | //$return=$algorand->get("v2","blocks","{block}","lightheader","proof"); 66 | 67 | #Get a proof for a transaction in a block. 68 | //$return=$algorand->get("v2","blocks","{round}","transactions","{txid}","proof"); 69 | 70 | #Starts a catchpoint catchup. For the last catchpoint access: https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/mainnet/latest.catchpoint 71 | //$return=$algorand->post("v2","catchup","{catchpoint}"); 72 | 73 | #Aborts a catchpoint catchup. 74 | //$return=$algorand->delete("v2","catchup","{catchpoint}"); 75 | 76 | #Get a LedgerStateDelta object for a given round 77 | //$return=$algorand->get("v2","deltas","{round}"); 78 | 79 | #Get the current supply reported by the ledger. 80 | //$return=$algorand->get("v2","ledger","supply"); 81 | 82 | #Returns the minimum sync round the ledger is keeping in cache. 83 | //$return=$algorand->get("v2","ledger","sync"); 84 | 85 | #Removes minimum sync round restriction from the ledger. 86 | //$return=$algorand->delete("v2","ledger","sync"); 87 | 88 | #Given a round, tells the ledger to keep that round in its cache. 89 | //$return=$algorand->post("v2","ledger","sync","{round}"); 90 | 91 | #Add a participation key to the node 92 | /* 93 | $params['body']="{participationkey}"; 94 | $return=$algorand->post("v2","participation",$params); 95 | */ 96 | 97 | #Return a list of participation keys 98 | //$return=$algorand->get("v2","participation"); 99 | 100 | #Append state proof keys to a participation key 101 | /* 102 | $params['body']="{keymap}"; 103 | $return=$algorand->post("v2","participation","{participation-id}",$params); 104 | */ 105 | 106 | #Get participation key info given a participation ID 107 | //$return=$algorand->get("v2","participation","{participation-id}"); 108 | 109 | 110 | #Delete a given participation key by ID 111 | //$return=$algorand->delete("v2","participation","{participation-id}"); 112 | 113 | 114 | #Special management endpoint to shutdown the node. Optionally provide a timeout parameter to indicate that the node should begin shutting down after a number of seconds. 115 | /* 116 | $params['params']=array("timeout" => 0); 117 | $return=$algorand->post("v2","shutdown", $params); 118 | */ 119 | 120 | 121 | #Get a state proof that covers a given round 122 | //$return=$algorand->get("v2","stateproofs","{round}"); 123 | 124 | 125 | #Compile TEAL source code to binary, produce its hash 126 | /* 127 | $params['body']=""; 128 | $return=$algorand->post("v2","teal","compile",$params); 129 | */ 130 | 131 | #Disassemble program bytes into the TEAL source code. 132 | /* 133 | $params['body']=""; 134 | $return=$algorand->post("v2","teal","disassemble",$params); 135 | */ 136 | 137 | 138 | #Provide debugging information for a transaction (or group). 139 | /* 140 | $params['$params']=array( 141 | "accounts" => array(), //Account 142 | "apps" => array(), //Application 143 | "latest-timestamp" => 0, //integer 144 | "protocol-version" => "", //string 145 | "round" => 0, //integer 146 | "sources" => array(), //DryrunSource 147 | "txns" => "", //string (json) > array 148 | ); 149 | $return=$algorand->post("v2","teal","dryrun",$params); 150 | */ 151 | 152 | 153 | #Broadcasts a raw transaction to the network. 154 | #Generate and Sign the transaction with cli or this sdk: 155 | //CLI sample 156 | #./goal clerk send -a 1000 -f {address_from} -t {address_to} -d data -o transactions/tran.txn 157 | #./goal clerk sign --infile="trans/tran.txn" --outfile="trans/tran.stxn" -d data 158 | 159 | 160 | //$params['file']="transactions/tran.stxn"; 161 | /* 162 | $params['transaction']=""; 163 | $return=$algorand->post("v2","transactions",$params); 164 | */ 165 | 166 | #Get parameters for constructing a new transaction 167 | //$return=$algorand->get("v2","transactions","params"); 168 | 169 | #Get a list of unconfirmed transactions currently in the transaction pool. 170 | //$return=$algorand->get("v2","transactions","pending","?format=json&max=2"); 171 | 172 | #Get a specific pending transaction. 173 | //$return=$algorand->get("v2","transactions","pending","{txid}","?format=json"); 174 | 175 | 176 | #Full response with debug (json response) 177 | if(!empty($return)){ 178 | print_r($return); 179 | } 180 | #Only response array 181 | if(!empty($return['response'])){ 182 | print_r(json_decode($return['response'])); 183 | } 184 | #Only erros messages array 185 | if(!empty($return['message'])){ 186 | print_r(json_decode($return['message'])); 187 | } 188 | 189 | //For definitions: 190 | //https://developer.algorand.org/docs/reference/rest-apis/algod/v2/#definitions 191 | ?> 192 | -------------------------------------------------------------------------------- /algokey.php: -------------------------------------------------------------------------------- 1 | generate(); 11 | print_r($key); 12 | echo "Words to string: ".implode(" ",$key['words'])."\n"; 13 | */ 14 | 15 | //Words to Private Key and Public Key (Array) 16 | /* 17 | $words=explode(" ","connect produce defense output sibling idea oil siege decline dentist faint electric method notice style cook unlock rice confirm host tone test vehicle able keen"); //2OEZACD77WSR5C2HFEHO2BYHQEATOGFIUW3REGKOGNPPNYPPLROHDU2CQE 18 | $privateKey=$algokey->WordsToPrivateKey($words); //Array 19 | $privateKey_decoded=base64_decode($privateKey); 20 | $publicKey=$algokey->publicKeyFromPrivateKey($privateKey); 21 | $publicKey_decoded=$algokey->publicKeyFromPrivateKey($privateKey,false); 22 | echo "Private Key: ".$privateKey."\n"; 23 | echo "Private Key decoded: ".$privateKey_decoded."\n"; 24 | echo "Public Key B32: ".$publicKey."\n"; 25 | echo "Public Key decoded: ".$publicKey_decoded."\n"; 26 | */ 27 | 28 | //Private Key to Words 29 | /* 30 | $privateKey="eenqctbZ48E5E8jHoc6jdhTGW/q6L3BP7l3gJnJ+P17TiZAIf/2lHotHKQ7tBweBATcYqKW3EhlOM1724e9cXA=="; 31 | $return_words=$algokey->privateKeyToWords($privateKey); 32 | print_r($return_words); 33 | echo "Words: ".implode(" ",$return_words)."\n"; 34 | */ 35 | 36 | 37 | #Sign Transaction with Algokey PHP 38 | /* 39 | $transaction=array( 40 | "txn" => array( 41 | "type" => "pay", //Tx Type 42 | "fee" => 1000, //Fee 43 | "fv" => 28237321, //First Valid 44 | "gen" => "mainnet-v1.0", // GenesisID 45 | "gh" => "wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=", //Genesis Hash 46 | "lv" => 28238321, //Last Valid 47 | "note" => "", //You note 48 | "snd" => "2QAXTOHQJQH6I4FM6RWUIISXKFJ2QA4NVWELMIJ5XAKZB4N4XIEX7F5KPU", //Sender 49 | "rcv" => "DI65FPLNUXOJJR47FDTIB5TNNIA5G4EZFA44RZMRBE7AA4D453OYD2JCW4", //Receiver 50 | "amt" => 1003, //Amount 51 | ), 52 | ); 53 | 54 | $transaction_raw=$algorand_transactions->encode($transaction); 55 | $signature=$algokey->sign($transaction_raw,$privateKey); 56 | 57 | #Broadcasts a raw transaction to the network. 58 | $transaction_raw_signed=$algorand_transactions->encode($transaction,true,$signature); 59 | 60 | $algorand = new Algorand("algod","4820e6e45f339e0026eaa2b74c2aa7d8735cbcb2db0cf0444fb492892e1c09b7","localhost",53898); 61 | $params['transaction']=$transaction_raw_signed; 62 | print_r($params); 63 | $return=$algorand->post("v2","transactions",$params); 64 | print_r($return); 65 | */ 66 | 67 | ?> -------------------------------------------------------------------------------- /examples/asset-manager-gui/css/main.css: -------------------------------------------------------------------------------- 1 | body{ 2 | background-color: #FFFFFF; 3 | font-size: 16px; 4 | } 5 | a:link, a:visited{ 6 | color: #003399; 7 | text-decoration: none; 8 | } 9 | a:hover{ 10 | color: #0066cc; 11 | text-decoration: none; 12 | } 13 | #wallet{ 14 | position: relative; 15 | width: 95%; 16 | margin-left: auto; 17 | margin-right: auto; 18 | overflow: hidden; 19 | clear: both; 20 | float: none; 21 | } 22 | #wallet #left{ 23 | float: left; 24 | width: 50%; 25 | } 26 | #wallet #right{ 27 | float: right; 28 | width: 50%; 29 | line-height: 25px; 30 | } 31 | #wallet h1{ 32 | font-family: fantasy; 33 | font-size: 38px; 34 | text-align: center; 35 | margin-bottom: 0px; 36 | } 37 | 38 | #wallet h2{ 39 | font-family: fantasy; 40 | font-size: 28px; 41 | text-align: left; 42 | font-family: cursive; 43 | } 44 | 45 | #keys, #assets{ 46 | width: 90%; 47 | height: 108px; 48 | } 49 | 50 | #wallet #left input[type=password]{ 51 | width: 200px; 52 | } 53 | 54 | #wallet #right textarea{ 55 | width: 100%; 56 | height: 150px; 57 | } 58 | #wallet #right select{ 59 | width: 100%; 60 | } 61 | 62 | #wallet #right input[type=text]{ 63 | width: 100%; 64 | } 65 | 66 | #unit_name{ 67 | width: inherit !important; 68 | } 69 | 70 | #transaction_id{ 71 | width: 80% !important; 72 | } 73 | 74 | #asset_title{ 75 | margin-bottom: 0px; 76 | } 77 | -------------------------------------------------------------------------------- /examples/asset-manager-gui/file-structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffsolutions/php-algorand-sdk/b9fecf66dc7964cc18f689efcf9a0a2bf0c430bf/examples/asset-manager-gui/file-structure.png -------------------------------------------------------------------------------- /examples/asset-manager-gui/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Algorand Asset Manager PHP 9 | 10 | 11 | 12 |
13 |

Algorand Asset Manager PHP

14 |
15 |

Wallets

16 | 19 | 20 | 21 | 22 |     23 | 24 | Wallet / Key Manager 25 | 26 |
27 |

Keys / From

28 | 31 | 32 |
33 | 34 | 35 | 36 | 37 |

Assets

38 | 39 | 40 | 43 | 44 |
45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
55 | 104 |
105 | 106 | 107 | -------------------------------------------------------------------------------- /examples/asset-manager-gui/php/wallet.class.php: -------------------------------------------------------------------------------- 1 | kmd=new Algorand("kmd",$kmd_token,$kmd_host,$kmd_port); 7 | } 8 | 9 | 10 | public function token($id,$password){ 11 | $params['params']=array( 12 | "wallet_id" => $id, 13 | "wallet_password" => $password, 14 | ); 15 | $return=$this->kmd->post("v1","wallet","init",$params); 16 | $return_array=json_decode($return['response']); 17 | $wallet_handle_token=$return_array->wallet_handle_token; 18 | return $wallet_handle_token; 19 | } 20 | 21 | 22 | public function list(){ 23 | $output=$this->kmd->get("v1","wallets"); 24 | return $output; 25 | } 26 | 27 | public function info($token){ 28 | $params['params']=array( 29 | "wallet_handle_token" => $token, 30 | ); 31 | return $this->kmd->post("v1","wallet","info",$params); 32 | } 33 | 34 | public function key_list($token){ 35 | $params['params']=array( 36 | "wallet_handle_token" => $token 37 | ); 38 | return $this->kmd->post("v1","key","list",$params); 39 | } 40 | 41 | public function sign($token,$wallet_password,$transaction){ 42 | 43 | $params['params']=array( 44 | "transaction" => $transaction, 45 | "wallet_handle_token" => $token, 46 | "wallet_password" => $wallet_password 47 | ); 48 | 49 | 50 | $return=$this->kmd->post("v1","transaction","sign",$params); 51 | 52 | 53 | if($return['code']==200){ 54 | $r=json_decode($return['response']); 55 | return $txn=base64_decode($r->signed_transaction); 56 | }else{ 57 | return $return; 58 | } 59 | 60 | } 61 | 62 | public function json_print($json){ 63 | $out=json_decode($json); 64 | $out=json_encode($out,JSON_PRETTY_PRINT); 65 | return $out; 66 | } 67 | 68 | 69 | } 70 | ?> 71 | -------------------------------------------------------------------------------- /examples/asset-manager-gui/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffsolutions/php-algorand-sdk/b9fecf66dc7964cc18f689efcf9a0a2bf0c430bf/examples/asset-manager-gui/preview.png -------------------------------------------------------------------------------- /examples/explorer-gui/css/main.css: -------------------------------------------------------------------------------- 1 | body{ 2 | background-color: #FFFFFF; 3 | font-size: 16px; 4 | } 5 | a:link, a:visited{ 6 | color: #003399; 7 | text-decoration: none; 8 | } 9 | a:hover{ 10 | color: #0066cc; 11 | text-decoration: none; 12 | } 13 | 14 | #explorer{ 15 | position: relative; 16 | width: 95%; 17 | margin-left: auto; 18 | margin-right: auto; 19 | overflow: hidden; 20 | clear: both; 21 | float: none; 22 | } 23 | #top{ 24 | float: node; 25 | width: 100%; 26 | text-align: center; 27 | } 28 | #left{ 29 | float: left; 30 | width: 50%; 31 | } 32 | #right{ 33 | float: right; 34 | width: 50%; 35 | } 36 | #bottom{ 37 | float: none; 38 | width: 100%; 39 | clear: both; 40 | } 41 | #explorer h1{ 42 | font-family: fantasy; 43 | font-size: 38px; 44 | text-align: center; 45 | margin-bottom: 0px; 46 | } 47 | 48 | #explorer h2{ 49 | font-family: fantasy; 50 | font-size: 28px; 51 | text-align: left; 52 | font-family: cursive; 53 | } 54 | 55 | #top textarea{ 56 | width: 100%; 57 | height: 250px; 58 | } 59 | 60 | #keyword{ 61 | width: 100% !important; 62 | margin-bottom: 10px; 63 | } 64 | #explorer_output{ 65 | width: 100%; 66 | height: 170px; 67 | } 68 | #limit, #minround, #maxround{ 69 | width: 80px; 70 | } 71 | 72 | #results{ 73 | font-family: Arial; 74 | overflow: hidden; 75 | clear: both; 76 | } 77 | #results ul{ 78 | padding: 0px; 79 | } 80 | #results ul li{ 81 | list-style: none; 82 | border: 1px solid #CCC; 83 | width: calc(50% - 2px); 84 | float: left; 85 | } 86 | #results .full{ 87 | width: calc(100% - 2px); 88 | } 89 | #results ul li h5{ 90 | font-size: 16px; 91 | text-align: left; 92 | margin-left: 20px; 93 | margin-bottom: 10px; 94 | font-weight: normal; 95 | margin: 10px; 96 | } 97 | #results ul li p{ 98 | margin: 10px; 99 | } 100 | #transactions, #blocks{ 101 | font-size: 11px; 102 | font-family: Arial; 103 | } 104 | #transactions ul, #blocks ul{ 105 | padding: 0px; 106 | border-top: 1px solid #CCC; 107 | display: flex; 108 | flex-wrap: wrap-reverse; 109 | } 110 | #blocks ul{ 111 | flex-wrap: wrap; 112 | } 113 | #transactions ul li, #blocks ul li{ 114 | list-style: none; 115 | padding: 10px; 116 | border-bottom: 1px solid #CCC; 117 | width: 100%; 118 | } 119 | #transactions ul li p, #blocks ul li p{ 120 | margin: 0px; 121 | } 122 | 123 | #reload-buttom{ 124 | float: left; 125 | } 126 | -------------------------------------------------------------------------------- /examples/explorer-gui/file-structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffsolutions/php-algorand-sdk/b9fecf66dc7964cc18f689efcf9a0a2bf0c430bf/examples/explorer-gui/file-structure.png -------------------------------------------------------------------------------- /examples/explorer-gui/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Algorand Explorer PHP 9 | 10 | 11 | 12 |
13 |

Algorand Explorer PHP

14 |
15 | 42 |
43 | 44 |
45 |
46 | 47 |
48 |

Latest Transactions

49 |
50 | 51 |
52 |
53 | 59 |
60 |

Output

61 | 62 |
63 |
64 | 65 | 66 | -------------------------------------------------------------------------------- /examples/explorer-gui/js/main.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | 3 | explorer = new Explorer(); 4 | explorer.health(); 5 | explorer.latest_transactions(); 6 | explorer.latest_blocks(); 7 | 8 | $("#search-buttom").click(function(){ 9 | explorer.search(); 10 | }); 11 | 12 | $("#reload-buttom").click(function(){ 13 | window.location.reload(); 14 | }); 15 | 16 | }); 17 | 18 | 19 | class Explorer { 20 | 21 | url="php/controller.php"; 22 | 23 | health() { 24 | $.post(this.url, { 25 | action: "health", 26 | }).done(function( data ) { 27 | $("#explorer_output").val(data); 28 | }); 29 | } 30 | 31 | search() { 32 | if($("#keyword").val()==""){ //List 33 | switch ($("#type").val()) { 34 | case 'address': 35 | $.post(this.url, { 36 | action: "addresses", 37 | limit: $("#limit").val(), 38 | }).done(function( data ) { 39 | $("#right").css("display",""); 40 | $("#left").css("width","50%"); 41 | $("#right h2").html("Addresses"); 42 | $("#blocks").html(data); 43 | }); 44 | break; 45 | 46 | case 'block': 47 | $.post(this.url, { 48 | action: "blocks", 49 | limit: $("#limit").val(), 50 | minround: $("#minround").val(), 51 | }).done(function( data ) { 52 | $("#right").css("display",""); 53 | $("#left").css("width","50%"); 54 | $("#right h2").html("Blocks"); 55 | $("#blocks").html(data); 56 | }); 57 | break; 58 | 59 | case 'application': 60 | $.post(this.url, { 61 | action: "applications", 62 | limit: $("#limit").val(), 63 | }).done(function( data ) { 64 | $("#right").css("display",""); 65 | $("#left").css("width","50%"); 66 | $("#right h2").html("Applications"); 67 | $("#blocks").html(data); 68 | }); 69 | break; 70 | 71 | case 'asset': 72 | $.post(this.url, { 73 | action: "assets", 74 | limit: $("#limit").val(), 75 | }).done(function( data ) { 76 | $("#right").css("display",""); 77 | $("#left").css("width","50%"); 78 | $("#right h2").html("Assets"); 79 | $("#blocks").html(data); 80 | }); 81 | break; 82 | 83 | default: 84 | $("#right").css("display","none"); 85 | $("#left").css("width","100%"); 86 | } 87 | }else{ // 88 | $.post(this.url, { //Search 89 | action: "search", 90 | limit: $("#limit").val(), 91 | type: $("#type").val(), 92 | keyword: $("#keyword").val(), 93 | minround: $("#minround").val(), 94 | maxround: $("#maxround").val(), 95 | }).done(function( data ) { 96 | $("#right").css("display","none"); 97 | $("#left").css("width","100%"); 98 | $("#results").html(data); 99 | }); 100 | } 101 | 102 | this.transactions(); 103 | 104 | } 105 | 106 | transactions() { 107 | $.post(this.url, { 108 | action: "transactions", 109 | limit: $("#limit").val(), 110 | type: $("#type").val(), 111 | keyword: $("#keyword").val(), 112 | minround: $("#minround").val(), 113 | maxround: $("#maxround").val(), 114 | }).done(function( data ) { 115 | $("#transactions").html(data); 116 | }); 117 | } 118 | 119 | latest_transactions() { 120 | $.post(this.url, { 121 | action: "latest_transactions", 122 | }).done(function( data ) { 123 | $("#transactions").html(data); 124 | }); 125 | } 126 | 127 | latest_blocks() { 128 | $.post(this.url, { 129 | action: "latest_blocks", 130 | }).done(function( data ) { 131 | $("#blocks").html(data); 132 | }); 133 | } 134 | 135 | address(value) { 136 | $("#type").val("address"); 137 | $("#keyword").val(value); 138 | this.search(); 139 | } 140 | 141 | txid(value) { 142 | $("#type").val("txid"); 143 | $("#keyword").val(value); 144 | this.search(); 145 | } 146 | 147 | block(value) { 148 | $("#type").val("block"); 149 | $("#keyword").val(value); 150 | this.search(); 151 | } 152 | 153 | asset(value) { 154 | $("#type").val("asset"); 155 | $("#keyword").val(value); 156 | this.search(); 157 | } 158 | 159 | application(value) { 160 | $("#type").val("application"); 161 | $("#keyword").val(value); 162 | this.search(); 163 | } 164 | 165 | } 166 | -------------------------------------------------------------------------------- /examples/explorer-gui/php/controller.php: -------------------------------------------------------------------------------- 1 | indexer_init(); 6 | 7 | 8 | $action=$_POST['action']; 9 | $type=$_POST['type']; 10 | $limit=$_POST['limit']; 11 | $keyword=$_POST['keyword']; 12 | $minround=$_POST['minround']; 13 | $maxround=$_POST['maxround']; 14 | 15 | 16 | switch ($action) { 17 | case 'health': 18 | $return=$explorer->health(); 19 | echo $explorer->json_print($return['response']); 20 | exit(); 21 | break; 22 | 23 | case "search": 24 | switch ($type) { 25 | case "address": 26 | echo $explorer->format_address($explorer->address($keyword)); 27 | exit(); 28 | break; 29 | 30 | case "txid": 31 | echo $explorer->format_transaction($explorer->transaction($keyword)); 32 | exit(); 33 | break; 34 | 35 | case "block": 36 | echo $explorer->format_block($explorer->block($keyword)); 37 | exit(); 38 | break; 39 | 40 | case "asset": 41 | echo $explorer->format_asset($explorer->asset($keyword)); 42 | exit(); 43 | break; 44 | 45 | case "application": 46 | echo $explorer->format_application($explorer->application($keyword)); 47 | exit(); 48 | break; 49 | } 50 | exit(); 51 | break; 52 | 53 | case "transactions": 54 | $params=array(); 55 | 56 | if(!empty($limit)){ $params['limit']=$limit; } 57 | if(!empty($keyword) AND $type=="application"){ $params['application-id']=$keyword; } 58 | if(!empty($keyword) AND $type=="asset"){ $params['asset-id']=$keyword; } 59 | if($type=="block"){ 60 | if(!empty($keyword)){ $params['round']=$keyword; } 61 | }else{ 62 | if($minround!="" AND $maxround==""){ 63 | 64 | $params['round']=$minround; 65 | }else{ 66 | if(!empty($minround)){ $params['min-round']=$minround; } 67 | if(!empty($maxround)){ $params['max-round']=$maxround; } 68 | } 69 | } 70 | if(!empty($keyword) AND $type=="txid"){ $params['txid']=$keyword; } 71 | if(!empty($keyword) AND $type=="address"){ $params['address']=$keyword; } 72 | 73 | echo $explorer->format_transactions($explorer->transactions($params)); 74 | exit(); 75 | break; 76 | 77 | case "addresses": 78 | $params=array(); 79 | if(!empty($limit)){ $params['limit']=$limit; } 80 | echo $explorer->format_addresses($explorer->addresses($params)); 81 | exit(); 82 | break; 83 | 84 | case "blocks": 85 | if($minround==0){ 86 | $return=$explorer->indexer->get("health"); 87 | $return=json_decode($return['response']); 88 | $round=$return->round; 89 | }else{ 90 | $round=$minround; 91 | } 92 | echo ''; 102 | exit(); 103 | break; 104 | 105 | case "assets": 106 | $params=array(); 107 | if(!empty($limit)){ $params['limit']=$limit; } 108 | echo $explorer->format_assets($explorer->assets($params)); 109 | exit(); 110 | break; 111 | 112 | case "applications": 113 | $params=array(); 114 | if(!empty($limit)){ $params['limit']=$limit; } 115 | echo $explorer->format_applications($explorer->applications($params)); 116 | exit(); 117 | break; 118 | 119 | case "latest_transactions": 120 | //Get the current block 121 | $return=$explorer->indexer->get("health"); 122 | $return=json_decode($return['response']); 123 | $round=$return->round; 124 | 125 | $params=array(); 126 | $params['max-round']=$round; 127 | $params['min-round']=$round-1000; 128 | $params['limit']=10; 129 | echo $explorer->format_transactions($explorer->transactions($params)); 130 | exit(); 131 | break; 132 | 133 | case "latest_blocks": 134 | //Get the current block 135 | $return=$explorer->indexer->get("health"); 136 | $return=json_decode($return['response']); 137 | $round=$return->round; 138 | echo ''; 147 | exit(); 148 | break; 149 | } 150 | ?> 151 | -------------------------------------------------------------------------------- /examples/explorer-gui/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffsolutions/php-algorand-sdk/b9fecf66dc7964cc18f689efcf9a0a2bf0c430bf/examples/explorer-gui/preview.png -------------------------------------------------------------------------------- /examples/wallet-gui/css/main.css: -------------------------------------------------------------------------------- 1 | body{ 2 | background-color: #FFFFFF; 3 | font-size: 16px; 4 | 5 | } 6 | #wallet{ 7 | position: relative; 8 | width: 95%; 9 | margin-left: auto; 10 | margin-right: auto; 11 | overflow: hidden; 12 | clear: both; 13 | float: none; 14 | } 15 | #wallet #left{ 16 | float: left; 17 | width: 50%; 18 | } 19 | #wallet #right{ 20 | float: right; 21 | width: 50%; 22 | } 23 | #wallet h1{ 24 | font-family: fantasy; 25 | font-size: 38px; 26 | text-align: center; 27 | margin-bottom: 0px; 28 | } 29 | 30 | #wallet h2{ 31 | font-family: fantasy; 32 | font-size: 28px; 33 | text-align: left; 34 | font-family: cursive; 35 | } 36 | 37 | #wallet select{ 38 | width: 90%; 39 | height: 120px; 40 | } 41 | 42 | #wallet #left input[type=text], #wallet #left input[type=password]{ 43 | width: 45%; 44 | } 45 | 46 | #wallet #right textarea{ 47 | width: 100%; 48 | height: 250px; 49 | } 50 | 51 | #wallet #right input[type=text]{ 52 | width: 100%; 53 | } 54 | 55 | #transaction_id{ 56 | width: 80% !important; 57 | } 58 | -------------------------------------------------------------------------------- /examples/wallet-gui/file-structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffsolutions/php-algorand-sdk/b9fecf66dc7964cc18f689efcf9a0a2bf0c430bf/examples/wallet-gui/file-structure.png -------------------------------------------------------------------------------- /examples/wallet-gui/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Algorand Wallet PHP 9 | 10 | 11 | 12 |
13 |

Algorand Wallet PHP

14 |
15 |

Wallets

16 | 19 |

20 | 21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 29 | 30 |

Keys

31 | 32 | 35 | 36 |

37 | 38 | 39 | 40 | 41 |
42 | 56 |
57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/wallet-gui/js/main.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | 3 | wallet = new Wallet(); 4 | wallet.list(); 5 | 6 | $("#wallet_load_keys").click(function(){ 7 | var id_wallet=$("#wallets").val(); 8 | wallet.list_keys(); 9 | }); 10 | 11 | $("#key_copy").click(function(){ 12 | $("#tmp").val($("#keys option:selected").val()); 13 | $("#tmp").focus(); 14 | $("#tmp").select(); 15 | document.execCommand('copy'); 16 | }); 17 | 18 | $("#wallet_create").click(function(){ 19 | wallet.create(); 20 | }); 21 | 22 | $("#wallet_rename").click(function(){ 23 | wallet.rename(); 24 | }); 25 | 26 | $("#wallet_info").click(function(){ 27 | wallet.info(); 28 | }); 29 | 30 | $("#key_generate").click(function(){ 31 | wallet.key_generate(); 32 | }); 33 | 34 | $("#key_balance").click(function(){ 35 | wallet.key_balance(); 36 | }); 37 | 38 | $("#send").click(function(){ 39 | wallet.send(); 40 | }); 41 | 42 | 43 | $("#key_delete").click(function(){ 44 | var r = confirm("Are you sure you want to remove this key?"); 45 | if (r == true) { 46 | wallet.key_delete(); 47 | } 48 | }); 49 | 50 | }); 51 | 52 | 53 | class Wallet { 54 | 55 | url="php/controller.php"; 56 | 57 | list() { 58 | $.post(this.url, { 59 | action: "list", 60 | }).done(function( data ) { 61 | var obj = $.parseJSON(data); 62 | $("#wallets").html(""); 63 | $.each(obj.wallets, function(index,itemx) { 64 | $("#wallets").append(''); 65 | }); 66 | }); 67 | } 68 | 69 | create() { 70 | $.post(this.url, { 71 | action: "create", 72 | wallet_name: $("#wallet_name").val(), 73 | wallet_password: $("#wallet_password").val(), 74 | }).done(function( data ) { 75 | $("#wallet_output").val(data); 76 | wallet.list(); 77 | var obj = $.parseJSON(data); 78 | console.log(obj); 79 | }); 80 | } 81 | 82 | rename() { 83 | $.post(this.url, { 84 | action: "rename", 85 | wallet_id: $("#wallets option:selected").val(), 86 | wallet_name: $("#wallet_name").val(), 87 | wallet_password: $("#wallet_password").val(), 88 | }).done(function( data ) { 89 | $("#wallet_output").val(data); 90 | wallet.list(); 91 | var obj = $.parseJSON(data); 92 | console.log(obj); 93 | }); 94 | } 95 | 96 | info() { 97 | $.post(this.url, { 98 | action: "info", 99 | wallet_id: $("#wallets option:selected").val(), 100 | wallet_password: $("#wallet_password").val(), 101 | }).done(function( data ) { 102 | $("#wallet_output").val(data); 103 | var obj = $.parseJSON(data); 104 | console.log(obj); 105 | }); 106 | } 107 | 108 | transaction_info() { 109 | $.post(this.url, { 110 | action: "transaction_info", 111 | key_id: $("#keys option:selected").val(), 112 | transaction_id: $("#transaction_id").val(), 113 | }).done(function( data ) { 114 | $("#wallet_output").val(data); 115 | var obj = $.parseJSON(data); 116 | console.log(obj); 117 | }); 118 | } 119 | 120 | key_generate() { 121 | $.post(this.url, { 122 | action: "key_generate", 123 | wallet_password: $("#wallet_password").val(), 124 | wallet_id: $("#wallets option:selected").val(), 125 | }).done(function( data ) { 126 | $("#wallet_output").val(data); 127 | wallet.list_keys(); 128 | var obj = $.parseJSON(data); 129 | console.log(obj); 130 | }); 131 | } 132 | 133 | key_balance() { 134 | $.post(this.url, { 135 | action: "key_balance", 136 | key_id: $("#keys option:selected").val(), 137 | }).done(function( data ) { 138 | $("#wallet_output").val(data); 139 | var obj = $.parseJSON(data); 140 | console.log(obj); 141 | }); 142 | } 143 | 144 | key_delete() { 145 | $.post(this.url, { 146 | action: "key_delete", 147 | wallet_id: $("#wallets option:selected").val(), 148 | key_id: $("#keys option:selected").val(), 149 | wallet_password: $("#wallet_password").val(), 150 | }).done(function( data ) { 151 | $("#wallet_output").val(data); 152 | wallet.list_keys(); 153 | var obj = $.parseJSON(data); 154 | console.log(obj); 155 | }); 156 | } 157 | 158 | list_keys() { 159 | $.post(this.url, { 160 | action: "list_keys", 161 | wallet_id: $("#wallets option:selected").val(), 162 | wallet_password: $("#wallet_password").val(), 163 | }).done(function( data ) { 164 | 165 | var obj = $.parseJSON(data); 166 | console.log(obj); 167 | $("#keys").html(""); 168 | $.each(obj.addresses, function(index,itemx) { 169 | $("#keys").append(''); 170 | }); 171 | 172 | }); 173 | } 174 | 175 | send() { 176 | $.post(this.url, { 177 | 178 | action: "send", 179 | wallet_id: $("#wallets option:selected").val(), 180 | key_id: $("#keys option:selected").val(), 181 | wallet_password: $("#wallet_password").val(), 182 | to: $("#to").val(), 183 | amount: $("#amount").val(), 184 | note: $("#note").val(), 185 | 186 | }).done(function( data ) { 187 | $("#wallet_output").val(data); 188 | var obj = $.parseJSON(data); 189 | console.log(obj); 190 | }); 191 | } 192 | 193 | 194 | } 195 | -------------------------------------------------------------------------------- /examples/wallet-gui/php/controller.php: -------------------------------------------------------------------------------- 1 | kmd_init($kmd_token,$kmd_host,$kmd_port); 14 | $algod = new Algorand("algod",$algod_token,$algod_host,$algod_port); 15 | $algorand_transactions = new Algorand_transactions; 16 | 17 | 18 | $action=$_POST['action']; 19 | $wallet_id=$_POST['wallet_id']; 20 | $wallet_password=$_POST['wallet_password']; 21 | $wallet_name=$_POST['wallet_name']; 22 | $key_id=$_POST['key_id']; 23 | $transaction_id=$_POST['transaction_id']; 24 | $to=$_POST['to']; 25 | $amount=$_POST['amount']; 26 | $note=$_POST['note']; 27 | 28 | switch ($action) { 29 | case 'list': 30 | $return=$wallet->list(); 31 | echo $return['response']; 32 | exit(); 33 | break; 34 | 35 | case 'create': 36 | $return=$wallet->create($wallet_name,$wallet_password); 37 | echo $wallet->json_print($return['response']); 38 | exit(); 39 | break; 40 | 41 | case 'rename': 42 | $return=$wallet->rename($wallet_name,$wallet_id,$wallet_password); 43 | echo $wallet->json_print($return['response']); 44 | exit(); 45 | break; 46 | 47 | case 'info': 48 | $wallet_token=$wallet->token($wallet_id,$wallet_password); 49 | $return=$wallet->info($wallet_token); 50 | echo $wallet->json_print($return['response']); 51 | exit(); 52 | break; 53 | 54 | case 'transaction_info': 55 | $return=$wallet->key_transaction_info($key_id,$transaction_id); 56 | echo $wallet->json_print($return['response']); 57 | exit(); 58 | break; 59 | 60 | case 'key_balance': 61 | $return=$algod->get("v2","accounts",$key_id); 62 | echo $wallet->json_print($return['response']); 63 | exit(); 64 | break; 65 | 66 | case 'key_delete': 67 | $wallet_token=$wallet->token($wallet_id,$wallet_password); 68 | $return=$wallet->key_delete($wallet_token,$key_id,$wallet_password); 69 | echo $wallet->json_print($return['response']); 70 | exit(); 71 | break; 72 | 73 | case 'key_generate': 74 | $wallet_token=$wallet->token($wallet_id,$wallet_password); 75 | $return=$wallet->key_generate($wallet_token); 76 | echo $wallet->json_print($return['response']); 77 | exit(); 78 | break; 79 | 80 | case 'list_keys': 81 | $wallet_token=$wallet->token($wallet_id,$wallet_password); 82 | $return=$wallet->key_list($wallet_token); 83 | echo $wallet->json_print($return['response']); 84 | exit(); 85 | break; 86 | 87 | case 'send': 88 | 89 | 90 | #Get parameters for constructing a new transaction 91 | $param_return=$algod->get("v2","transactions","params"); 92 | 93 | if($param_return['code']==200){ 94 | $transaction_param=json_decode($param_return['response']); 95 | }else{ 96 | return $param_return; 97 | } 98 | 99 | $fee=$transaction_param->{'min-fee'}; 100 | $fv=$transaction_param->{'last-round'}; 101 | $genesis_id=$transaction_param->{'genesis-id'}; 102 | $genesis_hash=$transaction_param->{'genesis-hash'}; 103 | $lv=$fv+1000; 104 | 105 | $transaction=array( 106 | "txn" => array( 107 | "fee" => $fee, //Fee 108 | "fv" => $fv, //First Valid 109 | "gen" => $genesis_id, // GenesisID 110 | "gh" => $genesis_hash, //Genesis Hash 111 | "lv" => $lv, //Last Valid 112 | "note" => $note, //You note 113 | "snd" => $key_id, //Sender 114 | "type" => "pay", //Tx Type 115 | "rcv" => $to, //Receiver 116 | "amt" => $amount, //Amount 117 | ), 118 | ); 119 | 120 | $transaction=$algorand_transactions->encode($transaction); 121 | 122 | //Sign Transaction 123 | $wallet_token=$wallet->token($wallet_id,$wallet_password); 124 | $txn_signed=$wallet->sign($wallet_token,$wallet_password,$transaction); 125 | 126 | #Broadcasts a raw transaction to the network. 127 | $params['transaction']=$txn_signed; 128 | $return=$algod->post("v2","transactions",$params); 129 | 130 | 131 | if($return['response']){ 132 | echo $wallet->json_print($return['response']); 133 | } 134 | if($return['message']){ 135 | echo $wallet->json_print($return['message']); 136 | } 137 | 138 | /* 139 | Array 140 | ( 141 | [code] => 200 142 | [response] => {"txId":"AOS5ODVPULLEUVPZ6FJVYUYXTRRP7C4I767B4O2AD2YV5AMNVCLA"} 143 | 144 | ) 145 | */ 146 | 147 | 148 | 149 | exit(); 150 | break; 151 | } 152 | ?> 153 | -------------------------------------------------------------------------------- /examples/wallet-gui/php/wallet.class.php: -------------------------------------------------------------------------------- 1 | kmd=new Algorand("kmd",$kmd_token,$kmd_host,$kmd_port); 9 | } 10 | 11 | public function tests(){ 12 | $algod=$this->algod->get("v2","status"); 13 | $kmd=$this->kmd->get("versions"); 14 | $output=array( 15 | "aldod" => $algod, 16 | "kmd" => $kmd 17 | ); 18 | return $output; 19 | } 20 | 21 | public function token($id,$password){ 22 | $params['params']=array( 23 | "wallet_id" => $id, 24 | "wallet_password" => $password, 25 | ); 26 | $return=$this->kmd->post("v1","wallet","init",$params); 27 | $return_array=json_decode($return['response']); 28 | $wallet_handle_token=$return_array->wallet_handle_token; 29 | return $wallet_handle_token; 30 | } 31 | 32 | public function create($name,$password){ 33 | $params['params']=array( 34 | "wallet_name" => $name, 35 | "wallet_password" => $password, 36 | "wallet_driver_name" => "sqlite", 37 | ); 38 | return $this->kmd->post("v1","wallet",$params); 39 | 40 | /* 41 | Array 42 | ( 43 | [code] => 200 44 | [response] => { 45 | "wallet": { 46 | "driver_name": "sqlite", 47 | "driver_version": 1, 48 | "id": "552284ca1503a10d73de88071c48314b", 49 | "mnemonic_ux": false, 50 | "name": "Wallet 2", 51 | "supported_txs": [ 52 | "pay", 53 | "keyreg" 54 | ] 55 | } 56 | } 57 | ) 58 | */ 59 | } 60 | 61 | public function list(){ 62 | $output=$this->kmd->get("v1","wallets"); 63 | return $output; 64 | /* 65 | Array 66 | ( 67 | [code] => 200 68 | [response] => { 69 | "wallets": [ 70 | { 71 | "driver_name": "sqlite", 72 | "driver_version": 1, 73 | "id": "4596a5cb20ccbedcec668762449363c1", 74 | "mnemonic_ux": false, 75 | "name": "Carteira 1", 76 | "supported_txs": [ 77 | "pay", 78 | "keyreg" 79 | ] 80 | }, 81 | */ 82 | } 83 | 84 | 85 | 86 | public function info($token){ 87 | $params['params']=array( 88 | "wallet_handle_token" => $token, 89 | ); 90 | return $this->kmd->post("v1","wallet","info",$params); 91 | /* 92 | Array 93 | ( 94 | [code] => 200 95 | [response] => { 96 | "wallet_handle": { 97 | "expires_seconds": 59, 98 | "wallet": { 99 | "driver_name": "sqlite", 100 | "driver_version": 1, 101 | "id": "4596a5cb20ccbedcec668762449363c1", 102 | "mnemonic_ux": false, 103 | "name": "Carteira 1", 104 | "supported_txs": [ 105 | "pay", 106 | "keyreg" 107 | ] 108 | } 109 | } 110 | } 111 | ) 112 | */ 113 | } 114 | public function rename($new_name,$id,$password){ 115 | $params['params']=array( 116 | "wallet_id" => $id, 117 | "wallet_name" => $new_name, 118 | "wallet_password" => $password, 119 | ); 120 | return $this->kmd->post("v1","wallet","rename",$params); 121 | /* 122 | Array 123 | ( 124 | [code] => 200 125 | [response] => { 126 | "wallet": { 127 | "driver_name": "sqlite", 128 | "driver_version": 1, 129 | "id": "4596a5cb20ccbedcec668762449363c1", 130 | "mnemonic_ux": false, 131 | "name": "Wallet 1", 132 | "supported_txs": [ 133 | "pay", 134 | "keyreg" 135 | ] 136 | } 137 | } 138 | ) 139 | */ 140 | } 141 | 142 | public function key_generate($token){ 143 | $params['params']=array( 144 | "display_mnemonic" => false, 145 | "wallet_handle_token" => $token 146 | ); 147 | return $this->kmd->post("v1","key",$params); 148 | /* 149 | Array 150 | ( 151 | [code] => 200 152 | [response] => { 153 | "address": "PL7BZ57KTKBVE2OFRNEJ4Z6VSYZPBH5T5SKS7L3O3IMYXIU4QCDAXJNRMM" 154 | } 155 | ) 156 | */ 157 | } 158 | 159 | public function key_delete($token,$address,$password){ 160 | $params['params']=array( 161 | "address" => $address, 162 | "wallet_handle_token" => $token, 163 | "wallet_password" => $password 164 | ); 165 | return $this->kmd->delete("v1","key",$params); 166 | /* 167 | Array 168 | ( 169 | [code] => 200 170 | [response] => {} 171 | ) 172 | */ 173 | } 174 | 175 | public function key_list($token){ 176 | $params['params']=array( 177 | "wallet_handle_token" => $token 178 | ); 179 | return $this->kmd->post("v1","key","list",$params); 180 | /* 181 | Array 182 | ( 183 | [code] => 200 184 | [response] => { 185 | "addresses": [ 186 | "DI65FPLNUXOJJR47FDTIB5TNNIA5G4EZFA44RZMRBE7AA4D453OYD2JCW4", 187 | "PL7BZ57KTKBVE2OFRNEJ4Z6VSYZPBH5T5SKS7L3O3IMYXIU4QCDAXJNRMM" 188 | ] 189 | } 190 | ) 191 | */ 192 | } 193 | 194 | 195 | public function sign($token,$wallet_password,$transaction){ 196 | 197 | $params['params']=array( 198 | "transaction" => $transaction, 199 | "wallet_handle_token" => $token, 200 | "wallet_password" => $wallet_password 201 | ); 202 | 203 | 204 | $return=$this->kmd->post("v1","transaction","sign",$params); 205 | 206 | 207 | if($return['code']==200){ 208 | $r=json_decode($return['response']); 209 | return $txn=base64_decode($r->signed_transaction); 210 | }else{ 211 | return $return; 212 | } 213 | 214 | } 215 | 216 | public function json_print($json){ 217 | $out=json_decode($json); 218 | $out=json_encode($out,JSON_PRETTY_PRINT); 219 | return $out; 220 | } 221 | 222 | 223 | } 224 | ?> 225 | -------------------------------------------------------------------------------- /examples/wallet-gui/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffsolutions/php-algorand-sdk/b9fecf66dc7964cc18f689efcf9a0a2bf0c430bf/examples/wallet-gui/preview.png -------------------------------------------------------------------------------- /indexer.php: -------------------------------------------------------------------------------- 1 | debug(1); 8 | //algorand->setSSL('/home/felipe/certificate.cert'); //Optional 9 | 10 | #Just uncomment to try all avaliable functions 11 | 12 | #Get health, Returns 200 if healthy. 13 | //$return=$algorand_indexer->get("health"); 14 | 15 | #Search for accounts. 16 | /* 17 | $query=http_build_query(array( 18 | //"application-id" => 0, //integer 19 | //"asset-id" => 0, //integer 20 | //"auth-addr" => "", //string 21 | //"currency-greater-than" => 0, //integer 22 | //"currency-less-than" => 0, //integer 23 | "limit" => 100, //integer 24 | //"next" => "", //string - previous return {next-token} 25 | //"round" => 0, //integer 26 | )); 27 | $return=$algorand_indexer->get("v2","accounts?".$query); 28 | */ 29 | 30 | #Lookup account information. 31 | //$return=$algorand_indexer->get("v2","accounts","{account-id}"); 32 | //$return=$algorand_indexer->get("v2","accounts","2MSH4KOT47B4ROHGROVV4AXBLKD4GYY47SX45UIGMOYMG4D4AZUG3WUFXA"); 33 | 34 | #Lookup account transactions. 35 | /* 36 | $query=http_build_query(array( 37 | //"application-id" => 0, //integer 38 | "asset-id" => 0, //integer 39 | "after-time" => "", //string (date-time) 40 | "before-time" => "", //string (date-time) 41 | "currency-greater-than" => 0, //integer 42 | "currency-less-than" => 0, //integer 43 | "limit" => 100, //integer 44 | //"max-round" => 0, //integer 45 | //"min-round" => 0, //integer 46 | //"next" => "", //string - previous return {next-token} 47 | "note-prefix" => "", //string 48 | "rekey-to" => false, //boolean 49 | //"round" => "", //integer 50 | "sig-type" => "sig", //enum (sig, msig, lsig) 51 | "tx-type" => "pay", //enum (pay, keyreg, acfg, axfer, afrz, appl) 52 | "txid" => "", //string 53 | )); 54 | */ 55 | //$return=$algorand_indexer->get("v2","accounts","{account-id}","transactions?".$query); 56 | //$return=$algorand_indexer->get("v2","accounts","2QAXTOHQJQH6I4FM6RWUIISXKFJ2QA4NVWELMIJ5XAKZB4N4XIEX7F5KPU","transactions?".$query); 57 | 58 | 59 | #Search for applications 60 | /* 61 | $query=http_build_query(array( 62 | "application-id" => 0, //integer 63 | "limit" => 100, //integer 64 | //"next" => "", //string - previous return {next-token} 65 | )); 66 | $return=$algorand_indexer->get("v2","applications?".$query); 67 | */ 68 | 69 | #Lookup application. 70 | //$return=$algorand_indexer->get("v2","applications","{application-id}"); 71 | 72 | #Search for assets. 73 | /* 74 | $query=http_build_query(array( 75 | //"asset-id" => 0, //integer 76 | //"creator" => 0, //integer 77 | "limit" => 100, //integer 78 | //"name" => "", //string 79 | //"next" => "", //string - previous return {next-token} 80 | //"unit" => "", //string 81 | )); 82 | $return=$algorand_indexer->get("v2","assets?".$query); 83 | */ 84 | 85 | #Lookup asset information. 86 | //$return=$algorand_indexer->get("v2","assets","5"); 87 | //$return=$algorand_indexer->get("v2","assets","312769"); 88 | 89 | #Lookup the list of accounts who hold this asset 90 | /* 91 | $query=http_build_query(array( 92 | //"currency-greater-than" => 0, //integer 93 | //"currency-less-than" => 0, //integer 94 | "limit" => 100, //integer 95 | //"next" => "", //string - previous return {next-token} 96 | //"round" => "", //integer 97 | )); 98 | $return=$algorand_indexer->get("v2","assets","{asset-id}","balances?".$query); 99 | */ 100 | 101 | #Lookup the list of accounts who hold this asset 102 | /* 103 | $query=http_build_query(array( 104 | "address" => "", //string 105 | "address-role" => "", //enum (sender, receiver, freeze-target) 106 | "after-time" => "", //string (date-time) 107 | "before-time" => "", //string (date-time) 108 | "currency-greater-than" => 0, //integer 109 | //"currency-less-than" => 0 //integer 110 | "exclude-close-to" => false, //boolean 111 | "limit" => 100, //integer 112 | "max-round" => 0, //integer 113 | "min-round" => 0, //integer 114 | //"next" => "", //string - previous return {next-token} 115 | "note-prefix" => "", //string 116 | "rekey-to" => false, //boolean 117 | //"round" => "", //integer 118 | "sig-type" => "sig", //enum (sig, msig, lsig) 119 | "tx-type" => "pay", //enum (pay, keyreg, acfg, axfer, afrz, appl) 120 | "txid" => "", //string 121 | )); 122 | $return=$algorand_indexer->get("v2","assets","{asset-id}","transactions".$query); 123 | */ 124 | 125 | #Lookup block. 126 | //$return=$algorand_indexer->get("v2","blocks","{round-number}"); 127 | //$return=$algorand_indexer->get("v2","blocks","5876435"); 128 | 129 | #Search for transactions. 130 | /* 131 | $query=http_build_query(array( 132 | //"address" => "NJCLL5UPIZKXTHQ42M52B72DSO3PATJ2DEQOZQXJMWFMZPDLGUYV3PBJ5Q", //string 133 | //"address-role" => "sender", //enum (sender, receiver, freeze-target) 134 | //"after-time" => "", //string (date-time) 135 | //"application-id" => 0, //integer 136 | //"asset-id" => 0, //integer 137 | //"before-time" => "", //string (date-time) 138 | //"currency-greater-than" => 0, //integer 139 | //"currency-less-than" => 0, //integer 140 | //"exclude-close-to" => "false", //boolean 141 | "limit" => "100", //integer 142 | //"min-round" => 2466647, //integer 143 | //"max-round" => 2566647, //integer 144 | //"next" => "", //string - previous return {next-token} 145 | //"note-prefix" => "", //string 146 | //"rekey-to" => false, //boolean 147 | //"round" => 2566247, //integer 148 | //"sig-type" => "sig", //enum (sig, msig, lsig) 149 | //"tx-type" => "pay", //enum (pay, keyreg, acfg, axfer, afrz, appl) 150 | //"txid" => "", //string 151 | )); 152 | 153 | $return=$algorand_indexer->get("v2","transactions?".$query); 154 | */ 155 | 156 | #Lookup a single transaction. 157 | //$return=$algorand_indexer->get("v2","transactions","3TRNCPXPTSVOYCHY3MJJPF5WKBJ5SL2XOUSAFMJWY4IS5MA75P3Q"); 158 | 159 | 160 | #Full response with debug (json response) 161 | if(!empty($return)){ 162 | print_r($return); 163 | } 164 | #Only response array 165 | if(!empty($return['response'])){ 166 | print_r(json_decode($return['response'])); 167 | } 168 | #Only erros messages array 169 | if(!empty($return['message'])){ 170 | print_r(json_decode($return['message'])); 171 | } 172 | 173 | //For definitions: 174 | //https://developer.algorand.org/docs/reference/rest-apis/indexer/ 175 | 176 | ?> 177 | -------------------------------------------------------------------------------- /kmd.php: -------------------------------------------------------------------------------- 1 | debug(1); 8 | //algorand->setSSL('/home/felipe/certificate.cert'); //Optional 9 | 10 | #Just uncomment to try all avaliable functions 11 | 12 | #Get Versions 13 | //$return=$algorand_kmd->get("versions"); 14 | 15 | #swagger.json 16 | #$return=$algorand_kmd->get("swagger.json"); 17 | 18 | #Create Wallet 19 | /* 20 | $params['params']=array( 21 | "wallet_name" => "wallet1", 22 | "wallet_password" => "tests", 23 | "wallet_driver_name" => "sqlite", 24 | ); 25 | $return=$algorand_kmd->post("v1","wallet",$params); 26 | */ 27 | 28 | #Wallet List 29 | //$return=$algorand_kmd->get("v1","wallets"); 30 | 31 | #Wallet Init 32 | /* 33 | $params['params']=array( 34 | "wallet_id" => "a735ea8218798325f7f5e5c24fad608b", 35 | "wallet_password" => "tests", 36 | ); 37 | $return=$algorand_kmd->post("v1","wallet","init",$params); 38 | $return_array=json_decode($return['response']); 39 | $wallet_handle_token=$return_array->wallet_handle_token; 40 | */ 41 | 42 | #Wallet Info 43 | /* 44 | $params['params']=array( 45 | "wallet_handle_token" => $wallet_handle_token, 46 | ); 47 | $return=$algorand_kmd->post("v1","wallet","info",$params); 48 | */ 49 | 50 | #Wallet Rename 51 | /* 52 | $params['params']=array( 53 | "wallet_id" => "a735ea8218798325f7f5e5c24fad608b", 54 | "wallet_name" => "wallet2", 55 | "wallet_password" => "tests", 56 | ); 57 | $return=$algorand_kmd->post("v1","wallet","rename",$params); 58 | */ 59 | #Wallet Handle Token Release 60 | /* 61 | $params['params']=array( 62 | "wallet_handle_token" => $wallet_handle_token, 63 | ); 64 | $return=$algorand_kmd->post("v1","wallet","release",$params); 65 | */ 66 | 67 | #Wallet Handle Token Renew 68 | /* 69 | $params['params']=array( 70 | "wallet_handle_token" => $wallet_handle_token, 71 | ); 72 | $return=$algorand_kmd->post("v1","wallet","renew",$params); 73 | */ 74 | 75 | #Generate a key 76 | /* 77 | $params['params']=array( 78 | "display_mnemonic" => false, 79 | "wallet_handle_token" => $wallet_handle_token 80 | ); 81 | $return=$algorand_kmd->post("v1","key",$params); 82 | */ 83 | 84 | #Delete a key 85 | /* 86 | $params['params']=array( 87 | "address" => "IPGDIZRKKXBRYUW5YTIXYYU6ER4PIS4DSKEZTYLKROZQTTMANWWYYQW3RI", 88 | "wallet_handle_token" => $wallet_handle_token, 89 | "wallet_password" => "tests" 90 | ); 91 | $return=$algorand_kmd->delete("v1","key",$params); 92 | */ 93 | 94 | #Export a key 95 | /* 96 | $params['params']=array( 97 | "address" => "2QAXTOHQJQH6I4FM6RWUIISXKFJ2QA4NVWELMIJ5XAKZB4N4XIEX7F5KPU", 98 | "wallet_password" => "tests", 99 | "wallet_handle_token" => $wallet_handle_token 100 | ); 101 | $return=$algorand_kmd->post("v1","key","export",$params); 102 | 103 | $export=json_decode($return['response']); 104 | 105 | print_r($export); 106 | 107 | require_once 'sdk/algokey.php'; 108 | $algokey=new algokey; 109 | 110 | $words=$algokey->privateKeyToWords($export->private_key); 111 | 112 | print_r($words); 113 | */ 114 | 115 | #Import a key 116 | /* 117 | require_once 'sdk/algokey.php'; 118 | 119 | $algokey=new algokey; 120 | $words="ripple trap smoke crop name donor sun actor wreck disease mushroom sweet because phrase involve sail umbrella control swing uncle card phrase human absent marble"; 121 | $words_array=explode(" ",$words); 122 | 123 | $privatekey=$algokey->WordsToPrivateKey($words_array); 124 | 125 | $params['params']=array( 126 | "private_key" => $privatekey, 127 | "wallet_handle_token" => $wallet_handle_token 128 | ); 129 | $return=$algorand_kmd->post("v1","key","import",$params); 130 | */ 131 | #List keys in wallet 132 | /* 133 | $params['params']=array( 134 | "wallet_handle_token" => $wallet_handle_token 135 | ); 136 | $return=$algorand_kmd->post("v1","key","list",$params); 137 | */ 138 | 139 | #Master Key export 140 | /* 141 | $params['params']=array( 142 | "wallet_password" => "testes", 143 | "wallet_handle_token" => $wallet_handle_token 144 | ); 145 | $return=$algorand_kmd->post("v1","master-key","export",$params); 146 | */ 147 | 148 | #Delete a multisig 149 | /* 150 | $params['params']=array( 151 | "address" => "E6VH3C5XX57PT7LSZBETCJJRJRPZPSWAY5TEB7AWGEAQAWLCSM66TRULT4", 152 | "wallet_handle_token" => $wallet_handle_token, 153 | "wallet_password" => "testes" 154 | ); 155 | $return=$algorand_kmd->delete("v1","multisig",$params); 156 | */ 157 | 158 | #Export a multisig 159 | /* 160 | $params['params']=array( 161 | "address" => "E6VH3C5XX57PT7LSZBETCJJRJRPZPSWAY5TEB7AWGEAQAWLCSM66TRULT4", 162 | "wallet_handle_token" => $wallet_handle_token 163 | ); 164 | $return=$algorand_kmd->post("v1","multisig","export",$params); 165 | */ 166 | 167 | #Import a multisig 168 | /* 169 | $params['params']=array( 170 | "multisig_version" => "1", 171 | "pks" => array('eGTs9KCLHSUcf2JUIUV7EIkjH2dQQX3AyeGUDZ7MfM26O+vm8PcgP6HdoGItRDl/pwO/tiIWsrAzU+8VK/vm4w=='), 172 | "threshold" => 1, 173 | "wallet_handle_token" => $wallet_handle_token 174 | ); 175 | $return=$algorand_kmd->post("v1","multisig","import",$params); 176 | */ 177 | 178 | #List multisig in wallet 179 | /* 180 | $params['params']=array( 181 | "wallet_handle_token" => $wallet_handle_token 182 | ); 183 | $return=$algorand_kmd->post("v1","multisig","list",$params); 184 | */ 185 | 186 | #Sign a multisig transaction 187 | /* 188 | $params['params']=array( 189 | "partial_multisig" => array( 190 | "Subsigs" => array( 191 | "Key" => array(), 192 | "Sig" => array(), 193 | ), 194 | "Threshold" => 1, 195 | "Version" => 1 196 | ), 197 | "public_key" => array(''), 198 | "signer" => array(''), 199 | "transaction" => $algorand_transactions->encode(""), 200 | "wallet_handle_token" => $wallet_handle_token, 201 | "wallet_password" => "testes" 202 | ); 203 | $return=$algorand_kmd->post("v1","multisig","sign",$params); 204 | */ 205 | 206 | 207 | #Sign a program for a multisig account 208 | /* 209 | $params['params']=array( 210 | "address" => "", 211 | "data" => $algorand_transactions->encode(""), 212 | "partial_multisig" => array( 213 | "Subsigs" => array( 214 | "Key" => array(), 215 | "Sig" => array(), 216 | ), 217 | "Threshold" => 1, 218 | "Version" => 1 219 | ), 220 | "public_key" => array(''), 221 | "wallet_handle_token" => $wallet_handle_token, 222 | "wallet_password" => "testes" 223 | ); 224 | $return=$algorand_kmd->post("v1","multisig","signprogram",$params); 225 | */ 226 | 227 | 228 | #Sign program 229 | 230 | /* 231 | $params['params']=array( 232 | "address" => "", 233 | "data" => $algorand_transactions->encode(""), 234 | "wallet_handle_token" => $wallet_handle_token, 235 | "wallet_password" => "testes" 236 | ); 237 | $return=$algorand_kmd->post("v1","program","sign",$params); 238 | */ 239 | 240 | 241 | #Full response with debug (json response) 242 | if(!empty($return)){ 243 | print_r($return); 244 | } 245 | #Only response array 246 | if(!empty($return['response'])){ 247 | print_r(json_decode($return['response'])); 248 | } 249 | #Only erros messages array 250 | if(!empty($return['message'])){ 251 | print_r(json_decode($return['message'])); 252 | } 253 | 254 | //For definitions: 255 | //https://developer.algorand.org/docs/reference/rest-apis/kmd/ 256 | ?> 257 | -------------------------------------------------------------------------------- /sdk/_namespace_based/Algorand/algorand.php: -------------------------------------------------------------------------------- 1 | token = $token; 42 | $this->host = $host; 43 | $this->port = $port; 44 | $this->external = $external; 45 | $this->service = $service; 46 | 47 | if($this->external==true){ 48 | $this->protocol = 'https'; 49 | }else{ 50 | $this->protocol = 'http'; 51 | } 52 | $this->certificate = null; 53 | 54 | } 55 | 56 | public function debug($opt){ 57 | 58 | $this->debug=$opt; 59 | 60 | } 61 | 62 | public function SSL($certificate = null) { 63 | 64 | $this->protocol = 'https'; 65 | $this->certificate = $certificate; 66 | 67 | } 68 | 69 | public function __call($type, $params){ 70 | 71 | $this->status = null; 72 | $this->error = null; 73 | $this->raw = null; 74 | $this->response = null; 75 | 76 | // Parameters 77 | $params = array_values($params); 78 | 79 | // Request Type 80 | $type=strtoupper($type); 81 | 82 | 83 | // Method 84 | $method=$params[0]; 85 | 86 | $request=""; 87 | $request_body=""; 88 | $file=""; 89 | $transaction=""; 90 | 91 | // cURL 92 | $options = array( 93 | CURLOPT_HTTPAUTH => CURLAUTH_BASIC, 94 | CURLOPT_RETURNTRANSFER => true, 95 | CURLOPT_FOLLOWLOCATION => true, 96 | CURLOPT_MAXREDIRS => 10, 97 | ); 98 | 99 | if($this->external==true){ 100 | $options[CURLOPT_HTTPHEADER][]='x-api-key: '.$this->token; 101 | }else{ 102 | switch($this->service){ 103 | case "algod": 104 | $options[CURLOPT_HTTPHEADER][]='X-Algo-API-Token: '.$this->token; 105 | break; 106 | case "kmd": 107 | $options[CURLOPT_HTTPHEADER][]='X-KMD-API-Token: '.$this->token; 108 | break; 109 | case "indexer": 110 | $options[CURLOPT_HTTPHEADER][]='X-Indexer-API-Token: '.$this->token; 111 | break; 112 | } 113 | 114 | } 115 | 116 | $tp=count($params); 117 | $params_url=""; 118 | 119 | for($xp=0;$xp<$tp;++$xp){ 120 | 121 | if(is_array($params[$xp])==false AND $xp>0){ 122 | 123 | $params_url.="/".$params[$xp]; 124 | 125 | }else{ 126 | 127 | // Request 128 | if(!empty($params[$xp]['params'])){ $request = $params[$xp]['params']; } 129 | if(!empty($params[$xp]['body'])){ $request_body = $params[$xp]['body']; } 130 | 131 | // File 132 | if(!empty($params[$xp]['file'])){ $file=$params[$xp]['file']; } 133 | 134 | // Transaction 135 | if(!empty($params[$xp]['transaction'])){ $transaction=$params[$xp]['transaction']; } 136 | 137 | } 138 | 139 | } 140 | 141 | if($file!=""){ 142 | if(file_exists($file)){ 143 | $options[CURLOPT_HTTPHEADER][]='Content-type: application/x-binary'; 144 | $request_body = file_get_contents($file); 145 | } 146 | } 147 | 148 | if($transaction!=""){ 149 | if($this->external==true){ 150 | $options[CURLOPT_HTTPHEADER][]='Content-type: application/x-binary'; 151 | } 152 | $request_body = $transaction; 153 | } 154 | 155 | 156 | if($type=="POST"){ 157 | 158 | $options[CURLOPT_POST]=true; 159 | if(!empty($request_body)){ 160 | $options[CURLOPT_POSTFIELDS]=$request_body; 161 | }else{ 162 | $options[CURLOPT_POSTFIELDS]=json_encode($request); 163 | } 164 | 165 | } 166 | 167 | if($type=="DELETE"){ 168 | 169 | $options[CURLOPT_CUSTOMREQUEST]="DELETE"; 170 | if(!empty($request_body)){ 171 | $options[CURLOPT_POSTFIELDS]=$request_body; 172 | }else{ 173 | if(is_array($request)){ 174 | $options[CURLOPT_POSTFIELDS]=json_encode($request); 175 | } 176 | } 177 | 178 | } 179 | 180 | if($this->external==true){ 181 | $url=$this->protocol."://".$this->host."/".$method.$params_url; 182 | }else{ 183 | $url=$this->protocol."://".$this->host.":".$this->port."/".$method.$params_url; 184 | } 185 | $curl = curl_init($url); 186 | 187 | 188 | if(ini_get('open_basedir')) { 189 | unset($options[CURLOPT_FOLLOWLOCATION]); 190 | } 191 | 192 | if($this->protocol == 'https') { 193 | 194 | if ($this->certificate!="") { 195 | $options[CURLOPT_CAINFO] = $this->certificate; 196 | $options[CURLOPT_CAPATH] = DIRNAME($this->certificate); 197 | } else { 198 | $options[CURLOPT_SSL_VERIFYPEER] = false; 199 | } 200 | 201 | } 202 | 203 | 204 | curl_setopt_array($curl, $options); 205 | 206 | // Execute 207 | $this->raw = curl_exec($curl); 208 | 209 | // Get Status 210 | $this->status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 211 | 212 | //Json decode 213 | $this->response = $this->raw; 214 | 215 | // Filter Error 216 | $curl_error = curl_error($curl); 217 | 218 | curl_close($curl); 219 | 220 | if($curl_error!="") { 221 | $this->error = $curl_error; 222 | } 223 | 224 | $return=""; 225 | 226 | if ($this->status != 200) { 227 | 228 | switch ($this->status) { 229 | case 400: 230 | $this->error = 'BAD REQUEST'; 231 | break; 232 | case 401: 233 | $this->error = 'UNAUTHORIZED'; 234 | break; 235 | case 403: 236 | $this->error = 'FORBIDDEN'; 237 | break; 238 | case 404: 239 | $this->error = 'NOT FOUND'; 240 | break; 241 | case 404: 242 | $this->error = 'NOT ALLOWED'; 243 | break; 244 | } 245 | 246 | $return = array( 247 | "code" => $this->status, 248 | "message" => $this->response, 249 | ); 250 | 251 | }else{ 252 | 253 | $return = array( 254 | "code" => $this->status, 255 | "response" => $this->response, 256 | ); 257 | 258 | } 259 | 260 | if($this->debug==1){ 261 | 262 | $return['DEBUG']="ON"; 263 | $return['url']=$url; 264 | $return['options']=$options; 265 | 266 | } 267 | return $return; 268 | 269 | } 270 | } 271 | ?> 272 | -------------------------------------------------------------------------------- /sdk/_namespace_based/Algorand/b32.php: -------------------------------------------------------------------------------- 1 | 0b00000,'A' => 0b00000,'B' => 0b00001,'C' => 0b00010,'D' => 0b00011,'E' => 0b00100,'F' => 0b00101,'G' => 0b00110,'H' => 0b00111,'I' => 0b01000,'J' => 0b01001,'K' => 0b01010,'L' => 0b01011,'M' => 0b01100,'N' => 0b01101,'O' => 0b01110,'P' => 0b01111,'Q' => 0b10000,'R' => 0b10001,'S' => 0b10010,'T' => 0b10011,'U' => 0b10100,'V' => 0b10101,'W' => 0b10110,'X' => 0b10111,'Y' => 0b11000,'Z' => 0b11001,'2' => 0b11010,'3' => 0b11011,'4' => 0b11100,'5' => 0b11101,'6' => 0b11110,'7' => 0b11111,]; 11 | 12 | public static function encode($string) { 13 | 14 | if ('' === $string) { return ''; } 15 | 16 | $encoded = ''; 17 | 18 | $n = $bitLen = $val = 0; 19 | 20 | $len = strlen($string); 21 | 22 | $string .= str_repeat(chr(0), 4); 23 | 24 | $chars = (array) unpack('C*', $string, 0); 25 | 26 | while ($n < $len || 0 !== $bitLen) { 27 | 28 | if ($bitLen < 5) { $val = $val << 8; $bitLen += 8; $n++; $val += $chars[$n]; } 29 | 30 | $shift = $bitLen - 5; $encoded .= ($n - (int)($bitLen > 8) > $len && 0 == $val) ? '=' : static::ALBT[$val >> $shift]; $val = $val & ((1 << $shift) - 1); $bitLen -= 5; 31 | 32 | } 33 | 34 | return $encoded; 35 | } 36 | 37 | public static function decode($base32String) { 38 | 39 | 40 | $base32String = strtoupper($base32String); $base32String = preg_replace(static::B2HEXP, '', $base32String); 41 | 42 | if ('' === $base32String || null === $base32String) { return ''; } 43 | 44 | $decoded = ''; $len = strlen($base32String)-6; $n = 0; $bitLen = 5; $val = static::MAPP[$base32String[0]]; 45 | 46 | while ($n < $len) { 47 | 48 | if ($bitLen < 8) { $val = $val << 5; $bitLen += 5; $n++; $pentet = $base32String[$n] ?? '='; 49 | 50 | if ('=' === $pentet) { $n = $len; } 51 | 52 | $val += static::MAPP[$pentet]; 53 | 54 | continue; 55 | 56 | } 57 | 58 | $shift = $bitLen - 8; $decoded .= chr($val >> $shift); $val = $val & ((1 << $shift) - 1); $bitLen -= 8; 59 | 60 | } 61 | return $decoded; 62 | } 63 | } 64 | ?> 65 | -------------------------------------------------------------------------------- /sdk/_namespace_based/Algorand/msgpack.php: -------------------------------------------------------------------------------- 1 | pInt($value); 19 | } 20 | 21 | if (is_string($value)) { 22 | if ('' === $value) { 23 | return $this->fFStr || $this->fDStrBin ? "\xa0" : "\xc4\x00"; 24 | } 25 | if ($this->fFStr) { 26 | return $this->pStr($value); 27 | } 28 | if ($this->fDStrBin && preg_match(self::UTF8_REGEX, $value)) { 29 | return $this->pStr($value); 30 | } 31 | 32 | return $this->pBin($value); 33 | } 34 | 35 | if (is_array($value)) { 36 | 37 | if ([] === $value) { 38 | return $this->fDArrMap || $this->fFArr ? "\x90" : "\x80"; 39 | } 40 | 41 | if ($this->fDArrMap) { 42 | 43 | if (!isset($value[0]) && !array_key_exists(0, $value)) { 44 | return $this->pMap($value); 45 | } 46 | 47 | return array_values($value) === $value 48 | ? $this->pArray($value) 49 | : $this->pMap($value); 50 | } 51 | 52 | return $this->fFArr ? $this->pArray($value) : $this->pMap($value); 53 | } 54 | 55 | if (is_null($value)) { 56 | return "\xc0"; 57 | } 58 | 59 | if (is_bool($value)) { 60 | return $value ? "\xc3" : "\xc2"; 61 | } 62 | 63 | if (is_float($value)) { 64 | return $this->pFloat($value); 65 | } 66 | 67 | if ($this->tmrs) { 68 | foreach ($this->tmrs as $transformer) { 69 | if (!is_null($packed = $transformer->p($this, $value))) { 70 | return $packed; 71 | } 72 | } 73 | } 74 | 75 | if ($value instanceof Ext) { 76 | return $this->pExt($value->type, $value->data); 77 | } 78 | } 79 | 80 | public function pNil(){ 81 | return "\xc0"; 82 | } 83 | 84 | public function pBool($bool){ 85 | return $bool ? "\xc3" : "\xc2"; 86 | } 87 | 88 | public function pInt($int){ 89 | 90 | if ($int >= 0) { 91 | 92 | if ($int <= 0x7f) { 93 | return chr($int); 94 | } 95 | 96 | if ($int <= 0xff) { 97 | return "\xcc".chr($int); 98 | } 99 | 100 | if ($int <= 0xffff) { 101 | return "\xcd".chr($int >> 8).chr($int); 102 | } 103 | 104 | if ($int <= 0xffffffff) { 105 | return pack('CN', 0xce, $int); 106 | } 107 | 108 | return pack('CJ', 0xcf, $int); 109 | } 110 | 111 | if ($int >= -0x20) { 112 | return chr(0xe0 | $int); 113 | } 114 | 115 | if ($int >= -0x80) { 116 | return "\xd0".chr($int); 117 | } 118 | 119 | if ($int >= -0x8000) { 120 | return "\xd1".chr($int >> 8).chr($int); 121 | } 122 | 123 | if ($int >= -0x80000000) { 124 | return pack('CN', 0xd2, $int); 125 | } 126 | 127 | return pack('CJ', 0xd3, $int); 128 | } 129 | 130 | public function pFloat($float){ 131 | return $this->fFF32 132 | ? "\xca".pack('G', $float) 133 | : "\xcb".pack('E', $float); 134 | } 135 | 136 | public function pFloat32($float){ 137 | return "\xca".pack('G', $float); 138 | } 139 | 140 | public function pFloat64($float){ 141 | return "\xcb".pack('E', $float); 142 | } 143 | 144 | public function pStr($str){ 145 | $length = strlen($str); 146 | 147 | if ($length < 32) { 148 | return chr(0xa0 | $length).$str; 149 | } 150 | 151 | if ($length <= 0xff) { 152 | return "\xd9".chr($length).$str; 153 | } 154 | 155 | if ($length <= 0xffff) { 156 | return "\xda".chr($length >> 8).chr($length).$str; 157 | } 158 | 159 | return pack('CN', 0xdb, $length).$str; 160 | 161 | } 162 | 163 | public function pBin($str){ 164 | 165 | $length = strlen($str); 166 | 167 | if ($length <= 0xff) { 168 | return "\xc4".\chr($length).$str; 169 | } 170 | 171 | if ($length <= 0xffff) { 172 | return "\xc5".chr($length >> 8).chr($length).$str; 173 | } 174 | 175 | return pack('CN', 0xc6, $length).$str; 176 | 177 | } 178 | 179 | public function pArray($array){ 180 | 181 | $data = $this->pArrayHeader(count($array)); 182 | 183 | foreach ($array as $val) { 184 | $data .= $this->p($val); 185 | } 186 | 187 | return $data; 188 | 189 | } 190 | 191 | public function pArrayHeader($size){ 192 | 193 | if ($size <= 0xf) { 194 | 195 | return chr(0x90 | $size); 196 | 197 | } 198 | 199 | if ($size <= 0xffff) { 200 | 201 | return "\xdc".chr($size >> 8).chr($size); 202 | 203 | } 204 | 205 | return pack('CN', 0xdd, $size); 206 | 207 | } 208 | 209 | public function pMap($map){ 210 | $data = $this->pMapHeader(count($map)); 211 | 212 | if ($this->fFStr) { 213 | 214 | foreach ($map as $key => $val) { 215 | 216 | $data .= is_string($key) ? $this->pStr($key) : $this->pInt($key); 217 | $data .= $this->p($val); 218 | 219 | } 220 | 221 | return $data; 222 | } 223 | 224 | if ($this->fDStrBin) { 225 | foreach ($map as $key => $val) { 226 | 227 | $data .= is_string($key) 228 | ? (preg_match(self::UTF8_REGEX, $key) ? $this->pStr($key) : $this->pBin($key)) 229 | : $this->pInt($key); 230 | 231 | $data .= $this->p($val); 232 | } 233 | 234 | return $data; 235 | } 236 | 237 | foreach ($map as $key => $val) { 238 | 239 | $data .= is_string($key) ? $this->pBin($key) : $this->pInt($key); 240 | 241 | $data .= $this->p($val); 242 | } 243 | 244 | return $data; 245 | } 246 | 247 | public function pMapHeader($size){ 248 | 249 | if ($size <= 0xf) { 250 | 251 | return chr(0x80 | $size); 252 | 253 | } 254 | 255 | if ($size <= 0xffff) { 256 | 257 | return "\xde".chr($size >> 8).chr($size); 258 | 259 | } 260 | 261 | return pack('CN', 0xdf, $size); 262 | 263 | } 264 | 265 | public function pExt($type, $data){ 266 | 267 | $length = strlen($data); 268 | 269 | switch ($length) { 270 | 271 | case 1: return "\xd4".chr($type).$data; 272 | case 2: return "\xd5".chr($type).$data; 273 | case 4: return "\xd6".chr($type).$data; 274 | case 8: return "\xd7".chr($type).$data; 275 | case 16: return "\xd8".chr($type).$data; 276 | 277 | } 278 | 279 | if ($length <= 0xff) { 280 | 281 | return "\xc7".chr($length).chr($type).$data; 282 | 283 | } 284 | 285 | if ($length <= 0xffff) { 286 | 287 | return pack('CnC', 0xc8, $length, $type).$data; 288 | 289 | } 290 | 291 | return pack('CNC', 0xc9, $length, $type).$data; 292 | } 293 | } 294 | ?> 295 | -------------------------------------------------------------------------------- /sdk/_namespace_based/Algorand/transactions.php: -------------------------------------------------------------------------------- 1 | pBin(utf8_encode(strval($out['txn']['note']))); } 27 | 28 | if(!empty($out['txn']['gp'])) { $out['txn']['gp']=strval($out['txn']['gp']); } 29 | if(!empty($out['txn']['rekey'])) { $out['txn']['rekey']=b32::decode($out['txn']['rekey']); } 30 | if(!empty($out['txn']['type'])) { $out['txn']['type']=strval($out['txn']['type']); } 31 | if(!empty($out['txn']['rcv'])) { $out['txn']['rcv']=strval($out['txn']['rcv']); } 32 | if(!empty($out['txn']['amt'])) { $out['txn']['amt']=intval($out['txn']['amt']); } 33 | if(!empty($out['txn']['aamt'])) { $out['txn']['aamt']=intval($out['txn']['aamt']); } 34 | if(!empty($out['txn']['close'])) { $out['txn']['close']=strval($out['txn']['close']); } 35 | if(!empty($out['txn']['xaid'])) { $out['txn']['xaid']=intval($out['txn']['xaid']); } 36 | if(!empty($out['txn']['apid'])) { $out['txn']['apid']=intval($out['txn']['apid']); } 37 | if(!empty($out['txn']['faid'])) { $out['txn']['faid']=intval($out['txn']['faid']); } 38 | if(!empty($out['txn']['caid'])) { $out['txn']['caid']=intval($out['txn']['caid']); } 39 | 40 | if(!empty($out['txn']['gh'])) { $out['txn']['gh']=base64_decode($out['txn']['gh']); } 41 | if(!empty($out['txn']['snd'])) { $out['txn']['snd']=b32::decode($out['txn']['snd']); } 42 | if(!empty($out['txn']['rcv'])) { $out['txn']['rcv']=b32::decode($out['txn']['rcv']); } 43 | if(!empty($out['txn']['close'])) { $out['txn']['close']=b32::decode($out['txn']['close']); } 44 | if(!empty($out['txn']['aclose'])) { $out['txn']['aclose']=b32::decode($out['txn']['aclose']); } 45 | if(!empty($out['txn']['selkey'])) { $out['txn']['selkey']=b32::decode($out['txn']['selkey']); } 46 | if(!empty($out['txn']['votekey'])) { $out['txn']['votekey']=b32::decode($out['txn']['votekey']); } 47 | if(!empty($out['txn']['arcv'])) { $out['txn']['arcv']=b32::decode($out['txn']['arcv']); } 48 | if(!empty($out['txn']['asnd'])) { $out['txn']['asnd']=b32::decode($out['txn']['asnd']); } 49 | if(!empty($out['txn']['fadd'])) { $out['txn']['fadd']=b32::decode($out['txn']['fadd']); } 50 | if(!empty($out['txn']['apat'])) { $out['txn']['apat']=b32::decode($out['txn']['apat']); } 51 | if(!empty($out['txn']['apap'])) { $out['txn']['apap']=b32::decode($out['txn']['apap']); } 52 | if(!empty($out['txn']['apsu'])) { $out['txn']['apsu']=b32::decode($out['txn']['apsu']); } 53 | if(!empty($out['txn']['apfa'])) { $out['txn']['apfa']=b32::decode($out['txn']['apfa']); } 54 | if(!empty($out['txn']['apas'])) { $out['txn']['apas']=b32::decode($out['txn']['apas']); } 55 | 56 | if(!empty($out['txn']['apar']['am'])) { $out['txn']['apar']['am']=b32::decode($out['txn']['apar']['am']); } 57 | if(!empty($out['txn']['apar']['c'])) { $out['txn']['apar']['c']=b32::decode($out['txn']['apar']['c']); } 58 | if(!empty($out['txn']['apar']['f'])) { $out['txn']['apar']['f']=b32::decode($out['txn']['apar']['f']); } 59 | if(!empty($out['txn']['apar']['m'])) { $out['txn']['apar']['m']=b32::decode($out['txn']['apar']['m']); } 60 | if(!empty($out['txn']['apar']['r'])) { $out['txn']['apar']['r']=b32::decode($out['txn']['apar']['r']); } 61 | if(!empty($out['txn']['apar']['dc'])) { $out['txn']['apar']['dc']=intval($out['txn']['apar']['dc']); } 62 | if(!empty($out['txn']['apar']['t'])) { $out['txn']['apar']['t']=intval($out['txn']['apar']['t']); } 63 | 64 | if($signature!=""){ 65 | $out=array( 66 | "sig" => $signature, 67 | "txn" => $out['txn'], 68 | ); 69 | $out=$msgpack->p($out); 70 | }else{ 71 | $out=$msgpack->p($out['txn']); 72 | } 73 | 74 | $out=bin2hex($out); 75 | $out=hex2bin($out); 76 | 77 | if($opt_msgpack==false){ 78 | $out=base64_encode($out); 79 | } 80 | return $out; 81 | } 82 | 83 | public function pk_encode($array){ 84 | $out=$array; 85 | $out=b32::decode($out); 86 | $out=base64_encode($out); 87 | return $out; 88 | } 89 | 90 | public function groupid($transactions){ 91 | 92 | $msgpack=new msgpack; 93 | $txn=""; 94 | $total=count($transactions); 95 | $txids=array(); 96 | for($x=0; $x<$total; $x++){ 97 | $raw_txn=$this->encode($transactions[$x],true); 98 | $raw_txn=hash('sha512/256',"TX".$raw_txn,true); 99 | $txids[$x]=$raw_txn; 100 | } 101 | 102 | $group_list=array( 103 | 'txlist' => $txids, 104 | ); 105 | 106 | $encoded=$msgpack->p($group_list); 107 | $gid = hash('sha512/256',"TG".$encoded,true); 108 | 109 | return $gid; 110 | } 111 | 112 | } 113 | ?> 114 | -------------------------------------------------------------------------------- /sdk/codeigniter setup/app/Algorand/b32.php: -------------------------------------------------------------------------------- 1 | 0b00000,'A' => 0b00000,'B' => 0b00001,'C' => 0b00010,'D' => 0b00011,'E' => 0b00100,'F' => 0b00101,'G' => 0b00110,'H' => 0b00111,'I' => 0b01000,'J' => 0b01001,'K' => 0b01010,'L' => 0b01011,'M' => 0b01100,'N' => 0b01101,'O' => 0b01110,'P' => 0b01111,'Q' => 0b10000,'R' => 0b10001,'S' => 0b10010,'T' => 0b10011,'U' => 0b10100,'V' => 0b10101,'W' => 0b10110,'X' => 0b10111,'Y' => 0b11000,'Z' => 0b11001,'2' => 0b11010,'3' => 0b11011,'4' => 0b11100,'5' => 0b11101,'6' => 0b11110,'7' => 0b11111,]; 11 | 12 | public static function encode($string) { 13 | 14 | if ('' === $string) { return ''; } 15 | 16 | $encoded = ''; 17 | 18 | $n = $bitLen = $val = 0; 19 | 20 | $len = strlen($string); 21 | 22 | $string .= str_repeat(chr(0), 4); 23 | 24 | $chars = (array) unpack('C*', $string, 0); 25 | 26 | while ($n < $len || 0 !== $bitLen) { 27 | 28 | if ($bitLen < 5) { $val = $val << 8; $bitLen += 8; $n++; $val += $chars[$n]; } 29 | 30 | $shift = $bitLen - 5; $encoded .= ($n - (int)($bitLen > 8) > $len && 0 == $val) ? '=' : static::ALBT[$val >> $shift]; $val = $val & ((1 << $shift) - 1); $bitLen -= 5; 31 | 32 | } 33 | 34 | return $encoded; 35 | } 36 | 37 | public static function decode($base32String) { 38 | 39 | 40 | $base32String = strtoupper($base32String); $base32String = preg_replace(static::B2HEXP, '', $base32String); 41 | 42 | if ('' === $base32String || null === $base32String) { return ''; } 43 | 44 | $decoded = ''; $len = strlen($base32String)-6; $n = 0; $bitLen = 5; $val = static::MAPP[$base32String[0]]; 45 | 46 | while ($n < $len) { 47 | 48 | if ($bitLen < 8) { $val = $val << 5; $bitLen += 5; $n++; $pentet = $base32String[$n] ?? '='; 49 | 50 | if ('=' === $pentet) { $n = $len; } 51 | 52 | $val += static::MAPP[$pentet]; 53 | 54 | continue; 55 | 56 | } 57 | 58 | $shift = $bitLen - 8; $decoded .= chr($val >> $shift); $val = $val & ((1 << $shift) - 1); $bitLen -= 8; 59 | 60 | } 61 | return $decoded; 62 | } 63 | } 64 | ?> 65 | -------------------------------------------------------------------------------- /sdk/codeigniter setup/app/Algorand/msgpack.php: -------------------------------------------------------------------------------- 1 | pInt($value); 19 | } 20 | 21 | if (is_string($value)) { 22 | if ('' === $value) { 23 | return $this->fFStr || $this->fDStrBin ? "\xa0" : "\xc4\x00"; 24 | } 25 | if ($this->fFStr) { 26 | return $this->pStr($value); 27 | } 28 | if ($this->fDStrBin && preg_match(self::UTF8_REGEX, $value)) { 29 | return $this->pStr($value); 30 | } 31 | 32 | return $this->pBin($value); 33 | } 34 | 35 | if (is_array($value)) { 36 | 37 | if ([] === $value) { 38 | return $this->fDArrMap || $this->fFArr ? "\x90" : "\x80"; 39 | } 40 | 41 | if ($this->fDArrMap) { 42 | 43 | if (!isset($value[0]) && !array_key_exists(0, $value)) { 44 | return $this->pMap($value); 45 | } 46 | 47 | return array_values($value) === $value 48 | ? $this->pArray($value) 49 | : $this->pMap($value); 50 | } 51 | 52 | return $this->fFArr ? $this->pArray($value) : $this->pMap($value); 53 | } 54 | 55 | if (is_null($value)) { 56 | return "\xc0"; 57 | } 58 | 59 | if (is_bool($value)) { 60 | return $value ? "\xc3" : "\xc2"; 61 | } 62 | 63 | if (is_float($value)) { 64 | return $this->pFloat($value); 65 | } 66 | 67 | if ($this->tmrs) { 68 | foreach ($this->tmrs as $transformer) { 69 | if (!is_null($packed = $transformer->p($this, $value))) { 70 | return $packed; 71 | } 72 | } 73 | } 74 | 75 | if ($value instanceof Ext) { 76 | return $this->pExt($value->type, $value->data); 77 | } 78 | } 79 | 80 | public function pNil(){ 81 | return "\xc0"; 82 | } 83 | 84 | public function pBool($bool){ 85 | return $bool ? "\xc3" : "\xc2"; 86 | } 87 | 88 | public function pInt($int){ 89 | 90 | if ($int >= 0) { 91 | 92 | if ($int <= 0x7f) { 93 | return chr($int); 94 | } 95 | 96 | if ($int <= 0xff) { 97 | return "\xcc".chr($int); 98 | } 99 | 100 | if ($int <= 0xffff) { 101 | return "\xcd".chr($int >> 8).chr($int); 102 | } 103 | 104 | if ($int <= 0xffffffff) { 105 | return pack('CN', 0xce, $int); 106 | } 107 | 108 | return pack('CJ', 0xcf, $int); 109 | } 110 | 111 | if ($int >= -0x20) { 112 | return chr(0xe0 | $int); 113 | } 114 | 115 | if ($int >= -0x80) { 116 | return "\xd0".chr($int); 117 | } 118 | 119 | if ($int >= -0x8000) { 120 | return "\xd1".chr($int >> 8).chr($int); 121 | } 122 | 123 | if ($int >= -0x80000000) { 124 | return pack('CN', 0xd2, $int); 125 | } 126 | 127 | return pack('CJ', 0xd3, $int); 128 | } 129 | 130 | public function pFloat($float){ 131 | return $this->fFF32 132 | ? "\xca".pack('G', $float) 133 | : "\xcb".pack('E', $float); 134 | } 135 | 136 | public function pFloat32($float){ 137 | return "\xca".pack('G', $float); 138 | } 139 | 140 | public function pFloat64($float){ 141 | return "\xcb".pack('E', $float); 142 | } 143 | 144 | public function pStr($str){ 145 | $length = strlen($str); 146 | 147 | if ($length < 32) { 148 | return chr(0xa0 | $length).$str; 149 | } 150 | 151 | if ($length <= 0xff) { 152 | return "\xd9".chr($length).$str; 153 | } 154 | 155 | if ($length <= 0xffff) { 156 | return "\xda".chr($length >> 8).chr($length).$str; 157 | } 158 | 159 | return pack('CN', 0xdb, $length).$str; 160 | 161 | } 162 | 163 | public function pBin($str){ 164 | 165 | $length = strlen($str); 166 | 167 | if ($length <= 0xff) { 168 | return "\xc4".\chr($length).$str; 169 | } 170 | 171 | if ($length <= 0xffff) { 172 | return "\xc5".chr($length >> 8).chr($length).$str; 173 | } 174 | 175 | return pack('CN', 0xc6, $length).$str; 176 | 177 | } 178 | 179 | public function pArray($array){ 180 | 181 | $data = $this->pArrayHeader(count($array)); 182 | 183 | foreach ($array as $val) { 184 | $data .= $this->p($val); 185 | } 186 | 187 | return $data; 188 | 189 | } 190 | 191 | public function pArrayHeader($size){ 192 | 193 | if ($size <= 0xf) { 194 | 195 | return chr(0x90 | $size); 196 | 197 | } 198 | 199 | if ($size <= 0xffff) { 200 | 201 | return "\xdc".chr($size >> 8).chr($size); 202 | 203 | } 204 | 205 | return pack('CN', 0xdd, $size); 206 | 207 | } 208 | 209 | public function pMap($map){ 210 | $data = $this->pMapHeader(count($map)); 211 | 212 | if ($this->fFStr) { 213 | 214 | foreach ($map as $key => $val) { 215 | 216 | $data .= is_string($key) ? $this->pStr($key) : $this->pInt($key); 217 | $data .= $this->p($val); 218 | 219 | } 220 | 221 | return $data; 222 | } 223 | 224 | if ($this->fDStrBin) { 225 | foreach ($map as $key => $val) { 226 | 227 | $data .= is_string($key) 228 | ? (preg_match(self::UTF8_REGEX, $key) ? $this->pStr($key) : $this->pBin($key)) 229 | : $this->pInt($key); 230 | 231 | $data .= $this->p($val); 232 | } 233 | 234 | return $data; 235 | } 236 | 237 | foreach ($map as $key => $val) { 238 | 239 | $data .= is_string($key) ? $this->pBin($key) : $this->pInt($key); 240 | 241 | $data .= $this->p($val); 242 | } 243 | 244 | return $data; 245 | } 246 | 247 | public function pMapHeader($size){ 248 | 249 | if ($size <= 0xf) { 250 | 251 | return chr(0x80 | $size); 252 | 253 | } 254 | 255 | if ($size <= 0xffff) { 256 | 257 | return "\xde".chr($size >> 8).chr($size); 258 | 259 | } 260 | 261 | return pack('CN', 0xdf, $size); 262 | 263 | } 264 | 265 | public function pExt($type, $data){ 266 | 267 | $length = strlen($data); 268 | 269 | switch ($length) { 270 | 271 | case 1: return "\xd4".chr($type).$data; 272 | case 2: return "\xd5".chr($type).$data; 273 | case 4: return "\xd6".chr($type).$data; 274 | case 8: return "\xd7".chr($type).$data; 275 | case 16: return "\xd8".chr($type).$data; 276 | 277 | } 278 | 279 | if ($length <= 0xff) { 280 | 281 | return "\xc7".chr($length).chr($type).$data; 282 | 283 | } 284 | 285 | if ($length <= 0xffff) { 286 | 287 | return pack('CnC', 0xc8, $length, $type).$data; 288 | 289 | } 290 | 291 | return pack('CNC', 0xc9, $length, $type).$data; 292 | } 293 | } 294 | ?> 295 | -------------------------------------------------------------------------------- /sdk/codeigniter setup/app/Algorand/transactions.php: -------------------------------------------------------------------------------- 1 | pBin(utf8_encode(strval($out['txn']['note']))); } 26 | 27 | if(!empty($out['txn']['gp'])) { $out['txn']['gp']=strval($out['txn']['gp']); } 28 | if(!empty($out['txn']['rekey'])) { $out['txn']['rekey']=b32::decode($out['txn']['rekey']); } 29 | if(!empty($out['txn']['type'])) { $out['txn']['type']=strval($out['txn']['type']); } 30 | if(!empty($out['txn']['rcv'])) { $out['txn']['rcv']=strval($out['txn']['rcv']); } 31 | if(!empty($out['txn']['amt'])) { $out['txn']['amt']=intval($out['txn']['amt']); } 32 | if(!empty($out['txn']['aamt'])) { $out['txn']['aamt']=intval($out['txn']['aamt']); } 33 | if(!empty($out['txn']['close'])) { $out['txn']['close']=strval($out['txn']['close']); } 34 | if(!empty($out['txn']['xaid'])) { $out['txn']['xaid']=intval($out['txn']['xaid']); } 35 | if(!empty($out['txn']['apid'])) { $out['txn']['apid']=intval($out['txn']['apid']); } 36 | if(!empty($out['txn']['faid'])) { $out['txn']['faid']=intval($out['txn']['faid']); } 37 | if(!empty($out['txn']['caid'])) { $out['txn']['caid']=intval($out['txn']['caid']); } 38 | 39 | if(!empty($out['txn']['gh'])) { $out['txn']['gh']=base64_decode($out['txn']['gh']); } 40 | if(!empty($out['txn']['snd'])) { $out['txn']['snd']=b32::decode($out['txn']['snd']); } 41 | if(!empty($out['txn']['rcv'])) { $out['txn']['rcv']=b32::decode($out['txn']['rcv']); } 42 | if(!empty($out['txn']['close'])) { $out['txn']['close']=b32::decode($out['txn']['close']); } 43 | if(!empty($out['txn']['aclose'])) { $out['txn']['aclose']=b32::decode($out['txn']['aclose']); } 44 | if(!empty($out['txn']['selkey'])) { $out['txn']['selkey']=b32::decode($out['txn']['selkey']); } 45 | if(!empty($out['txn']['votekey'])) { $out['txn']['votekey']=b32::decode($out['txn']['votekey']); } 46 | if(!empty($out['txn']['arcv'])) { $out['txn']['arcv']=b32::decode($out['txn']['arcv']); } 47 | if(!empty($out['txn']['asnd'])) { $out['txn']['asnd']=b32::decode($out['txn']['asnd']); } 48 | if(!empty($out['txn']['fadd'])) { $out['txn']['fadd']=b32::decode($out['txn']['fadd']); } 49 | if(!empty($out['txn']['apat'])) { $out['txn']['apat']=b32::decode($out['txn']['apat']); } 50 | if(!empty($out['txn']['apap'])) { $out['txn']['apap']=b32::decode($out['txn']['apap']); } 51 | if(!empty($out['txn']['apsu'])) { $out['txn']['apsu']=b32::decode($out['txn']['apsu']); } 52 | if(!empty($out['txn']['apfa'])) { $out['txn']['apfa']=b32::decode($out['txn']['apfa']); } 53 | if(!empty($out['txn']['apas'])) { $out['txn']['apas']=b32::decode($out['txn']['apas']); } 54 | 55 | if(!empty($out['txn']['apar']['am'])) { $out['txn']['apar']['am']=b32::decode($out['txn']['apar']['am']); } 56 | if(!empty($out['txn']['apar']['c'])) { $out['txn']['apar']['c']=b32::decode($out['txn']['apar']['c']); } 57 | if(!empty($out['txn']['apar']['f'])) { $out['txn']['apar']['f']=b32::decode($out['txn']['apar']['f']); } 58 | if(!empty($out['txn']['apar']['m'])) { $out['txn']['apar']['m']=b32::decode($out['txn']['apar']['m']); } 59 | if(!empty($out['txn']['apar']['r'])) { $out['txn']['apar']['r']=b32::decode($out['txn']['apar']['r']); } 60 | if(!empty($out['txn']['apar']['dc'])) { $out['txn']['apar']['dc']=intval($out['txn']['apar']['dc']); } 61 | if(!empty($out['txn']['apar']['t'])) { $out['txn']['apar']['t']=intval($out['txn']['apar']['t']); } 62 | 63 | if($signature!=""){ 64 | $out=array( 65 | "sig" => $signature, 66 | "txn" => $out['txn'], 67 | ); 68 | $out=$msgpack->p($out); 69 | }else{ 70 | $out=$msgpack->p($out['txn']); 71 | } 72 | 73 | $out=bin2hex($out); 74 | $out=hex2bin($out); 75 | 76 | if($opt_msgpack==false){ 77 | $out=base64_encode($out); 78 | } 79 | return $out; 80 | } 81 | 82 | public function pk_encode($array){ 83 | $out=$array; 84 | $out=b32::decode($out); 85 | $out=base64_encode($out); 86 | return $out; 87 | } 88 | 89 | public function groupid($transactions){ 90 | 91 | $msgpack=new msgpack; 92 | $txn=""; 93 | $total=count($transactions); 94 | $txids=array(); 95 | for($x=0; $x<$total; $x++){ 96 | $raw_txn=$this->encode($transactions[$x],true); 97 | $raw_txn=hash('sha512/256',"TX".$raw_txn,true); 98 | $txids[$x]=$raw_txn; 99 | } 100 | 101 | $group_list=array( 102 | 'txlist' => $txids, 103 | ); 104 | 105 | $encoded=$msgpack->p($group_list); 106 | $gid = hash('sha512/256',"TG".$encoded,true); 107 | 108 | return $gid; 109 | } 110 | 111 | } 112 | ?> 113 | -------------------------------------------------------------------------------- /sdk/codeigniter setup/app/Config/Routes.php: -------------------------------------------------------------------------------- 1 | setDefaultNamespace('App\Controllers'); 21 | $routes->setDefaultController('Home'); 22 | $routes->setDefaultMethod('index'); 23 | $routes->setTranslateURIDashes(false); 24 | $routes->set404Override(); 25 | $routes->setAutoRoute(true); 26 | 27 | /* 28 | * -------------------------------------------------------------------- 29 | * Route Definitions 30 | * -------------------------------------------------------------------- 31 | */ 32 | 33 | // We get a performance increase by specifying the default 34 | // route since we don't have to scan directories. 35 | $routes->get('/', 'Home::index'); 36 | $routes->get('/algod', 'AlgodController::index'); 37 | $routes->get('/kmd', 'KmdController::index'); 38 | $routes->get('/indexer', 'IndexerController::index'); 39 | /* 40 | * -------------------------------------------------------------------- 41 | * Additional Routing 42 | * -------------------------------------------------------------------- 43 | * 44 | * There will often be times that you need additional routing and you 45 | * need it to be able to override any defaults in this file. Environment 46 | * based routes is one such time. require() additional route files here 47 | * to make that happen. 48 | * 49 | * You will have access to the $routes object within that file without 50 | * needing to reload it. 51 | */ 52 | if (file_exists(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) 53 | { 54 | require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php'; 55 | } 56 | -------------------------------------------------------------------------------- /sdk/codeigniter setup/app/Controllers/AlgodController.php: -------------------------------------------------------------------------------- 1 | debug(1); 17 | 18 | #Get the status 19 | //$return=$algorand->get("v2","status"); 20 | 21 | $return=$algorand->get("v2","ledger","supply"); 22 | 23 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 24 | 25 | #Full response with debug (json response) 26 | if(!empty($return)){ 27 | print_r($return); 28 | } 29 | #Only response array 30 | if(!empty($return['response'])){ 31 | print_r(json_decode($return['response'])); 32 | } 33 | #Only erros messages array 34 | if(!empty($return['message'])){ 35 | print_r(json_decode($return['message'])); 36 | } 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /sdk/codeigniter setup/app/Controllers/Home.php: -------------------------------------------------------------------------------- 1 | debug(1); 17 | 18 | #Get Versions 19 | $return=$algorand_indexer->get("health"); 20 | 21 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 22 | 23 | #Full response with debug (json response) 24 | if(!empty($return)){ 25 | print_r($return); 26 | } 27 | #Only response array 28 | if(!empty($return['response'])){ 29 | print_r(json_decode($return['response'])); 30 | } 31 | #Only erros messages array 32 | if(!empty($return['message'])){ 33 | print_r(json_decode($return['message'])); 34 | } 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /sdk/codeigniter setup/app/Controllers/KmdController.php: -------------------------------------------------------------------------------- 1 | debug(1); 17 | 18 | #Get Versions 19 | $return=$algorand_kmd->get("versions"); 20 | 21 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 22 | 23 | $return=$algorand_kmd->get("v1","wallets"); 24 | 25 | 26 | #Full response with debug (json response) 27 | if(!empty($return)){ 28 | print_r($return); 29 | } 30 | #Only response array 31 | if(!empty($return['response'])){ 32 | print_r(json_decode($return['response'])); 33 | } 34 | #Only erros messages array 35 | if(!empty($return['message'])){ 36 | print_r(json_decode($return['message'])); 37 | } 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /sdk/laravel setup/app/Algorand/algorand.php: -------------------------------------------------------------------------------- 1 | token = $token; 42 | $this->host = $host; 43 | $this->port = $port; 44 | $this->external = $external; 45 | $this->service = $service; 46 | 47 | if($this->external==true){ 48 | $this->protocol = 'https'; 49 | }else{ 50 | $this->protocol = 'http'; 51 | } 52 | $this->certificate = null; 53 | 54 | } 55 | 56 | public function debug($opt){ 57 | 58 | $this->debug=$opt; 59 | 60 | } 61 | 62 | public function SSL($certificate = null) { 63 | 64 | $this->protocol = 'https'; 65 | $this->certificate = $certificate; 66 | 67 | } 68 | 69 | public function __call($type, $params){ 70 | 71 | $this->status = null; 72 | $this->error = null; 73 | $this->raw = null; 74 | $this->response = null; 75 | 76 | // Parameters 77 | $params = array_values($params); 78 | 79 | // Request Type 80 | $type=strtoupper($type); 81 | 82 | 83 | // Method 84 | $method=$params[0]; 85 | 86 | $request=""; 87 | $request_body=""; 88 | $file=""; 89 | $transaction=""; 90 | 91 | // cURL 92 | $options = array( 93 | CURLOPT_HTTPAUTH => CURLAUTH_BASIC, 94 | CURLOPT_RETURNTRANSFER => true, 95 | CURLOPT_FOLLOWLOCATION => true, 96 | CURLOPT_MAXREDIRS => 10, 97 | ); 98 | 99 | if($this->external==true){ 100 | $options[CURLOPT_HTTPHEADER][]='x-api-key: '.$this->token; 101 | }else{ 102 | switch($this->service){ 103 | case "algod": 104 | $options[CURLOPT_HTTPHEADER][]='X-Algo-API-Token: '.$this->token; 105 | break; 106 | case "kmd": 107 | $options[CURLOPT_HTTPHEADER][]='X-KMD-API-Token: '.$this->token; 108 | break; 109 | case "indexer": 110 | $options[CURLOPT_HTTPHEADER][]='X-Indexer-API-Token: '.$this->token; 111 | break; 112 | } 113 | 114 | } 115 | 116 | $tp=count($params); 117 | $params_url=""; 118 | 119 | for($xp=0;$xp<$tp;++$xp){ 120 | 121 | if(is_array($params[$xp])==false AND $xp>0){ 122 | 123 | $params_url.="/".$params[$xp]; 124 | 125 | }else{ 126 | 127 | // Request 128 | if(!empty($params[$xp]['params'])){ $request = $params[$xp]['params']; } 129 | if(!empty($params[$xp]['body'])){ $request_body = $params[$xp]['body']; } 130 | 131 | // File 132 | if(!empty($params[$xp]['file'])){ $file=$params[$xp]['file']; } 133 | 134 | // Transaction 135 | if(!empty($params[$xp]['transaction'])){ $transaction=$params[$xp]['transaction']; } 136 | 137 | } 138 | 139 | } 140 | 141 | if($file!=""){ 142 | if(file_exists($file)){ 143 | $options[CURLOPT_HTTPHEADER][]='Content-type: application/x-binary'; 144 | $request_body = file_get_contents($file); 145 | } 146 | } 147 | 148 | if($transaction!=""){ 149 | if($this->external==true){ 150 | $options[CURLOPT_HTTPHEADER][]='Content-type: application/x-binary'; 151 | } 152 | $request_body = $transaction; 153 | } 154 | 155 | 156 | if($type=="POST"){ 157 | 158 | $options[CURLOPT_POST]=true; 159 | if(!empty($request_body)){ 160 | $options[CURLOPT_POSTFIELDS]=$request_body; 161 | }else{ 162 | $options[CURLOPT_POSTFIELDS]=json_encode($request); 163 | } 164 | 165 | } 166 | 167 | if($type=="DELETE"){ 168 | 169 | $options[CURLOPT_CUSTOMREQUEST]="DELETE"; 170 | if(!empty($request_body)){ 171 | $options[CURLOPT_POSTFIELDS]=$request_body; 172 | }else{ 173 | if(is_array($request)){ 174 | $options[CURLOPT_POSTFIELDS]=json_encode($request); 175 | } 176 | } 177 | 178 | } 179 | 180 | if($this->external==true){ 181 | $url=$this->protocol."://".$this->host."/".$method.$params_url; 182 | }else{ 183 | $url=$this->protocol."://".$this->host.":".$this->port."/".$method.$params_url; 184 | } 185 | $curl = curl_init($url); 186 | 187 | 188 | if(ini_get('open_basedir')) { 189 | unset($options[CURLOPT_FOLLOWLOCATION]); 190 | } 191 | 192 | if($this->protocol == 'https') { 193 | 194 | if ($this->certificate!="") { 195 | $options[CURLOPT_CAINFO] = $this->certificate; 196 | $options[CURLOPT_CAPATH] = DIRNAME($this->certificate); 197 | } else { 198 | $options[CURLOPT_SSL_VERIFYPEER] = false; 199 | } 200 | 201 | } 202 | 203 | 204 | curl_setopt_array($curl, $options); 205 | 206 | // Execute 207 | $this->raw = curl_exec($curl); 208 | 209 | // Get Status 210 | $this->status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 211 | 212 | //Json decode 213 | $this->response = $this->raw; 214 | 215 | // Filter Error 216 | $curl_error = curl_error($curl); 217 | 218 | curl_close($curl); 219 | 220 | if($curl_error!="") { 221 | $this->error = $curl_error; 222 | } 223 | 224 | $return=""; 225 | 226 | if ($this->status != 200) { 227 | 228 | switch ($this->status) { 229 | case 400: 230 | $this->error = 'BAD REQUEST'; 231 | break; 232 | case 401: 233 | $this->error = 'UNAUTHORIZED'; 234 | break; 235 | case 403: 236 | $this->error = 'FORBIDDEN'; 237 | break; 238 | case 404: 239 | $this->error = 'NOT FOUND'; 240 | break; 241 | case 404: 242 | $this->error = 'NOT ALLOWED'; 243 | break; 244 | } 245 | 246 | $return = array( 247 | "code" => $this->status, 248 | "message" => $this->response, 249 | ); 250 | 251 | }else{ 252 | 253 | $return = array( 254 | "code" => $this->status, 255 | "response" => $this->response, 256 | ); 257 | 258 | } 259 | 260 | if($this->debug==1){ 261 | 262 | $return['DEBUG']="ON"; 263 | $return['url']=$url; 264 | $return['options']=$options; 265 | 266 | } 267 | return $return; 268 | 269 | } 270 | } 271 | ?> 272 | -------------------------------------------------------------------------------- /sdk/laravel setup/app/Algorand/b32.php: -------------------------------------------------------------------------------- 1 | 0b00000,'A' => 0b00000,'B' => 0b00001,'C' => 0b00010,'D' => 0b00011,'E' => 0b00100,'F' => 0b00101,'G' => 0b00110,'H' => 0b00111,'I' => 0b01000,'J' => 0b01001,'K' => 0b01010,'L' => 0b01011,'M' => 0b01100,'N' => 0b01101,'O' => 0b01110,'P' => 0b01111,'Q' => 0b10000,'R' => 0b10001,'S' => 0b10010,'T' => 0b10011,'U' => 0b10100,'V' => 0b10101,'W' => 0b10110,'X' => 0b10111,'Y' => 0b11000,'Z' => 0b11001,'2' => 0b11010,'3' => 0b11011,'4' => 0b11100,'5' => 0b11101,'6' => 0b11110,'7' => 0b11111,]; 11 | 12 | public static function encode($string) { 13 | 14 | if ('' === $string) { return ''; } 15 | 16 | $encoded = ''; 17 | 18 | $n = $bitLen = $val = 0; 19 | 20 | $len = strlen($string); 21 | 22 | $string .= str_repeat(chr(0), 4); 23 | 24 | $chars = (array) unpack('C*', $string, 0); 25 | 26 | while ($n < $len || 0 !== $bitLen) { 27 | 28 | if ($bitLen < 5) { $val = $val << 8; $bitLen += 8; $n++; $val += $chars[$n]; } 29 | 30 | $shift = $bitLen - 5; $encoded .= ($n - (int)($bitLen > 8) > $len && 0 == $val) ? '=' : static::ALBT[$val >> $shift]; $val = $val & ((1 << $shift) - 1); $bitLen -= 5; 31 | 32 | } 33 | 34 | return $encoded; 35 | } 36 | 37 | public static function decode($base32String) { 38 | 39 | 40 | $base32String = strtoupper($base32String); $base32String = preg_replace(static::B2HEXP, '', $base32String); 41 | 42 | if ('' === $base32String || null === $base32String) { return ''; } 43 | 44 | $decoded = ''; $len = strlen($base32String)-6; $n = 0; $bitLen = 5; $val = static::MAPP[$base32String[0]]; 45 | 46 | while ($n < $len) { 47 | 48 | if ($bitLen < 8) { $val = $val << 5; $bitLen += 5; $n++; $pentet = $base32String[$n] ?? '='; 49 | 50 | if ('=' === $pentet) { $n = $len; } 51 | 52 | $val += static::MAPP[$pentet]; 53 | 54 | continue; 55 | 56 | } 57 | 58 | $shift = $bitLen - 8; $decoded .= chr($val >> $shift); $val = $val & ((1 << $shift) - 1); $bitLen -= 8; 59 | 60 | } 61 | return $decoded; 62 | } 63 | } 64 | ?> 65 | -------------------------------------------------------------------------------- /sdk/laravel setup/app/Algorand/msgpack.php: -------------------------------------------------------------------------------- 1 | pInt($value); 19 | } 20 | 21 | if (is_string($value)) { 22 | if ('' === $value) { 23 | return $this->fFStr || $this->fDStrBin ? "\xa0" : "\xc4\x00"; 24 | } 25 | if ($this->fFStr) { 26 | return $this->pStr($value); 27 | } 28 | if ($this->fDStrBin && preg_match(self::UTF8_REGEX, $value)) { 29 | return $this->pStr($value); 30 | } 31 | 32 | return $this->pBin($value); 33 | } 34 | 35 | if (is_array($value)) { 36 | 37 | if ([] === $value) { 38 | return $this->fDArrMap || $this->fFArr ? "\x90" : "\x80"; 39 | } 40 | 41 | if ($this->fDArrMap) { 42 | 43 | if (!isset($value[0]) && !array_key_exists(0, $value)) { 44 | return $this->pMap($value); 45 | } 46 | 47 | return array_values($value) === $value 48 | ? $this->pArray($value) 49 | : $this->pMap($value); 50 | } 51 | 52 | return $this->fFArr ? $this->pArray($value) : $this->pMap($value); 53 | } 54 | 55 | if (is_null($value)) { 56 | return "\xc0"; 57 | } 58 | 59 | if (is_bool($value)) { 60 | return $value ? "\xc3" : "\xc2"; 61 | } 62 | 63 | if (is_float($value)) { 64 | return $this->pFloat($value); 65 | } 66 | 67 | if ($this->tmrs) { 68 | foreach ($this->tmrs as $transformer) { 69 | if (!is_null($packed = $transformer->p($this, $value))) { 70 | return $packed; 71 | } 72 | } 73 | } 74 | 75 | if ($value instanceof Ext) { 76 | return $this->pExt($value->type, $value->data); 77 | } 78 | } 79 | 80 | public function pNil(){ 81 | return "\xc0"; 82 | } 83 | 84 | public function pBool($bool){ 85 | return $bool ? "\xc3" : "\xc2"; 86 | } 87 | 88 | public function pInt($int){ 89 | 90 | if ($int >= 0) { 91 | 92 | if ($int <= 0x7f) { 93 | return chr($int); 94 | } 95 | 96 | if ($int <= 0xff) { 97 | return "\xcc".chr($int); 98 | } 99 | 100 | if ($int <= 0xffff) { 101 | return "\xcd".chr($int >> 8).chr($int); 102 | } 103 | 104 | if ($int <= 0xffffffff) { 105 | return pack('CN', 0xce, $int); 106 | } 107 | 108 | return pack('CJ', 0xcf, $int); 109 | } 110 | 111 | if ($int >= -0x20) { 112 | return chr(0xe0 | $int); 113 | } 114 | 115 | if ($int >= -0x80) { 116 | return "\xd0".chr($int); 117 | } 118 | 119 | if ($int >= -0x8000) { 120 | return "\xd1".chr($int >> 8).chr($int); 121 | } 122 | 123 | if ($int >= -0x80000000) { 124 | return pack('CN', 0xd2, $int); 125 | } 126 | 127 | return pack('CJ', 0xd3, $int); 128 | } 129 | 130 | public function pFloat($float){ 131 | return $this->fFF32 132 | ? "\xca".pack('G', $float) 133 | : "\xcb".pack('E', $float); 134 | } 135 | 136 | public function pFloat32($float){ 137 | return "\xca".pack('G', $float); 138 | } 139 | 140 | public function pFloat64($float){ 141 | return "\xcb".pack('E', $float); 142 | } 143 | 144 | public function pStr($str){ 145 | $length = strlen($str); 146 | 147 | if ($length < 32) { 148 | return chr(0xa0 | $length).$str; 149 | } 150 | 151 | if ($length <= 0xff) { 152 | return "\xd9".chr($length).$str; 153 | } 154 | 155 | if ($length <= 0xffff) { 156 | return "\xda".chr($length >> 8).chr($length).$str; 157 | } 158 | 159 | return pack('CN', 0xdb, $length).$str; 160 | 161 | } 162 | 163 | public function pBin($str){ 164 | 165 | $length = strlen($str); 166 | 167 | if ($length <= 0xff) { 168 | return "\xc4".\chr($length).$str; 169 | } 170 | 171 | if ($length <= 0xffff) { 172 | return "\xc5".chr($length >> 8).chr($length).$str; 173 | } 174 | 175 | return pack('CN', 0xc6, $length).$str; 176 | 177 | } 178 | 179 | public function pArray($array){ 180 | 181 | $data = $this->pArrayHeader(count($array)); 182 | 183 | foreach ($array as $val) { 184 | $data .= $this->p($val); 185 | } 186 | 187 | return $data; 188 | 189 | } 190 | 191 | public function pArrayHeader($size){ 192 | 193 | if ($size <= 0xf) { 194 | 195 | return chr(0x90 | $size); 196 | 197 | } 198 | 199 | if ($size <= 0xffff) { 200 | 201 | return "\xdc".chr($size >> 8).chr($size); 202 | 203 | } 204 | 205 | return pack('CN', 0xdd, $size); 206 | 207 | } 208 | 209 | public function pMap($map){ 210 | $data = $this->pMapHeader(count($map)); 211 | 212 | if ($this->fFStr) { 213 | 214 | foreach ($map as $key => $val) { 215 | 216 | $data .= is_string($key) ? $this->pStr($key) : $this->pInt($key); 217 | $data .= $this->p($val); 218 | 219 | } 220 | 221 | return $data; 222 | } 223 | 224 | if ($this->fDStrBin) { 225 | foreach ($map as $key => $val) { 226 | 227 | $data .= is_string($key) 228 | ? (preg_match(self::UTF8_REGEX, $key) ? $this->pStr($key) : $this->pBin($key)) 229 | : $this->pInt($key); 230 | 231 | $data .= $this->p($val); 232 | } 233 | 234 | return $data; 235 | } 236 | 237 | foreach ($map as $key => $val) { 238 | 239 | $data .= is_string($key) ? $this->pBin($key) : $this->pInt($key); 240 | 241 | $data .= $this->p($val); 242 | } 243 | 244 | return $data; 245 | } 246 | 247 | public function pMapHeader($size){ 248 | 249 | if ($size <= 0xf) { 250 | 251 | return chr(0x80 | $size); 252 | 253 | } 254 | 255 | if ($size <= 0xffff) { 256 | 257 | return "\xde".chr($size >> 8).chr($size); 258 | 259 | } 260 | 261 | return pack('CN', 0xdf, $size); 262 | 263 | } 264 | 265 | public function pExt($type, $data){ 266 | 267 | $length = strlen($data); 268 | 269 | switch ($length) { 270 | 271 | case 1: return "\xd4".chr($type).$data; 272 | case 2: return "\xd5".chr($type).$data; 273 | case 4: return "\xd6".chr($type).$data; 274 | case 8: return "\xd7".chr($type).$data; 275 | case 16: return "\xd8".chr($type).$data; 276 | 277 | } 278 | 279 | if ($length <= 0xff) { 280 | 281 | return "\xc7".chr($length).chr($type).$data; 282 | 283 | } 284 | 285 | if ($length <= 0xffff) { 286 | 287 | return pack('CnC', 0xc8, $length, $type).$data; 288 | 289 | } 290 | 291 | return pack('CNC', 0xc9, $length, $type).$data; 292 | } 293 | } 294 | ?> 295 | -------------------------------------------------------------------------------- /sdk/laravel setup/app/Algorand/transactions.php: -------------------------------------------------------------------------------- 1 | pBin(utf8_encode(strval($out['txn']['note']))); } 27 | 28 | if(!empty($out['txn']['gp'])) { $out['txn']['gp']=strval($out['txn']['gp']); } 29 | if(!empty($out['txn']['rekey'])) { $out['txn']['rekey']=b32::decode($out['txn']['rekey']); } 30 | if(!empty($out['txn']['type'])) { $out['txn']['type']=strval($out['txn']['type']); } 31 | if(!empty($out['txn']['rcv'])) { $out['txn']['rcv']=strval($out['txn']['rcv']); } 32 | if(!empty($out['txn']['amt'])) { $out['txn']['amt']=intval($out['txn']['amt']); } 33 | if(!empty($out['txn']['aamt'])) { $out['txn']['aamt']=intval($out['txn']['aamt']); } 34 | if(!empty($out['txn']['close'])) { $out['txn']['close']=strval($out['txn']['close']); } 35 | if(!empty($out['txn']['xaid'])) { $out['txn']['xaid']=intval($out['txn']['xaid']); } 36 | if(!empty($out['txn']['apid'])) { $out['txn']['apid']=intval($out['txn']['apid']); } 37 | if(!empty($out['txn']['faid'])) { $out['txn']['faid']=intval($out['txn']['faid']); } 38 | if(!empty($out['txn']['caid'])) { $out['txn']['caid']=intval($out['txn']['caid']); } 39 | 40 | if(!empty($out['txn']['gh'])) { $out['txn']['gh']=base64_decode($out['txn']['gh']); } 41 | if(!empty($out['txn']['snd'])) { $out['txn']['snd']=b32::decode($out['txn']['snd']); } 42 | if(!empty($out['txn']['rcv'])) { $out['txn']['rcv']=b32::decode($out['txn']['rcv']); } 43 | if(!empty($out['txn']['close'])) { $out['txn']['close']=b32::decode($out['txn']['close']); } 44 | if(!empty($out['txn']['aclose'])) { $out['txn']['aclose']=b32::decode($out['txn']['aclose']); } 45 | if(!empty($out['txn']['selkey'])) { $out['txn']['selkey']=b32::decode($out['txn']['selkey']); } 46 | if(!empty($out['txn']['votekey'])) { $out['txn']['votekey']=b32::decode($out['txn']['votekey']); } 47 | if(!empty($out['txn']['arcv'])) { $out['txn']['arcv']=b32::decode($out['txn']['arcv']); } 48 | if(!empty($out['txn']['asnd'])) { $out['txn']['asnd']=b32::decode($out['txn']['asnd']); } 49 | if(!empty($out['txn']['fadd'])) { $out['txn']['fadd']=b32::decode($out['txn']['fadd']); } 50 | if(!empty($out['txn']['apat'])) { $out['txn']['apat']=b32::decode($out['txn']['apat']); } 51 | if(!empty($out['txn']['apap'])) { $out['txn']['apap']=b32::decode($out['txn']['apap']); } 52 | if(!empty($out['txn']['apsu'])) { $out['txn']['apsu']=b32::decode($out['txn']['apsu']); } 53 | if(!empty($out['txn']['apfa'])) { $out['txn']['apfa']=b32::decode($out['txn']['apfa']); } 54 | if(!empty($out['txn']['apas'])) { $out['txn']['apas']=b32::decode($out['txn']['apas']); } 55 | 56 | if(!empty($out['txn']['apar']['am'])) { $out['txn']['apar']['am']=b32::decode($out['txn']['apar']['am']); } 57 | if(!empty($out['txn']['apar']['c'])) { $out['txn']['apar']['c']=b32::decode($out['txn']['apar']['c']); } 58 | if(!empty($out['txn']['apar']['f'])) { $out['txn']['apar']['f']=b32::decode($out['txn']['apar']['f']); } 59 | if(!empty($out['txn']['apar']['m'])) { $out['txn']['apar']['m']=b32::decode($out['txn']['apar']['m']); } 60 | if(!empty($out['txn']['apar']['r'])) { $out['txn']['apar']['r']=b32::decode($out['txn']['apar']['r']); } 61 | if(!empty($out['txn']['apar']['dc'])) { $out['txn']['apar']['dc']=intval($out['txn']['apar']['dc']); } 62 | if(!empty($out['txn']['apar']['t'])) { $out['txn']['apar']['t']=intval($out['txn']['apar']['t']); } 63 | 64 | if($signature!=""){ 65 | $out=array( 66 | "sig" => $signature, 67 | "txn" => $out['txn'], 68 | ); 69 | $out=$msgpack->p($out); 70 | }else{ 71 | $out=$msgpack->p($out['txn']); 72 | } 73 | 74 | $out=bin2hex($out); 75 | $out=hex2bin($out); 76 | 77 | if($opt_msgpack==false){ 78 | $out=base64_encode($out); 79 | } 80 | return $out; 81 | } 82 | 83 | public function pk_encode($array){ 84 | $out=$array; 85 | $out=b32::decode($out); 86 | $out=base64_encode($out); 87 | return $out; 88 | } 89 | 90 | public function groupid($transactions){ 91 | 92 | $msgpack=new msgpack; 93 | $txn=""; 94 | $total=count($transactions); 95 | $txids=array(); 96 | for($x=0; $x<$total; $x++){ 97 | $raw_txn=$this->encode($transactions[$x],true); 98 | $raw_txn=hash('sha512/256',"TX".$raw_txn,true); 99 | $txids[$x]=$raw_txn; 100 | } 101 | 102 | $group_list=array( 103 | 'txlist' => $txids, 104 | ); 105 | 106 | $encoded=$msgpack->p($group_list); 107 | $gid = hash('sha512/256',"TG".$encoded,true); 108 | 109 | return $gid; 110 | } 111 | 112 | } 113 | ?> 114 | -------------------------------------------------------------------------------- /sdk/laravel setup/app/Http/Controllers/AlgodController.php: -------------------------------------------------------------------------------- 1 | debug(1); 19 | 20 | #Get the versions 21 | $return=$algorand->get("v2","status"); 22 | 23 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 24 | 25 | #Full response with debug (json response) 26 | if(!empty($return)){ 27 | print_r($return); 28 | } 29 | #Only response array 30 | if(!empty($return['response'])){ 31 | print_r(json_decode($return['response'])); 32 | } 33 | #Only erros messages array 34 | if(!empty($return['message'])){ 35 | print_r(json_decode($return['message'])); 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /sdk/laravel setup/app/Http/Controllers/IndexerController.php: -------------------------------------------------------------------------------- 1 | debug(1); 19 | 20 | #Get health, Returns 200 if healthy. 21 | $return=$algorand_indexer->get("health"); 22 | 23 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 24 | 25 | #Full response with debug (json response) 26 | if(!empty($return)){ 27 | print_r($return); 28 | } 29 | #Only response array 30 | if(!empty($return['response'])){ 31 | print_r(json_decode($return['response'])); 32 | } 33 | #Only erros messages array 34 | if(!empty($return['message'])){ 35 | print_r(json_decode($return['message'])); 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /sdk/laravel setup/app/Http/Controllers/KmdController.php: -------------------------------------------------------------------------------- 1 | debug(1); 20 | 21 | #Get Versions 22 | //$return=$algorand_kmd->get("versions"); 23 | 24 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 25 | 26 | 27 | #Wallet Init 28 | 29 | $params['params']=array( 30 | "wallet_id" => "4596a5cb20ccbedcec668762449363c1", 31 | "wallet_password" => "testes", 32 | ); 33 | $return=$algorand_kmd->post("v1","wallet","init",$params); 34 | $return_array=json_decode($return['response']); 35 | $wallet_handle_token=$return_array->wallet_handle_token; 36 | 37 | $return=$algorand_kmd->get("v1","wallets"); 38 | 39 | #Full response with debug (json response) 40 | if(!empty($return)){ 41 | print_r($return); 42 | } 43 | #Only response array 44 | if(!empty($return['response'])){ 45 | print_r(json_decode($return['response'])); 46 | } 47 | #Only erros messages array 48 | if(!empty($return['message'])){ 49 | print_r(json_decode($return['message'])); 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sdk/laravel setup/routes/web.php: -------------------------------------------------------------------------------- 1 | token = $token; 42 | $this->host = $host; 43 | $this->port = $port; 44 | $this->external = $external; 45 | $this->service = $service; 46 | 47 | if($this->external==true){ 48 | $this->protocol = 'https'; 49 | }else{ 50 | $this->protocol = 'http'; 51 | } 52 | $this->certificate = null; 53 | 54 | } 55 | 56 | public function debug($opt){ 57 | 58 | $this->debug=$opt; 59 | 60 | } 61 | 62 | public function SSL($certificate = null) { 63 | 64 | $this->protocol = 'https'; 65 | $this->certificate = $certificate; 66 | 67 | } 68 | 69 | public function __call($type, $params){ 70 | 71 | $this->status = null; 72 | $this->error = null; 73 | $this->raw = null; 74 | $this->response = null; 75 | 76 | // Parameters 77 | $params = array_values($params); 78 | 79 | // Request Type 80 | $type=strtoupper($type); 81 | 82 | 83 | // Method 84 | $method=$params[0]; 85 | 86 | $request=""; 87 | $request_body=""; 88 | $file=""; 89 | $transaction=""; 90 | 91 | // cURL 92 | $options = array( 93 | CURLOPT_HTTPAUTH => CURLAUTH_BASIC, 94 | CURLOPT_RETURNTRANSFER => true, 95 | CURLOPT_FOLLOWLOCATION => true, 96 | CURLOPT_MAXREDIRS => 10, 97 | ); 98 | 99 | if($this->external==true){ 100 | $options[CURLOPT_HTTPHEADER][]='x-api-key: '.$this->token; 101 | }else{ 102 | switch($this->service){ 103 | case "algod": 104 | $options[CURLOPT_HTTPHEADER][]='X-Algo-API-Token: '.$this->token; 105 | break; 106 | case "kmd": 107 | $options[CURLOPT_HTTPHEADER][]='X-KMD-API-Token: '.$this->token; 108 | break; 109 | case "indexer": 110 | $options[CURLOPT_HTTPHEADER][]='X-Indexer-API-Token: '.$this->token; 111 | break; 112 | } 113 | 114 | } 115 | 116 | $tp=count($params); 117 | $params_url=""; 118 | 119 | for($xp=0;$xp<$tp;++$xp){ 120 | 121 | if(is_array($params[$xp])==false AND $xp>0){ 122 | 123 | $params_url.="/".$params[$xp]; 124 | 125 | }else{ 126 | 127 | // Request 128 | if(!empty($params[$xp]['params'])){ $request = $params[$xp]['params']; } 129 | if(!empty($params[$xp]['body'])){ $request_body = $params[$xp]['body']; } 130 | 131 | // File 132 | if(!empty($params[$xp]['file'])){ $file=$params[$xp]['file']; } 133 | 134 | // Transaction 135 | if(!empty($params[$xp]['transaction'])){ $transaction=$params[$xp]['transaction']; } 136 | 137 | } 138 | 139 | } 140 | 141 | if($file!=""){ 142 | if(file_exists($file)){ 143 | $options[CURLOPT_HTTPHEADER][]='Content-type: application/x-binary'; 144 | $request_body = file_get_contents($file); 145 | } 146 | } 147 | 148 | if($transaction!=""){ 149 | if($this->external==true){ 150 | $options[CURLOPT_HTTPHEADER][]='Content-type: application/x-binary'; 151 | } 152 | $request_body = $transaction; 153 | } 154 | 155 | 156 | if($type=="POST"){ 157 | 158 | $options[CURLOPT_POST]=true; 159 | if(!empty($request_body)){ 160 | $options[CURLOPT_POSTFIELDS]=$request_body; 161 | }else{ 162 | $options[CURLOPT_POSTFIELDS]=json_encode($request); 163 | } 164 | 165 | } 166 | 167 | if($type=="DELETE"){ 168 | 169 | $options[CURLOPT_CUSTOMREQUEST]="DELETE"; 170 | if(!empty($request_body)){ 171 | $options[CURLOPT_POSTFIELDS]=$request_body; 172 | }else{ 173 | if(is_array($request)){ 174 | $options[CURLOPT_POSTFIELDS]=json_encode($request); 175 | } 176 | } 177 | 178 | } 179 | 180 | if($this->external==true){ 181 | $url=$this->protocol."://".$this->host."/".$method.$params_url; 182 | }else{ 183 | $url=$this->protocol."://".$this->host.":".$this->port."/".$method.$params_url; 184 | } 185 | $curl = curl_init($url); 186 | 187 | 188 | if(ini_get('open_basedir')) { 189 | unset($options[CURLOPT_FOLLOWLOCATION]); 190 | } 191 | 192 | if($this->protocol == 'https') { 193 | 194 | if ($this->certificate!="") { 195 | $options[CURLOPT_CAINFO] = $this->certificate; 196 | $options[CURLOPT_CAPATH] = DIRNAME($this->certificate); 197 | } else { 198 | $options[CURLOPT_SSL_VERIFYPEER] = false; 199 | } 200 | 201 | } 202 | 203 | 204 | curl_setopt_array($curl, $options); 205 | 206 | // Execute 207 | $this->raw = curl_exec($curl); 208 | 209 | // Get Status 210 | $this->status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 211 | 212 | //Json decode 213 | $this->response = $this->raw; 214 | 215 | // Filter Error 216 | $curl_error = curl_error($curl); 217 | 218 | curl_close($curl); 219 | 220 | if($curl_error!="") { 221 | $this->error = $curl_error; 222 | } 223 | 224 | $return=""; 225 | 226 | if ($this->status != 200) { 227 | 228 | switch ($this->status) { 229 | case 400: 230 | $this->error = 'BAD REQUEST'; 231 | break; 232 | case 401: 233 | $this->error = 'UNAUTHORIZED'; 234 | break; 235 | case 403: 236 | $this->error = 'FORBIDDEN'; 237 | break; 238 | case 404: 239 | $this->error = 'NOT FOUND'; 240 | break; 241 | case 404: 242 | $this->error = 'NOT ALLOWED'; 243 | break; 244 | } 245 | 246 | $return = array( 247 | "code" => $this->status, 248 | "message" => $this->response, 249 | ); 250 | 251 | }else{ 252 | 253 | $return = array( 254 | "code" => $this->status, 255 | "response" => $this->response, 256 | ); 257 | 258 | } 259 | 260 | if($this->debug==1){ 261 | 262 | $return['DEBUG']="ON"; 263 | $return['url']=$url; 264 | $return['options']=$options; 265 | 266 | } 267 | return $return; 268 | 269 | } 270 | } 271 | ?> 272 | -------------------------------------------------------------------------------- /sdk/lumen setup/app/Algorand/b32.php: -------------------------------------------------------------------------------- 1 | 0b00000,'A' => 0b00000,'B' => 0b00001,'C' => 0b00010,'D' => 0b00011,'E' => 0b00100,'F' => 0b00101,'G' => 0b00110,'H' => 0b00111,'I' => 0b01000,'J' => 0b01001,'K' => 0b01010,'L' => 0b01011,'M' => 0b01100,'N' => 0b01101,'O' => 0b01110,'P' => 0b01111,'Q' => 0b10000,'R' => 0b10001,'S' => 0b10010,'T' => 0b10011,'U' => 0b10100,'V' => 0b10101,'W' => 0b10110,'X' => 0b10111,'Y' => 0b11000,'Z' => 0b11001,'2' => 0b11010,'3' => 0b11011,'4' => 0b11100,'5' => 0b11101,'6' => 0b11110,'7' => 0b11111,]; 11 | 12 | public static function encode($string) { 13 | 14 | if ('' === $string) { return ''; } 15 | 16 | $encoded = ''; 17 | 18 | $n = $bitLen = $val = 0; 19 | 20 | $len = strlen($string); 21 | 22 | $string .= str_repeat(chr(0), 4); 23 | 24 | $chars = (array) unpack('C*', $string, 0); 25 | 26 | while ($n < $len || 0 !== $bitLen) { 27 | 28 | if ($bitLen < 5) { $val = $val << 8; $bitLen += 8; $n++; $val += $chars[$n]; } 29 | 30 | $shift = $bitLen - 5; $encoded .= ($n - (int)($bitLen > 8) > $len && 0 == $val) ? '=' : static::ALBT[$val >> $shift]; $val = $val & ((1 << $shift) - 1); $bitLen -= 5; 31 | 32 | } 33 | 34 | return $encoded; 35 | } 36 | 37 | public static function decode($base32String) { 38 | 39 | 40 | $base32String = strtoupper($base32String); $base32String = preg_replace(static::B2HEXP, '', $base32String); 41 | 42 | if ('' === $base32String || null === $base32String) { return ''; } 43 | 44 | $decoded = ''; $len = strlen($base32String)-6; $n = 0; $bitLen = 5; $val = static::MAPP[$base32String[0]]; 45 | 46 | while ($n < $len) { 47 | 48 | if ($bitLen < 8) { $val = $val << 5; $bitLen += 5; $n++; $pentet = $base32String[$n] ?? '='; 49 | 50 | if ('=' === $pentet) { $n = $len; } 51 | 52 | $val += static::MAPP[$pentet]; 53 | 54 | continue; 55 | 56 | } 57 | 58 | $shift = $bitLen - 8; $decoded .= chr($val >> $shift); $val = $val & ((1 << $shift) - 1); $bitLen -= 8; 59 | 60 | } 61 | return $decoded; 62 | } 63 | } 64 | ?> 65 | -------------------------------------------------------------------------------- /sdk/lumen setup/app/Algorand/msgpack.php: -------------------------------------------------------------------------------- 1 | pInt($value); 19 | } 20 | 21 | if (is_string($value)) { 22 | if ('' === $value) { 23 | return $this->fFStr || $this->fDStrBin ? "\xa0" : "\xc4\x00"; 24 | } 25 | if ($this->fFStr) { 26 | return $this->pStr($value); 27 | } 28 | if ($this->fDStrBin && preg_match(self::UTF8_REGEX, $value)) { 29 | return $this->pStr($value); 30 | } 31 | 32 | return $this->pBin($value); 33 | } 34 | 35 | if (is_array($value)) { 36 | 37 | if ([] === $value) { 38 | return $this->fDArrMap || $this->fFArr ? "\x90" : "\x80"; 39 | } 40 | 41 | if ($this->fDArrMap) { 42 | 43 | if (!isset($value[0]) && !array_key_exists(0, $value)) { 44 | return $this->pMap($value); 45 | } 46 | 47 | return array_values($value) === $value 48 | ? $this->pArray($value) 49 | : $this->pMap($value); 50 | } 51 | 52 | return $this->fFArr ? $this->pArray($value) : $this->pMap($value); 53 | } 54 | 55 | if (is_null($value)) { 56 | return "\xc0"; 57 | } 58 | 59 | if (is_bool($value)) { 60 | return $value ? "\xc3" : "\xc2"; 61 | } 62 | 63 | if (is_float($value)) { 64 | return $this->pFloat($value); 65 | } 66 | 67 | if ($this->tmrs) { 68 | foreach ($this->tmrs as $transformer) { 69 | if (!is_null($packed = $transformer->p($this, $value))) { 70 | return $packed; 71 | } 72 | } 73 | } 74 | 75 | if ($value instanceof Ext) { 76 | return $this->pExt($value->type, $value->data); 77 | } 78 | } 79 | 80 | public function pNil(){ 81 | return "\xc0"; 82 | } 83 | 84 | public function pBool($bool){ 85 | return $bool ? "\xc3" : "\xc2"; 86 | } 87 | 88 | public function pInt($int){ 89 | 90 | if ($int >= 0) { 91 | 92 | if ($int <= 0x7f) { 93 | return chr($int); 94 | } 95 | 96 | if ($int <= 0xff) { 97 | return "\xcc".chr($int); 98 | } 99 | 100 | if ($int <= 0xffff) { 101 | return "\xcd".chr($int >> 8).chr($int); 102 | } 103 | 104 | if ($int <= 0xffffffff) { 105 | return pack('CN', 0xce, $int); 106 | } 107 | 108 | return pack('CJ', 0xcf, $int); 109 | } 110 | 111 | if ($int >= -0x20) { 112 | return chr(0xe0 | $int); 113 | } 114 | 115 | if ($int >= -0x80) { 116 | return "\xd0".chr($int); 117 | } 118 | 119 | if ($int >= -0x8000) { 120 | return "\xd1".chr($int >> 8).chr($int); 121 | } 122 | 123 | if ($int >= -0x80000000) { 124 | return pack('CN', 0xd2, $int); 125 | } 126 | 127 | return pack('CJ', 0xd3, $int); 128 | } 129 | 130 | public function pFloat($float){ 131 | return $this->fFF32 132 | ? "\xca".pack('G', $float) 133 | : "\xcb".pack('E', $float); 134 | } 135 | 136 | public function pFloat32($float){ 137 | return "\xca".pack('G', $float); 138 | } 139 | 140 | public function pFloat64($float){ 141 | return "\xcb".pack('E', $float); 142 | } 143 | 144 | public function pStr($str){ 145 | $length = strlen($str); 146 | 147 | if ($length < 32) { 148 | return chr(0xa0 | $length).$str; 149 | } 150 | 151 | if ($length <= 0xff) { 152 | return "\xd9".chr($length).$str; 153 | } 154 | 155 | if ($length <= 0xffff) { 156 | return "\xda".chr($length >> 8).chr($length).$str; 157 | } 158 | 159 | return pack('CN', 0xdb, $length).$str; 160 | 161 | } 162 | 163 | public function pBin($str){ 164 | 165 | $length = strlen($str); 166 | 167 | if ($length <= 0xff) { 168 | return "\xc4".\chr($length).$str; 169 | } 170 | 171 | if ($length <= 0xffff) { 172 | return "\xc5".chr($length >> 8).chr($length).$str; 173 | } 174 | 175 | return pack('CN', 0xc6, $length).$str; 176 | 177 | } 178 | 179 | public function pArray($array){ 180 | 181 | $data = $this->pArrayHeader(count($array)); 182 | 183 | foreach ($array as $val) { 184 | $data .= $this->p($val); 185 | } 186 | 187 | return $data; 188 | 189 | } 190 | 191 | public function pArrayHeader($size){ 192 | 193 | if ($size <= 0xf) { 194 | 195 | return chr(0x90 | $size); 196 | 197 | } 198 | 199 | if ($size <= 0xffff) { 200 | 201 | return "\xdc".chr($size >> 8).chr($size); 202 | 203 | } 204 | 205 | return pack('CN', 0xdd, $size); 206 | 207 | } 208 | 209 | public function pMap($map){ 210 | $data = $this->pMapHeader(count($map)); 211 | 212 | if ($this->fFStr) { 213 | 214 | foreach ($map as $key => $val) { 215 | 216 | $data .= is_string($key) ? $this->pStr($key) : $this->pInt($key); 217 | $data .= $this->p($val); 218 | 219 | } 220 | 221 | return $data; 222 | } 223 | 224 | if ($this->fDStrBin) { 225 | foreach ($map as $key => $val) { 226 | 227 | $data .= is_string($key) 228 | ? (preg_match(self::UTF8_REGEX, $key) ? $this->pStr($key) : $this->pBin($key)) 229 | : $this->pInt($key); 230 | 231 | $data .= $this->p($val); 232 | } 233 | 234 | return $data; 235 | } 236 | 237 | foreach ($map as $key => $val) { 238 | 239 | $data .= is_string($key) ? $this->pBin($key) : $this->pInt($key); 240 | 241 | $data .= $this->p($val); 242 | } 243 | 244 | return $data; 245 | } 246 | 247 | public function pMapHeader($size){ 248 | 249 | if ($size <= 0xf) { 250 | 251 | return chr(0x80 | $size); 252 | 253 | } 254 | 255 | if ($size <= 0xffff) { 256 | 257 | return "\xde".chr($size >> 8).chr($size); 258 | 259 | } 260 | 261 | return pack('CN', 0xdf, $size); 262 | 263 | } 264 | 265 | public function pExt($type, $data){ 266 | 267 | $length = strlen($data); 268 | 269 | switch ($length) { 270 | 271 | case 1: return "\xd4".chr($type).$data; 272 | case 2: return "\xd5".chr($type).$data; 273 | case 4: return "\xd6".chr($type).$data; 274 | case 8: return "\xd7".chr($type).$data; 275 | case 16: return "\xd8".chr($type).$data; 276 | 277 | } 278 | 279 | if ($length <= 0xff) { 280 | 281 | return "\xc7".chr($length).chr($type).$data; 282 | 283 | } 284 | 285 | if ($length <= 0xffff) { 286 | 287 | return pack('CnC', 0xc8, $length, $type).$data; 288 | 289 | } 290 | 291 | return pack('CNC', 0xc9, $length, $type).$data; 292 | } 293 | } 294 | ?> 295 | -------------------------------------------------------------------------------- /sdk/lumen setup/app/Algorand/transactions.php: -------------------------------------------------------------------------------- 1 | pBin(utf8_encode(strval($out['txn']['note']))); } 26 | 27 | if(!empty($out['txn']['gp'])) { $out['txn']['gp']=strval($out['txn']['gp']); } 28 | if(!empty($out['txn']['rekey'])) { $out['txn']['rekey']=b32::decode($out['txn']['rekey']); } 29 | if(!empty($out['txn']['type'])) { $out['txn']['type']=strval($out['txn']['type']); } 30 | if(!empty($out['txn']['rcv'])) { $out['txn']['rcv']=strval($out['txn']['rcv']); } 31 | if(!empty($out['txn']['amt'])) { $out['txn']['amt']=intval($out['txn']['amt']); } 32 | if(!empty($out['txn']['aamt'])) { $out['txn']['aamt']=intval($out['txn']['aamt']); } 33 | if(!empty($out['txn']['close'])) { $out['txn']['close']=strval($out['txn']['close']); } 34 | if(!empty($out['txn']['xaid'])) { $out['txn']['xaid']=intval($out['txn']['xaid']); } 35 | if(!empty($out['txn']['apid'])) { $out['txn']['apid']=intval($out['txn']['apid']); } 36 | if(!empty($out['txn']['faid'])) { $out['txn']['faid']=intval($out['txn']['faid']); } 37 | if(!empty($out['txn']['caid'])) { $out['txn']['caid']=intval($out['txn']['caid']); } 38 | 39 | if(!empty($out['txn']['gh'])) { $out['txn']['gh']=base64_decode($out['txn']['gh']); } 40 | if(!empty($out['txn']['snd'])) { $out['txn']['snd']=b32::decode($out['txn']['snd']); } 41 | if(!empty($out['txn']['rcv'])) { $out['txn']['rcv']=b32::decode($out['txn']['rcv']); } 42 | if(!empty($out['txn']['close'])) { $out['txn']['close']=b32::decode($out['txn']['close']); } 43 | if(!empty($out['txn']['aclose'])) { $out['txn']['aclose']=b32::decode($out['txn']['aclose']); } 44 | if(!empty($out['txn']['selkey'])) { $out['txn']['selkey']=b32::decode($out['txn']['selkey']); } 45 | if(!empty($out['txn']['votekey'])) { $out['txn']['votekey']=b32::decode($out['txn']['votekey']); } 46 | if(!empty($out['txn']['arcv'])) { $out['txn']['arcv']=b32::decode($out['txn']['arcv']); } 47 | if(!empty($out['txn']['asnd'])) { $out['txn']['asnd']=b32::decode($out['txn']['asnd']); } 48 | if(!empty($out['txn']['fadd'])) { $out['txn']['fadd']=b32::decode($out['txn']['fadd']); } 49 | if(!empty($out['txn']['apat'])) { $out['txn']['apat']=b32::decode($out['txn']['apat']); } 50 | if(!empty($out['txn']['apap'])) { $out['txn']['apap']=b32::decode($out['txn']['apap']); } 51 | if(!empty($out['txn']['apsu'])) { $out['txn']['apsu']=b32::decode($out['txn']['apsu']); } 52 | if(!empty($out['txn']['apfa'])) { $out['txn']['apfa']=b32::decode($out['txn']['apfa']); } 53 | if(!empty($out['txn']['apas'])) { $out['txn']['apas']=b32::decode($out['txn']['apas']); } 54 | 55 | if(!empty($out['txn']['apar']['am'])) { $out['txn']['apar']['am']=b32::decode($out['txn']['apar']['am']); } 56 | if(!empty($out['txn']['apar']['c'])) { $out['txn']['apar']['c']=b32::decode($out['txn']['apar']['c']); } 57 | if(!empty($out['txn']['apar']['f'])) { $out['txn']['apar']['f']=b32::decode($out['txn']['apar']['f']); } 58 | if(!empty($out['txn']['apar']['m'])) { $out['txn']['apar']['m']=b32::decode($out['txn']['apar']['m']); } 59 | if(!empty($out['txn']['apar']['r'])) { $out['txn']['apar']['r']=b32::decode($out['txn']['apar']['r']); } 60 | if(!empty($out['txn']['apar']['dc'])) { $out['txn']['apar']['dc']=intval($out['txn']['apar']['dc']); } 61 | if(!empty($out['txn']['apar']['t'])) { $out['txn']['apar']['t']=intval($out['txn']['apar']['t']); } 62 | 63 | if($signature!=""){ 64 | $out=array( 65 | "sig" => $signature, 66 | "txn" => $out['txn'], 67 | ); 68 | $out=$msgpack->p($out); 69 | }else{ 70 | $out=$msgpack->p($out['txn']); 71 | } 72 | 73 | $out=bin2hex($out); 74 | $out=hex2bin($out); 75 | 76 | if($opt_msgpack==false){ 77 | $out=base64_encode($out); 78 | } 79 | return $out; 80 | } 81 | 82 | public function pk_encode($array){ 83 | $out=$array; 84 | $out=b32::decode($out); 85 | $out=base64_encode($out); 86 | return $out; 87 | } 88 | 89 | public function groupid($transactions){ 90 | 91 | $msgpack=new msgpack; 92 | $txn=""; 93 | $total=count($transactions); 94 | $txids=array(); 95 | for($x=0; $x<$total; $x++){ 96 | $raw_txn=$this->encode($transactions[$x],true); 97 | $raw_txn=hash('sha512/256',"TX".$raw_txn,true); 98 | $txids[$x]=$raw_txn; 99 | } 100 | 101 | $group_list=array( 102 | 'txlist' => $txids, 103 | ); 104 | 105 | $encoded=$msgpack->p($group_list); 106 | $gid = hash('sha512/256',"TG".$encoded,true); 107 | 108 | return $gid; 109 | } 110 | 111 | } 112 | ?> 113 | -------------------------------------------------------------------------------- /sdk/lumen setup/app/Http/Controllers/AlgodController.php: -------------------------------------------------------------------------------- 1 | debug(1); 19 | 20 | #Get the versions 21 | $return=$algorand->get("v2","status"); 22 | 23 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 24 | 25 | #Full response with debug (json response) 26 | if(!empty($return)){ 27 | print_r($return); 28 | } 29 | #Only response array 30 | if(!empty($return['response'])){ 31 | print_r(json_decode($return['response'])); 32 | } 33 | #Only erros messages array 34 | if(!empty($return['message'])){ 35 | print_r(json_decode($return['message'])); 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /sdk/lumen setup/app/Http/Controllers/IndexerController.php: -------------------------------------------------------------------------------- 1 | debug(1); 19 | 20 | #Get health, Returns 200 if healthy. 21 | $return=$algorand_indexer->get("health"); 22 | 23 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 24 | 25 | #Full response with debug (json response) 26 | if(!empty($return)){ 27 | print_r($return); 28 | } 29 | #Only response array 30 | if(!empty($return['response'])){ 31 | print_r(json_decode($return['response'])); 32 | } 33 | #Only erros messages array 34 | if(!empty($return['message'])){ 35 | print_r(json_decode($return['message'])); 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /sdk/lumen setup/app/Http/Controllers/KmdController.php: -------------------------------------------------------------------------------- 1 | debug(1); 20 | 21 | #Get Versions 22 | //$return=$algorand_kmd->get("versions"); 23 | 24 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 25 | 26 | 27 | #Wallet List 28 | $return=$algorand_kmd->get("v1","wallets"); 29 | 30 | 31 | #Full response with debug (json response) 32 | if(!empty($return)){ 33 | print_r($return); 34 | } 35 | #Only response array 36 | if(!empty($return['response'])){ 37 | print_r(json_decode($return['response'])); 38 | } 39 | #Only erros messages array 40 | if(!empty($return['message'])){ 41 | print_r(json_decode($return['message'])); 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sdk/lumen setup/routes/web.php: -------------------------------------------------------------------------------- 1 | get('/algod', 'AlgodController@index'); 23 | $router->get('/kmd', 'KmdController@index'); 24 | $router->get('/indexer', 'IndexerController@index'); 25 | 26 | #Simple Native Method Setup 27 | $router->get('/', function () { 28 | 29 | 30 | }); 31 | -------------------------------------------------------------------------------- /sdk/symfony setup/src/Algorand/b32.php: -------------------------------------------------------------------------------- 1 | 0b00000,'A' => 0b00000,'B' => 0b00001,'C' => 0b00010,'D' => 0b00011,'E' => 0b00100,'F' => 0b00101,'G' => 0b00110,'H' => 0b00111,'I' => 0b01000,'J' => 0b01001,'K' => 0b01010,'L' => 0b01011,'M' => 0b01100,'N' => 0b01101,'O' => 0b01110,'P' => 0b01111,'Q' => 0b10000,'R' => 0b10001,'S' => 0b10010,'T' => 0b10011,'U' => 0b10100,'V' => 0b10101,'W' => 0b10110,'X' => 0b10111,'Y' => 0b11000,'Z' => 0b11001,'2' => 0b11010,'3' => 0b11011,'4' => 0b11100,'5' => 0b11101,'6' => 0b11110,'7' => 0b11111,]; 11 | 12 | public static function encode($string) { 13 | 14 | if ('' === $string) { return ''; } 15 | 16 | $encoded = ''; 17 | 18 | $n = $bitLen = $val = 0; 19 | 20 | $len = strlen($string); 21 | 22 | $string .= str_repeat(chr(0), 4); 23 | 24 | $chars = (array) unpack('C*', $string, 0); 25 | 26 | while ($n < $len || 0 !== $bitLen) { 27 | 28 | if ($bitLen < 5) { $val = $val << 8; $bitLen += 8; $n++; $val += $chars[$n]; } 29 | 30 | $shift = $bitLen - 5; $encoded .= ($n - (int)($bitLen > 8) > $len && 0 == $val) ? '=' : static::ALBT[$val >> $shift]; $val = $val & ((1 << $shift) - 1); $bitLen -= 5; 31 | 32 | } 33 | 34 | return $encoded; 35 | } 36 | 37 | public static function decode($base32String) { 38 | 39 | 40 | $base32String = strtoupper($base32String); $base32String = preg_replace(static::B2HEXP, '', $base32String); 41 | 42 | if ('' === $base32String || null === $base32String) { return ''; } 43 | 44 | $decoded = ''; $len = strlen($base32String)-6; $n = 0; $bitLen = 5; $val = static::MAPP[$base32String[0]]; 45 | 46 | while ($n < $len) { 47 | 48 | if ($bitLen < 8) { $val = $val << 5; $bitLen += 5; $n++; $pentet = $base32String[$n] ?? '='; 49 | 50 | if ('=' === $pentet) { $n = $len; } 51 | 52 | $val += static::MAPP[$pentet]; 53 | 54 | continue; 55 | 56 | } 57 | 58 | $shift = $bitLen - 8; $decoded .= chr($val >> $shift); $val = $val & ((1 << $shift) - 1); $bitLen -= 8; 59 | 60 | } 61 | return $decoded; 62 | } 63 | } 64 | ?> 65 | -------------------------------------------------------------------------------- /sdk/symfony setup/src/Algorand/msgpack.php: -------------------------------------------------------------------------------- 1 | pInt($value); 19 | } 20 | 21 | if (is_string($value)) { 22 | if ('' === $value) { 23 | return $this->fFStr || $this->fDStrBin ? "\xa0" : "\xc4\x00"; 24 | } 25 | if ($this->fFStr) { 26 | return $this->pStr($value); 27 | } 28 | if ($this->fDStrBin && preg_match(self::UTF8_REGEX, $value)) { 29 | return $this->pStr($value); 30 | } 31 | 32 | return $this->pBin($value); 33 | } 34 | 35 | if (is_array($value)) { 36 | 37 | if ([] === $value) { 38 | return $this->fDArrMap || $this->fFArr ? "\x90" : "\x80"; 39 | } 40 | 41 | if ($this->fDArrMap) { 42 | 43 | if (!isset($value[0]) && !array_key_exists(0, $value)) { 44 | return $this->pMap($value); 45 | } 46 | 47 | return array_values($value) === $value 48 | ? $this->pArray($value) 49 | : $this->pMap($value); 50 | } 51 | 52 | return $this->fFArr ? $this->pArray($value) : $this->pMap($value); 53 | } 54 | 55 | if (is_null($value)) { 56 | return "\xc0"; 57 | } 58 | 59 | if (is_bool($value)) { 60 | return $value ? "\xc3" : "\xc2"; 61 | } 62 | 63 | if (is_float($value)) { 64 | return $this->pFloat($value); 65 | } 66 | 67 | if ($this->tmrs) { 68 | foreach ($this->tmrs as $transformer) { 69 | if (!is_null($packed = $transformer->p($this, $value))) { 70 | return $packed; 71 | } 72 | } 73 | } 74 | 75 | if ($value instanceof Ext) { 76 | return $this->pExt($value->type, $value->data); 77 | } 78 | } 79 | 80 | public function pNil(){ 81 | return "\xc0"; 82 | } 83 | 84 | public function pBool($bool){ 85 | return $bool ? "\xc3" : "\xc2"; 86 | } 87 | 88 | public function pInt($int){ 89 | 90 | if ($int >= 0) { 91 | 92 | if ($int <= 0x7f) { 93 | return chr($int); 94 | } 95 | 96 | if ($int <= 0xff) { 97 | return "\xcc".chr($int); 98 | } 99 | 100 | if ($int <= 0xffff) { 101 | return "\xcd".chr($int >> 8).chr($int); 102 | } 103 | 104 | if ($int <= 0xffffffff) { 105 | return pack('CN', 0xce, $int); 106 | } 107 | 108 | return pack('CJ', 0xcf, $int); 109 | } 110 | 111 | if ($int >= -0x20) { 112 | return chr(0xe0 | $int); 113 | } 114 | 115 | if ($int >= -0x80) { 116 | return "\xd0".chr($int); 117 | } 118 | 119 | if ($int >= -0x8000) { 120 | return "\xd1".chr($int >> 8).chr($int); 121 | } 122 | 123 | if ($int >= -0x80000000) { 124 | return pack('CN', 0xd2, $int); 125 | } 126 | 127 | return pack('CJ', 0xd3, $int); 128 | } 129 | 130 | public function pFloat($float){ 131 | return $this->fFF32 132 | ? "\xca".pack('G', $float) 133 | : "\xcb".pack('E', $float); 134 | } 135 | 136 | public function pFloat32($float){ 137 | return "\xca".pack('G', $float); 138 | } 139 | 140 | public function pFloat64($float){ 141 | return "\xcb".pack('E', $float); 142 | } 143 | 144 | public function pStr($str){ 145 | $length = strlen($str); 146 | 147 | if ($length < 32) { 148 | return chr(0xa0 | $length).$str; 149 | } 150 | 151 | if ($length <= 0xff) { 152 | return "\xd9".chr($length).$str; 153 | } 154 | 155 | if ($length <= 0xffff) { 156 | return "\xda".chr($length >> 8).chr($length).$str; 157 | } 158 | 159 | return pack('CN', 0xdb, $length).$str; 160 | 161 | } 162 | 163 | public function pBin($str){ 164 | 165 | $length = strlen($str); 166 | 167 | if ($length <= 0xff) { 168 | return "\xc4".\chr($length).$str; 169 | } 170 | 171 | if ($length <= 0xffff) { 172 | return "\xc5".chr($length >> 8).chr($length).$str; 173 | } 174 | 175 | return pack('CN', 0xc6, $length).$str; 176 | 177 | } 178 | 179 | public function pArray($array){ 180 | 181 | $data = $this->pArrayHeader(count($array)); 182 | 183 | foreach ($array as $val) { 184 | $data .= $this->p($val); 185 | } 186 | 187 | return $data; 188 | 189 | } 190 | 191 | public function pArrayHeader($size){ 192 | 193 | if ($size <= 0xf) { 194 | 195 | return chr(0x90 | $size); 196 | 197 | } 198 | 199 | if ($size <= 0xffff) { 200 | 201 | return "\xdc".chr($size >> 8).chr($size); 202 | 203 | } 204 | 205 | return pack('CN', 0xdd, $size); 206 | 207 | } 208 | 209 | public function pMap($map){ 210 | $data = $this->pMapHeader(count($map)); 211 | 212 | if ($this->fFStr) { 213 | 214 | foreach ($map as $key => $val) { 215 | 216 | $data .= is_string($key) ? $this->pStr($key) : $this->pInt($key); 217 | $data .= $this->p($val); 218 | 219 | } 220 | 221 | return $data; 222 | } 223 | 224 | if ($this->fDStrBin) { 225 | foreach ($map as $key => $val) { 226 | 227 | $data .= is_string($key) 228 | ? (preg_match(self::UTF8_REGEX, $key) ? $this->pStr($key) : $this->pBin($key)) 229 | : $this->pInt($key); 230 | 231 | $data .= $this->p($val); 232 | } 233 | 234 | return $data; 235 | } 236 | 237 | foreach ($map as $key => $val) { 238 | 239 | $data .= is_string($key) ? $this->pBin($key) : $this->pInt($key); 240 | 241 | $data .= $this->p($val); 242 | } 243 | 244 | return $data; 245 | } 246 | 247 | public function pMapHeader($size){ 248 | 249 | if ($size <= 0xf) { 250 | 251 | return chr(0x80 | $size); 252 | 253 | } 254 | 255 | if ($size <= 0xffff) { 256 | 257 | return "\xde".chr($size >> 8).chr($size); 258 | 259 | } 260 | 261 | return pack('CN', 0xdf, $size); 262 | 263 | } 264 | 265 | public function pExt($type, $data){ 266 | 267 | $length = strlen($data); 268 | 269 | switch ($length) { 270 | 271 | case 1: return "\xd4".chr($type).$data; 272 | case 2: return "\xd5".chr($type).$data; 273 | case 4: return "\xd6".chr($type).$data; 274 | case 8: return "\xd7".chr($type).$data; 275 | case 16: return "\xd8".chr($type).$data; 276 | 277 | } 278 | 279 | if ($length <= 0xff) { 280 | 281 | return "\xc7".chr($length).chr($type).$data; 282 | 283 | } 284 | 285 | if ($length <= 0xffff) { 286 | 287 | return pack('CnC', 0xc8, $length, $type).$data; 288 | 289 | } 290 | 291 | return pack('CNC', 0xc9, $length, $type).$data; 292 | } 293 | } 294 | ?> 295 | -------------------------------------------------------------------------------- /sdk/symfony setup/src/Algorand/transactions.php: -------------------------------------------------------------------------------- 1 | pBin(utf8_encode(strval($out['txn']['note']))); } 26 | 27 | if(!empty($out['txn']['gp'])) { $out['txn']['gp']=strval($out['txn']['gp']); } 28 | if(!empty($out['txn']['rekey'])) { $out['txn']['rekey']=b32::decode($out['txn']['rekey']); } 29 | if(!empty($out['txn']['type'])) { $out['txn']['type']=strval($out['txn']['type']); } 30 | if(!empty($out['txn']['rcv'])) { $out['txn']['rcv']=strval($out['txn']['rcv']); } 31 | if(!empty($out['txn']['amt'])) { $out['txn']['amt']=intval($out['txn']['amt']); } 32 | if(!empty($out['txn']['aamt'])) { $out['txn']['aamt']=intval($out['txn']['aamt']); } 33 | if(!empty($out['txn']['close'])) { $out['txn']['close']=strval($out['txn']['close']); } 34 | if(!empty($out['txn']['xaid'])) { $out['txn']['xaid']=intval($out['txn']['xaid']); } 35 | if(!empty($out['txn']['apid'])) { $out['txn']['apid']=intval($out['txn']['apid']); } 36 | if(!empty($out['txn']['faid'])) { $out['txn']['faid']=intval($out['txn']['faid']); } 37 | if(!empty($out['txn']['caid'])) { $out['txn']['caid']=intval($out['txn']['caid']); } 38 | 39 | if(!empty($out['txn']['gh'])) { $out['txn']['gh']=base64_decode($out['txn']['gh']); } 40 | if(!empty($out['txn']['snd'])) { $out['txn']['snd']=b32::decode($out['txn']['snd']); } 41 | if(!empty($out['txn']['rcv'])) { $out['txn']['rcv']=b32::decode($out['txn']['rcv']); } 42 | if(!empty($out['txn']['close'])) { $out['txn']['close']=b32::decode($out['txn']['close']); } 43 | if(!empty($out['txn']['aclose'])) { $out['txn']['aclose']=b32::decode($out['txn']['aclose']); } 44 | if(!empty($out['txn']['selkey'])) { $out['txn']['selkey']=b32::decode($out['txn']['selkey']); } 45 | if(!empty($out['txn']['votekey'])) { $out['txn']['votekey']=b32::decode($out['txn']['votekey']); } 46 | if(!empty($out['txn']['arcv'])) { $out['txn']['arcv']=b32::decode($out['txn']['arcv']); } 47 | if(!empty($out['txn']['asnd'])) { $out['txn']['asnd']=b32::decode($out['txn']['asnd']); } 48 | if(!empty($out['txn']['fadd'])) { $out['txn']['fadd']=b32::decode($out['txn']['fadd']); } 49 | if(!empty($out['txn']['apat'])) { $out['txn']['apat']=b32::decode($out['txn']['apat']); } 50 | if(!empty($out['txn']['apap'])) { $out['txn']['apap']=b32::decode($out['txn']['apap']); } 51 | if(!empty($out['txn']['apsu'])) { $out['txn']['apsu']=b32::decode($out['txn']['apsu']); } 52 | if(!empty($out['txn']['apfa'])) { $out['txn']['apfa']=b32::decode($out['txn']['apfa']); } 53 | if(!empty($out['txn']['apas'])) { $out['txn']['apas']=b32::decode($out['txn']['apas']); } 54 | 55 | if(!empty($out['txn']['apar']['am'])) { $out['txn']['apar']['am']=b32::decode($out['txn']['apar']['am']); } 56 | if(!empty($out['txn']['apar']['c'])) { $out['txn']['apar']['c']=b32::decode($out['txn']['apar']['c']); } 57 | if(!empty($out['txn']['apar']['f'])) { $out['txn']['apar']['f']=b32::decode($out['txn']['apar']['f']); } 58 | if(!empty($out['txn']['apar']['m'])) { $out['txn']['apar']['m']=b32::decode($out['txn']['apar']['m']); } 59 | if(!empty($out['txn']['apar']['r'])) { $out['txn']['apar']['r']=b32::decode($out['txn']['apar']['r']); } 60 | if(!empty($out['txn']['apar']['dc'])) { $out['txn']['apar']['dc']=intval($out['txn']['apar']['dc']); } 61 | if(!empty($out['txn']['apar']['t'])) { $out['txn']['apar']['t']=intval($out['txn']['apar']['t']); } 62 | 63 | if($signature!=""){ 64 | $out=array( 65 | "sig" => $signature, 66 | "txn" => $out['txn'], 67 | ); 68 | $out=$msgpack->p($out); 69 | }else{ 70 | $out=$msgpack->p($out['txn']); 71 | } 72 | 73 | $out=bin2hex($out); 74 | $out=hex2bin($out); 75 | 76 | if($opt_msgpack==false){ 77 | $out=base64_encode($out); 78 | } 79 | return $out; 80 | } 81 | 82 | public function pk_encode($array){ 83 | $out=$array; 84 | $out=b32::decode($out); 85 | $out=base64_encode($out); 86 | return $out; 87 | } 88 | 89 | public function groupid($transactions){ 90 | 91 | $msgpack=new msgpack; 92 | $txn=""; 93 | $total=count($transactions); 94 | $txids=array(); 95 | for($x=0; $x<$total; $x++){ 96 | $raw_txn=$this->encode($transactions[$x],true); 97 | $raw_txn=hash('sha512/256',"TX".$raw_txn,true); 98 | $txids[$x]=$raw_txn; 99 | } 100 | 101 | $group_list=array( 102 | 'txlist' => $txids, 103 | ); 104 | 105 | $encoded=$msgpack->p($group_list); 106 | $gid = hash('sha512/256',"TG".$encoded,true); 107 | 108 | return $gid; 109 | } 110 | 111 | } 112 | ?> 113 | -------------------------------------------------------------------------------- /sdk/symfony setup/src/Controller/DefaultController.php: -------------------------------------------------------------------------------- 1 | debug(1); 36 | 37 | #Gets the current node status. 38 | $return=$algorand->get("v2","status"); 39 | 40 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 41 | 42 | $output=""; 43 | 44 | #Full response with debug (json response) 45 | if(!empty($return)){ 46 | $output.=print_r($return, true); 47 | } 48 | if(!empty($return['response'])){ 49 | $output.=print_r(json_decode($return['response']), true); 50 | } 51 | if(!empty($return['message'])){ 52 | $output.=print_r(json_decode($return['message']), true); 53 | } 54 | $response = new Response($output); 55 | 56 | return $response; 57 | } 58 | 59 | /** 60 | * @Route("/kmd", name="AlgorandKmd") 61 | */ 62 | public function AlgorandKmd(): Response 63 | { 64 | 65 | $algorand_kmd = new Algorand("kmd","dcb406527f3ded8464dbd56e6ea001b9b17882cfcf8194c17069bb22816307ad","localhost",7833); 66 | $algorand_kmd->debug(1); 67 | 68 | #Gets the current node status. 69 | //$return=$algorand_kmd->get("versions"); 70 | 71 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 72 | 73 | $output=""; 74 | 75 | $return=$algorand_kmd->get("v1","wallets"); 76 | 77 | #Full response with debug (json response) 78 | if(!empty($return)){ 79 | $output.=print_r($return, true); 80 | } 81 | if(!empty($return['response'])){ 82 | $output.=print_r(json_decode($return['response']), true); 83 | } 84 | if(!empty($return['message'])){ 85 | $output.=print_r(json_decode($return['message']), true); 86 | } 87 | $response = new Response($output); 88 | 89 | return $response; 90 | 91 | } 92 | 93 | /** 94 | * @Route("/indexer", name="AlgorandIndexer") 95 | */ 96 | public function AlgorandIndexer(): Response 97 | { 98 | 99 | $algorand_indexer = new Algorand("indexer","{indexer-token}","localhost",8980); 100 | $algorand_indexer->debug(1); 101 | 102 | #Get health, Returns 200 if healthy. 103 | $return=$algorand_indexer->get("health"); 104 | 105 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 106 | 107 | $output=""; 108 | 109 | #Full response with debug (json response) 110 | if(!empty($return)){ 111 | $output.=print_r($return, true); 112 | } 113 | if(!empty($return['response'])){ 114 | $output.=print_r(json_decode($return['response']), true); 115 | } 116 | if(!empty($return['message'])){ 117 | $output.=print_r(json_decode($return['message']), true); 118 | } 119 | $response = new Response($output); 120 | 121 | return $response; 122 | 123 | } 124 | 125 | 126 | } 127 | -------------------------------------------------------------------------------- /sdk/symfony setup/src/config/routes.yaml: -------------------------------------------------------------------------------- 1 | index: 2 | path: / 3 | controller: App\Controller\DefaultController::index 4 | -------------------------------------------------------------------------------- /sdk/yii setup/Algorand/algorand.php: -------------------------------------------------------------------------------- 1 | token = $token; 42 | $this->host = $host; 43 | $this->port = $port; 44 | $this->external = $external; 45 | $this->service = $service; 46 | 47 | if($this->external==true){ 48 | $this->protocol = 'https'; 49 | }else{ 50 | $this->protocol = 'http'; 51 | } 52 | $this->certificate = null; 53 | 54 | } 55 | 56 | public function debug($opt){ 57 | 58 | $this->debug=$opt; 59 | 60 | } 61 | 62 | public function SSL($certificate = null) { 63 | 64 | $this->protocol = 'https'; 65 | $this->certificate = $certificate; 66 | 67 | } 68 | 69 | public function __call($type, $params){ 70 | 71 | $this->status = null; 72 | $this->error = null; 73 | $this->raw = null; 74 | $this->response = null; 75 | 76 | // Parameters 77 | $params = array_values($params); 78 | 79 | // Request Type 80 | $type=strtoupper($type); 81 | 82 | 83 | // Method 84 | $method=$params[0]; 85 | 86 | $request=""; 87 | $request_body=""; 88 | $file=""; 89 | $transaction=""; 90 | 91 | // cURL 92 | $options = array( 93 | CURLOPT_HTTPAUTH => CURLAUTH_BASIC, 94 | CURLOPT_RETURNTRANSFER => true, 95 | CURLOPT_FOLLOWLOCATION => true, 96 | CURLOPT_MAXREDIRS => 10, 97 | ); 98 | 99 | if($this->external==true){ 100 | $options[CURLOPT_HTTPHEADER][]='x-api-key: '.$this->token; 101 | }else{ 102 | switch($this->service){ 103 | case "algod": 104 | $options[CURLOPT_HTTPHEADER][]='X-Algo-API-Token: '.$this->token; 105 | break; 106 | case "kmd": 107 | $options[CURLOPT_HTTPHEADER][]='X-KMD-API-Token: '.$this->token; 108 | break; 109 | case "indexer": 110 | $options[CURLOPT_HTTPHEADER][]='X-Indexer-API-Token: '.$this->token; 111 | break; 112 | } 113 | 114 | } 115 | 116 | $tp=count($params); 117 | $params_url=""; 118 | 119 | for($xp=0;$xp<$tp;++$xp){ 120 | 121 | if(is_array($params[$xp])==false AND $xp>0){ 122 | 123 | $params_url.="/".$params[$xp]; 124 | 125 | }else{ 126 | 127 | // Request 128 | if(!empty($params[$xp]['params'])){ $request = $params[$xp]['params']; } 129 | if(!empty($params[$xp]['body'])){ $request_body = $params[$xp]['body']; } 130 | 131 | // File 132 | if(!empty($params[$xp]['file'])){ $file=$params[$xp]['file']; } 133 | 134 | // Transaction 135 | if(!empty($params[$xp]['transaction'])){ $transaction=$params[$xp]['transaction']; } 136 | 137 | } 138 | 139 | } 140 | 141 | if($file!=""){ 142 | if(file_exists($file)){ 143 | $options[CURLOPT_HTTPHEADER][]='Content-type: application/x-binary'; 144 | $request_body = file_get_contents($file); 145 | } 146 | } 147 | 148 | if($transaction!=""){ 149 | if($this->external==true){ 150 | $options[CURLOPT_HTTPHEADER][]='Content-type: application/x-binary'; 151 | } 152 | $request_body = $transaction; 153 | } 154 | 155 | 156 | if($type=="POST"){ 157 | 158 | $options[CURLOPT_POST]=true; 159 | if(!empty($request_body)){ 160 | $options[CURLOPT_POSTFIELDS]=$request_body; 161 | }else{ 162 | $options[CURLOPT_POSTFIELDS]=json_encode($request); 163 | } 164 | 165 | } 166 | 167 | if($type=="DELETE"){ 168 | 169 | $options[CURLOPT_CUSTOMREQUEST]="DELETE"; 170 | if(!empty($request_body)){ 171 | $options[CURLOPT_POSTFIELDS]=$request_body; 172 | }else{ 173 | if(is_array($request)){ 174 | $options[CURLOPT_POSTFIELDS]=json_encode($request); 175 | } 176 | } 177 | 178 | } 179 | 180 | if($this->external==true){ 181 | $url=$this->protocol."://".$this->host."/".$method.$params_url; 182 | }else{ 183 | $url=$this->protocol."://".$this->host.":".$this->port."/".$method.$params_url; 184 | } 185 | $curl = curl_init($url); 186 | 187 | 188 | if(ini_get('open_basedir')) { 189 | unset($options[CURLOPT_FOLLOWLOCATION]); 190 | } 191 | 192 | if($this->protocol == 'https') { 193 | 194 | if ($this->certificate!="") { 195 | $options[CURLOPT_CAINFO] = $this->certificate; 196 | $options[CURLOPT_CAPATH] = DIRNAME($this->certificate); 197 | } else { 198 | $options[CURLOPT_SSL_VERIFYPEER] = false; 199 | } 200 | 201 | } 202 | 203 | 204 | curl_setopt_array($curl, $options); 205 | 206 | // Execute 207 | $this->raw = curl_exec($curl); 208 | 209 | // Get Status 210 | $this->status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 211 | 212 | //Json decode 213 | $this->response = $this->raw; 214 | 215 | // Filter Error 216 | $curl_error = curl_error($curl); 217 | 218 | curl_close($curl); 219 | 220 | if($curl_error!="") { 221 | $this->error = $curl_error; 222 | } 223 | 224 | $return=""; 225 | 226 | if ($this->status != 200) { 227 | 228 | switch ($this->status) { 229 | case 400: 230 | $this->error = 'BAD REQUEST'; 231 | break; 232 | case 401: 233 | $this->error = 'UNAUTHORIZED'; 234 | break; 235 | case 403: 236 | $this->error = 'FORBIDDEN'; 237 | break; 238 | case 404: 239 | $this->error = 'NOT FOUND'; 240 | break; 241 | case 404: 242 | $this->error = 'NOT ALLOWED'; 243 | break; 244 | } 245 | 246 | $return = array( 247 | "code" => $this->status, 248 | "message" => $this->response, 249 | ); 250 | 251 | }else{ 252 | 253 | $return = array( 254 | "code" => $this->status, 255 | "response" => $this->response, 256 | ); 257 | 258 | } 259 | 260 | if($this->debug==1){ 261 | 262 | $return['DEBUG']="ON"; 263 | $return['url']=$url; 264 | $return['options']=$options; 265 | 266 | } 267 | return $return; 268 | 269 | } 270 | } 271 | ?> 272 | -------------------------------------------------------------------------------- /sdk/yii setup/Algorand/b32.php: -------------------------------------------------------------------------------- 1 | 0b00000,'A' => 0b00000,'B' => 0b00001,'C' => 0b00010,'D' => 0b00011,'E' => 0b00100,'F' => 0b00101,'G' => 0b00110,'H' => 0b00111,'I' => 0b01000,'J' => 0b01001,'K' => 0b01010,'L' => 0b01011,'M' => 0b01100,'N' => 0b01101,'O' => 0b01110,'P' => 0b01111,'Q' => 0b10000,'R' => 0b10001,'S' => 0b10010,'T' => 0b10011,'U' => 0b10100,'V' => 0b10101,'W' => 0b10110,'X' => 0b10111,'Y' => 0b11000,'Z' => 0b11001,'2' => 0b11010,'3' => 0b11011,'4' => 0b11100,'5' => 0b11101,'6' => 0b11110,'7' => 0b11111,]; 11 | 12 | public static function encode($string) { 13 | 14 | if ('' === $string) { return ''; } 15 | 16 | $encoded = ''; 17 | 18 | $n = $bitLen = $val = 0; 19 | 20 | $len = strlen($string); 21 | 22 | $string .= str_repeat(chr(0), 4); 23 | 24 | $chars = (array) unpack('C*', $string, 0); 25 | 26 | while ($n < $len || 0 !== $bitLen) { 27 | 28 | if ($bitLen < 5) { $val = $val << 8; $bitLen += 8; $n++; $val += $chars[$n]; } 29 | 30 | $shift = $bitLen - 5; $encoded .= ($n - (int)($bitLen > 8) > $len && 0 == $val) ? '=' : static::ALBT[$val >> $shift]; $val = $val & ((1 << $shift) - 1); $bitLen -= 5; 31 | 32 | } 33 | 34 | return $encoded; 35 | } 36 | 37 | public static function decode($base32String) { 38 | 39 | 40 | $base32String = strtoupper($base32String); $base32String = preg_replace(static::B2HEXP, '', $base32String); 41 | 42 | if ('' === $base32String || null === $base32String) { return ''; } 43 | 44 | $decoded = ''; $len = strlen($base32String)-6; $n = 0; $bitLen = 5; $val = static::MAPP[$base32String[0]]; 45 | 46 | while ($n < $len) { 47 | 48 | if ($bitLen < 8) { $val = $val << 5; $bitLen += 5; $n++; $pentet = $base32String[$n] ?? '='; 49 | 50 | if ('=' === $pentet) { $n = $len; } 51 | 52 | $val += static::MAPP[$pentet]; 53 | 54 | continue; 55 | 56 | } 57 | 58 | $shift = $bitLen - 8; $decoded .= chr($val >> $shift); $val = $val & ((1 << $shift) - 1); $bitLen -= 8; 59 | 60 | } 61 | return $decoded; 62 | } 63 | } 64 | ?> 65 | -------------------------------------------------------------------------------- /sdk/yii setup/Algorand/msgpack.php: -------------------------------------------------------------------------------- 1 | pInt($value); 19 | } 20 | 21 | if (is_string($value)) { 22 | if ('' === $value) { 23 | return $this->fFStr || $this->fDStrBin ? "\xa0" : "\xc4\x00"; 24 | } 25 | if ($this->fFStr) { 26 | return $this->pStr($value); 27 | } 28 | if ($this->fDStrBin && preg_match(self::UTF8_REGEX, $value)) { 29 | return $this->pStr($value); 30 | } 31 | 32 | return $this->pBin($value); 33 | } 34 | 35 | if (is_array($value)) { 36 | 37 | if ([] === $value) { 38 | return $this->fDArrMap || $this->fFArr ? "\x90" : "\x80"; 39 | } 40 | 41 | if ($this->fDArrMap) { 42 | 43 | if (!isset($value[0]) && !array_key_exists(0, $value)) { 44 | return $this->pMap($value); 45 | } 46 | 47 | return array_values($value) === $value 48 | ? $this->pArray($value) 49 | : $this->pMap($value); 50 | } 51 | 52 | return $this->fFArr ? $this->pArray($value) : $this->pMap($value); 53 | } 54 | 55 | if (is_null($value)) { 56 | return "\xc0"; 57 | } 58 | 59 | if (is_bool($value)) { 60 | return $value ? "\xc3" : "\xc2"; 61 | } 62 | 63 | if (is_float($value)) { 64 | return $this->pFloat($value); 65 | } 66 | 67 | if ($this->tmrs) { 68 | foreach ($this->tmrs as $transformer) { 69 | if (!is_null($packed = $transformer->p($this, $value))) { 70 | return $packed; 71 | } 72 | } 73 | } 74 | 75 | if ($value instanceof Ext) { 76 | return $this->pExt($value->type, $value->data); 77 | } 78 | } 79 | 80 | public function pNil(){ 81 | return "\xc0"; 82 | } 83 | 84 | public function pBool($bool){ 85 | return $bool ? "\xc3" : "\xc2"; 86 | } 87 | 88 | public function pInt($int){ 89 | 90 | if ($int >= 0) { 91 | 92 | if ($int <= 0x7f) { 93 | return chr($int); 94 | } 95 | 96 | if ($int <= 0xff) { 97 | return "\xcc".chr($int); 98 | } 99 | 100 | if ($int <= 0xffff) { 101 | return "\xcd".chr($int >> 8).chr($int); 102 | } 103 | 104 | if ($int <= 0xffffffff) { 105 | return pack('CN', 0xce, $int); 106 | } 107 | 108 | return pack('CJ', 0xcf, $int); 109 | } 110 | 111 | if ($int >= -0x20) { 112 | return chr(0xe0 | $int); 113 | } 114 | 115 | if ($int >= -0x80) { 116 | return "\xd0".chr($int); 117 | } 118 | 119 | if ($int >= -0x8000) { 120 | return "\xd1".chr($int >> 8).chr($int); 121 | } 122 | 123 | if ($int >= -0x80000000) { 124 | return pack('CN', 0xd2, $int); 125 | } 126 | 127 | return pack('CJ', 0xd3, $int); 128 | } 129 | 130 | public function pFloat($float){ 131 | return $this->fFF32 132 | ? "\xca".pack('G', $float) 133 | : "\xcb".pack('E', $float); 134 | } 135 | 136 | public function pFloat32($float){ 137 | return "\xca".pack('G', $float); 138 | } 139 | 140 | public function pFloat64($float){ 141 | return "\xcb".pack('E', $float); 142 | } 143 | 144 | public function pStr($str){ 145 | $length = strlen($str); 146 | 147 | if ($length < 32) { 148 | return chr(0xa0 | $length).$str; 149 | } 150 | 151 | if ($length <= 0xff) { 152 | return "\xd9".chr($length).$str; 153 | } 154 | 155 | if ($length <= 0xffff) { 156 | return "\xda".chr($length >> 8).chr($length).$str; 157 | } 158 | 159 | return pack('CN', 0xdb, $length).$str; 160 | 161 | } 162 | 163 | public function pBin($str){ 164 | 165 | $length = strlen($str); 166 | 167 | if ($length <= 0xff) { 168 | return "\xc4".\chr($length).$str; 169 | } 170 | 171 | if ($length <= 0xffff) { 172 | return "\xc5".chr($length >> 8).chr($length).$str; 173 | } 174 | 175 | return pack('CN', 0xc6, $length).$str; 176 | 177 | } 178 | 179 | public function pArray($array){ 180 | 181 | $data = $this->pArrayHeader(count($array)); 182 | 183 | foreach ($array as $val) { 184 | $data .= $this->p($val); 185 | } 186 | 187 | return $data; 188 | 189 | } 190 | 191 | public function pArrayHeader($size){ 192 | 193 | if ($size <= 0xf) { 194 | 195 | return chr(0x90 | $size); 196 | 197 | } 198 | 199 | if ($size <= 0xffff) { 200 | 201 | return "\xdc".chr($size >> 8).chr($size); 202 | 203 | } 204 | 205 | return pack('CN', 0xdd, $size); 206 | 207 | } 208 | 209 | public function pMap($map){ 210 | $data = $this->pMapHeader(count($map)); 211 | 212 | if ($this->fFStr) { 213 | 214 | foreach ($map as $key => $val) { 215 | 216 | $data .= is_string($key) ? $this->pStr($key) : $this->pInt($key); 217 | $data .= $this->p($val); 218 | 219 | } 220 | 221 | return $data; 222 | } 223 | 224 | if ($this->fDStrBin) { 225 | foreach ($map as $key => $val) { 226 | 227 | $data .= is_string($key) 228 | ? (preg_match(self::UTF8_REGEX, $key) ? $this->pStr($key) : $this->pBin($key)) 229 | : $this->pInt($key); 230 | 231 | $data .= $this->p($val); 232 | } 233 | 234 | return $data; 235 | } 236 | 237 | foreach ($map as $key => $val) { 238 | 239 | $data .= is_string($key) ? $this->pBin($key) : $this->pInt($key); 240 | 241 | $data .= $this->p($val); 242 | } 243 | 244 | return $data; 245 | } 246 | 247 | public function pMapHeader($size){ 248 | 249 | if ($size <= 0xf) { 250 | 251 | return chr(0x80 | $size); 252 | 253 | } 254 | 255 | if ($size <= 0xffff) { 256 | 257 | return "\xde".chr($size >> 8).chr($size); 258 | 259 | } 260 | 261 | return pack('CN', 0xdf, $size); 262 | 263 | } 264 | 265 | public function pExt($type, $data){ 266 | 267 | $length = strlen($data); 268 | 269 | switch ($length) { 270 | 271 | case 1: return "\xd4".chr($type).$data; 272 | case 2: return "\xd5".chr($type).$data; 273 | case 4: return "\xd6".chr($type).$data; 274 | case 8: return "\xd7".chr($type).$data; 275 | case 16: return "\xd8".chr($type).$data; 276 | 277 | } 278 | 279 | if ($length <= 0xff) { 280 | 281 | return "\xc7".chr($length).chr($type).$data; 282 | 283 | } 284 | 285 | if ($length <= 0xffff) { 286 | 287 | return pack('CnC', 0xc8, $length, $type).$data; 288 | 289 | } 290 | 291 | return pack('CNC', 0xc9, $length, $type).$data; 292 | } 293 | } 294 | ?> 295 | -------------------------------------------------------------------------------- /sdk/yii setup/Algorand/transactions.php: -------------------------------------------------------------------------------- 1 | pBin(utf8_encode(strval($out['txn']['note']))); } 26 | 27 | if(!empty($out['txn']['gp'])) { $out['txn']['gp']=strval($out['txn']['gp']); } 28 | if(!empty($out['txn']['rekey'])) { $out['txn']['rekey']=b32::decode($out['txn']['rekey']); } 29 | if(!empty($out['txn']['type'])) { $out['txn']['type']=strval($out['txn']['type']); } 30 | if(!empty($out['txn']['rcv'])) { $out['txn']['rcv']=strval($out['txn']['rcv']); } 31 | if(!empty($out['txn']['amt'])) { $out['txn']['amt']=intval($out['txn']['amt']); } 32 | if(!empty($out['txn']['aamt'])) { $out['txn']['aamt']=intval($out['txn']['aamt']); } 33 | if(!empty($out['txn']['close'])) { $out['txn']['close']=strval($out['txn']['close']); } 34 | if(!empty($out['txn']['xaid'])) { $out['txn']['xaid']=intval($out['txn']['xaid']); } 35 | if(!empty($out['txn']['apid'])) { $out['txn']['apid']=intval($out['txn']['apid']); } 36 | if(!empty($out['txn']['faid'])) { $out['txn']['faid']=intval($out['txn']['faid']); } 37 | if(!empty($out['txn']['caid'])) { $out['txn']['caid']=intval($out['txn']['caid']); } 38 | 39 | if(!empty($out['txn']['gh'])) { $out['txn']['gh']=base64_decode($out['txn']['gh']); } 40 | if(!empty($out['txn']['snd'])) { $out['txn']['snd']=b32::decode($out['txn']['snd']); } 41 | if(!empty($out['txn']['rcv'])) { $out['txn']['rcv']=b32::decode($out['txn']['rcv']); } 42 | if(!empty($out['txn']['close'])) { $out['txn']['close']=b32::decode($out['txn']['close']); } 43 | if(!empty($out['txn']['aclose'])) { $out['txn']['aclose']=b32::decode($out['txn']['aclose']); } 44 | if(!empty($out['txn']['selkey'])) { $out['txn']['selkey']=b32::decode($out['txn']['selkey']); } 45 | if(!empty($out['txn']['votekey'])) { $out['txn']['votekey']=b32::decode($out['txn']['votekey']); } 46 | if(!empty($out['txn']['arcv'])) { $out['txn']['arcv']=b32::decode($out['txn']['arcv']); } 47 | if(!empty($out['txn']['asnd'])) { $out['txn']['asnd']=b32::decode($out['txn']['asnd']); } 48 | if(!empty($out['txn']['fadd'])) { $out['txn']['fadd']=b32::decode($out['txn']['fadd']); } 49 | if(!empty($out['txn']['apat'])) { $out['txn']['apat']=b32::decode($out['txn']['apat']); } 50 | if(!empty($out['txn']['apap'])) { $out['txn']['apap']=b32::decode($out['txn']['apap']); } 51 | if(!empty($out['txn']['apsu'])) { $out['txn']['apsu']=b32::decode($out['txn']['apsu']); } 52 | if(!empty($out['txn']['apfa'])) { $out['txn']['apfa']=b32::decode($out['txn']['apfa']); } 53 | if(!empty($out['txn']['apas'])) { $out['txn']['apas']=b32::decode($out['txn']['apas']); } 54 | 55 | if(!empty($out['txn']['apar']['am'])) { $out['txn']['apar']['am']=b32::decode($out['txn']['apar']['am']); } 56 | if(!empty($out['txn']['apar']['c'])) { $out['txn']['apar']['c']=b32::decode($out['txn']['apar']['c']); } 57 | if(!empty($out['txn']['apar']['f'])) { $out['txn']['apar']['f']=b32::decode($out['txn']['apar']['f']); } 58 | if(!empty($out['txn']['apar']['m'])) { $out['txn']['apar']['m']=b32::decode($out['txn']['apar']['m']); } 59 | if(!empty($out['txn']['apar']['r'])) { $out['txn']['apar']['r']=b32::decode($out['txn']['apar']['r']); } 60 | if(!empty($out['txn']['apar']['dc'])) { $out['txn']['apar']['dc']=intval($out['txn']['apar']['dc']); } 61 | if(!empty($out['txn']['apar']['t'])) { $out['txn']['apar']['t']=intval($out['txn']['apar']['t']); } 62 | 63 | if($signature!=""){ 64 | $out=array( 65 | "sig" => $signature, 66 | "txn" => $out['txn'], 67 | ); 68 | $out=$msgpack->p($out); 69 | }else{ 70 | $out=$msgpack->p($out['txn']); 71 | } 72 | 73 | $out=bin2hex($out); 74 | $out=hex2bin($out); 75 | 76 | if($opt_msgpack==false){ 77 | $out=base64_encode($out); 78 | } 79 | return $out; 80 | } 81 | 82 | public function pk_encode($array){ 83 | $out=$array; 84 | $out=b32::decode($out); 85 | $out=base64_encode($out); 86 | return $out; 87 | } 88 | 89 | public function groupid($transactions){ 90 | 91 | $msgpack=new msgpack; 92 | $txn=""; 93 | $total=count($transactions); 94 | $txids=array(); 95 | for($x=0; $x<$total; $x++){ 96 | $raw_txn=$this->encode($transactions[$x],true); 97 | $raw_txn=hash('sha512/256',"TX".$raw_txn,true); 98 | $txids[$x]=$raw_txn; 99 | } 100 | 101 | $group_list=array( 102 | 'txlist' => $txids, 103 | ); 104 | 105 | $encoded=$msgpack->p($group_list); 106 | $gid = hash('sha512/256',"TG".$encoded,true); 107 | 108 | return $gid; 109 | } 110 | 111 | } 112 | ?> 113 | -------------------------------------------------------------------------------- /sdk/yii setup/controllers/SiteController.php: -------------------------------------------------------------------------------- 1 | [ 27 | 'class' => AccessControl::className(), 28 | 'only' => ['logout'], 29 | 'rules' => [ 30 | [ 31 | 'actions' => ['logout'], 32 | 'allow' => true, 33 | 'roles' => ['@'], 34 | ], 35 | ], 36 | ], 37 | 'verbs' => [ 38 | 'class' => VerbFilter::className(), 39 | 'actions' => [ 40 | 'logout' => ['post'], 41 | ], 42 | ], 43 | ]; 44 | } 45 | 46 | /** 47 | * {@inheritdoc} 48 | */ 49 | public function actions() 50 | { 51 | return [ 52 | 'error' => [ 53 | 'class' => 'yii\web\ErrorAction', 54 | ], 55 | 'captcha' => [ 56 | 'class' => 'yii\captcha\CaptchaAction', 57 | 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, 58 | ], 59 | ]; 60 | } 61 | 62 | /** 63 | * Displays homepage. 64 | * 65 | * @return string 66 | */ 67 | public function actionIndex() 68 | { 69 | echo "Access: ?r=site/algod, ?r=site/kmd or ?r=site/indexer"; 70 | } 71 | 72 | 73 | /** 74 | * Displays Algod page. 75 | * 76 | * @return string 77 | */ 78 | public function actionAlgod() 79 | { 80 | 81 | $algorand = new Algorand("algod","4820e6e45f339e0026eaa2b74c2aa7d8735cbcb2db0cf0444fb492892e1c09b7","localhost",53898); 82 | $algorand->debug(1); 83 | 84 | #Gets the current node status. 85 | //$return=$algorand->get("v2","status"); 86 | 87 | $return=$algorand->get("v2","status"); 88 | 89 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 90 | 91 | #Full response with debug (json response) 92 | if(!empty($return)){ 93 | print_r($return); 94 | } 95 | #Only response array 96 | if(!empty($return['response'])){ 97 | print_r(json_decode($return['response'])); 98 | } 99 | #Only erros messages array 100 | if(!empty($return['message'])){ 101 | print_r(json_decode($return['message'])); 102 | } 103 | } 104 | 105 | /** 106 | * Displays Kmd page. 107 | * 108 | * @return string 109 | */ 110 | public function actionKmd() 111 | { 112 | 113 | $algorand_kmd = new Algorand("kmd","dcb406527f3ded8464dbd56e6ea001b9b17882cfcf8194c17069bb22816307ad","localhost",7833); 114 | $algorand_kmd->debug(1); 115 | 116 | #Get Versions 117 | //$return=$algorand_kmd->get("versions"); 118 | 119 | 120 | #See all Algorand SDK Functions at: https://github.com/ffsolutions/php-algorand-sdk 121 | 122 | $return=$algorand_kmd->get("v1","wallets"); 123 | 124 | #Full response with debug (json response) 125 | if(!empty($return)){ 126 | print_r($return); 127 | } 128 | #Only response array 129 | if(!empty($return['response'])){ 130 | print_r(json_decode($return['response'])); 131 | } 132 | #Only erros messages array 133 | if(!empty($return['message'])){ 134 | print_r(json_decode($return['message'])); 135 | } 136 | } 137 | 138 | /** 139 | * Displays Indexer page. 140 | * 141 | * @return string 142 | */ 143 | public function actionIndexer() 144 | { 145 | 146 | $algorand_indexer = new Algorand("indexer","{indexer-token}","localhost",8980); 147 | $algorand_indexer->debug(1); 148 | 149 | #Get health, Returns 200 if healthy. 150 | $return=$algorand_indexer->get("health"); 151 | 152 | #Full response with debug (json response) 153 | if(!empty($return)){ 154 | print_r($return); 155 | } 156 | #Only response array 157 | if(!empty($return['response'])){ 158 | print_r(json_decode($return['response'])); 159 | } 160 | #Only erros messages array 161 | if(!empty($return['message'])){ 162 | print_r(json_decode($return['message'])); 163 | } 164 | } 165 | 166 | } 167 | --------------------------------------------------------------------------------