diff options
Diffstat (limited to 'ledger/apply/apply.go')
-rw-r--r-- | ledger/apply/apply.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/ledger/apply/apply.go b/ledger/apply/apply.go index 988ae8cb9..f6a91ed8e 100644 --- a/ledger/apply/apply.go +++ b/ledger/apply/apply.go @@ -64,3 +64,26 @@ type Balances interface { // to a ConsensusParams. This returns those parameters. ConsensusParams() config.ConsensusParams } + +// Rekey updates tx.Sender's AuthAddr to tx.RekeyTo, if provided +func Rekey(balances Balances, tx *transactions.Transaction) error { + if (tx.RekeyTo != basics.Address{}) { + acct, err := balances.Get(tx.Sender, false) + if err != nil { + return err + } + // Special case: rekeying to the account's actual address just sets acct.AuthAddr to 0 + // This saves 32 bytes in your balance record if you want to go back to using your original key + if tx.RekeyTo == tx.Sender { + acct.AuthAddr = basics.Address{} + } else { + acct.AuthAddr = tx.RekeyTo + } + + err = balances.Put(tx.Sender, acct) + if err != nil { + return err + } + } + return nil +} |