-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
107 changed files
with
7,579 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.github/ @algorand/dev | ||
.circleci/ @algorand/dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/algorand/go-algorand-sdk/v2/client/v2/algod" | ||
"github.com/algorand/go-algorand-sdk/v2/crypto" | ||
"github.com/algorand/go-algorand-sdk/v2/mnemonic" | ||
"github.com/algorand/go-algorand-sdk/v2/transaction" | ||
) | ||
|
||
func main() { | ||
// example: ACCOUNT_GENERATE | ||
account := crypto.GenerateAccount() | ||
mn, err := mnemonic.FromPrivateKey(account.PrivateKey) | ||
|
||
if err != nil { | ||
log.Fatalf("failed to generate account: %s", err) | ||
} | ||
|
||
log.Printf("Address: %s\n", account.Address) | ||
log.Printf("Mnemonic: %s\n", mn) | ||
// example: ACCOUNT_GENERATE | ||
|
||
// example: ACCOUNT_RECOVER_MNEMONIC | ||
k, err := mnemonic.ToPrivateKey(mn) | ||
if err != nil { | ||
log.Fatalf("failed to parse mnemonic: %s", err) | ||
} | ||
|
||
recovered, err := crypto.AccountFromPrivateKey(k) | ||
if err != nil { | ||
log.Fatalf("failed to recover account from key: %s", err) | ||
} | ||
|
||
log.Printf("%+v", recovered) | ||
// example: ACCOUNT_RECOVER_MNEMONIC | ||
accts, err := getSandboxAccounts() | ||
if err != nil { | ||
log.Fatalf("failed to get sandbox accounts: %s", err) | ||
} | ||
rekeyAccount(getAlgodClient(), accts[0], accts[1]) | ||
} | ||
|
||
func rekeyAccount(algodClient *algod.Client, acct crypto.Account, rekeyTarget crypto.Account) { | ||
// example: ACCOUNT_REKEY | ||
sp, err := algodClient.SuggestedParams().Do(context.Background()) | ||
if err != nil { | ||
log.Fatalf("failed to get suggested params: %s", err) | ||
} | ||
|
||
addr := acct.Address.String() | ||
// here we create a payment transaction but rekey is valid | ||
// on any transaction type | ||
rktxn, err := transaction.MakePaymentTxn(addr, addr, 0, nil, "", sp) | ||
if err != nil { | ||
log.Fatalf("failed to creating transaction: %s\n", err) | ||
} | ||
// Set the rekey parameter | ||
rktxn.RekeyTo = rekeyTarget.Address | ||
|
||
_, stxn, err := crypto.SignTransaction(acct.PrivateKey, rktxn) | ||
if err != nil { | ||
fmt.Printf("Failed to sign transaction: %s\n", err) | ||
} | ||
|
||
txID, err := algodClient.SendRawTransaction(stxn).Do(context.Background()) | ||
if err != nil { | ||
fmt.Printf("failed to send transaction: %s\n", err) | ||
return | ||
} | ||
|
||
result, err := transaction.WaitForConfirmation(algodClient, txID, 4, context.Background()) | ||
if err != nil { | ||
fmt.Printf("Error waiting for confirmation on txID: %s\n", txID) | ||
return | ||
} | ||
|
||
fmt.Printf("Confirmed Transaction: %s in Round %d\n", txID, result.ConfirmedRound) | ||
// example: ACCOUNT_REKEY | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#pragma version 4 | ||
// Handle each possible OnCompletion type. We don't have to worry about | ||
// handling ClearState, because the ClearStateProgram will execute in that | ||
// case, not the ApprovalProgram. | ||
txn ApplicationID | ||
int 0 | ||
== | ||
bnz handle_approve | ||
|
||
txn OnCompletion | ||
int NoOp | ||
== | ||
bnz handle_noop | ||
|
||
txn OnCompletion | ||
int OptIn | ||
== | ||
bnz handle_approve | ||
|
||
txn OnCompletion | ||
int CloseOut | ||
== | ||
bnz handle_closeout | ||
|
||
txn OnCompletion | ||
int UpdateApplication | ||
== | ||
bnz handle_updateapp | ||
|
||
txn OnCompletion | ||
int DeleteApplication | ||
== | ||
bnz handle_deleteapp | ||
|
||
// Unexpected OnCompletion value. Should be unreachable. | ||
err | ||
|
||
handle_noop: | ||
// Handle NoOp | ||
|
||
// read global state | ||
byte "counter" | ||
dup | ||
app_global_get | ||
|
||
// increment the value | ||
int 1 | ||
+ | ||
|
||
// store to scratch space | ||
dup | ||
store 0 | ||
|
||
// update global state | ||
app_global_put | ||
|
||
// read local state for sender | ||
int 0 | ||
byte "counter" | ||
app_local_get | ||
|
||
// increment the value | ||
int 1 | ||
+ | ||
store 1 | ||
|
||
// update local state for sender | ||
int 0 | ||
byte "counter" | ||
load 1 | ||
app_local_put | ||
|
||
// load return value as approval | ||
load 0 | ||
return | ||
|
||
|
||
handle_closeout: | ||
// Handle CloseOut | ||
//approval | ||
int 1 | ||
return | ||
|
||
handle_deleteapp: | ||
// Check for creator | ||
global CreatorAddress | ||
txn Sender | ||
== | ||
return | ||
|
||
handle_updateapp: | ||
// Check for creator | ||
global CreatorAddress | ||
txn Sender | ||
== | ||
return | ||
|
||
handle_approve: | ||
int 1 | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#pragma version 4 | ||
// Handle each possible OnCompletion type. We don't have to worry about | ||
// handling ClearState, because the ClearStateProgram will execute in that | ||
// case, not the ApprovalProgram. | ||
|
||
txn ApplicationID | ||
int 0 | ||
== | ||
bnz handle_approve | ||
|
||
txn OnCompletion | ||
int NoOp | ||
== | ||
bnz handle_noop | ||
|
||
txn OnCompletion | ||
int OptIn | ||
== | ||
bnz handle_approve | ||
|
||
txn OnCompletion | ||
int CloseOut | ||
== | ||
bnz handle_closeout | ||
|
||
txn OnCompletion | ||
int UpdateApplication | ||
== | ||
bnz handle_updateapp | ||
|
||
txn OnCompletion | ||
int DeleteApplication | ||
== | ||
bnz handle_deleteapp | ||
|
||
// Unexpected OnCompletion value. Should be unreachable. | ||
err | ||
|
||
handle_noop: | ||
// Handle NoOp | ||
|
||
// read global state | ||
byte "counter" | ||
dup | ||
app_global_get | ||
|
||
// increment the value | ||
int 1 | ||
+ | ||
|
||
// store to scratch space | ||
dup | ||
store 0 | ||
|
||
// update global state | ||
app_global_put | ||
|
||
// read local state for sender | ||
int 0 | ||
byte "counter" | ||
app_local_get | ||
|
||
// increment the value | ||
int 1 | ||
+ | ||
store 1 | ||
|
||
// update local state for sender | ||
// update "counter" | ||
int 0 | ||
byte "counter" | ||
load 1 | ||
app_local_put | ||
|
||
// update "timestamp" | ||
int 0 | ||
byte "timestamp" | ||
txn ApplicationArgs 0 | ||
app_local_put | ||
|
||
// load return value as approval | ||
load 0 | ||
return | ||
|
||
handle_closeout: | ||
// Handle CloseOut | ||
//approval | ||
int 1 | ||
return | ||
|
||
handle_deleteapp: | ||
// Check for creator | ||
global CreatorAddress | ||
txn Sender | ||
== | ||
return | ||
|
||
handle_updateapp: | ||
// Check for creator | ||
global CreatorAddress | ||
txn Sender | ||
== | ||
return | ||
|
||
handle_approve: | ||
int 1 | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma version 4 | ||
int 1 | ||
return |
Oops, something went wrong.