func (a *addressbook) BeneficiaryPeer(beneficiary common.Address) (peer swarm.Address, known bool, err error) {
	err = a.store.Get(beneficiaryPeerKey(beneficiary), &peer)
	if err != nil {
		if err != storage.ErrNotFound {
			return swarm.Address{}, false, err
		}
		return swarm.Address{}, false, nil
	}
	return peer, true, nil
}
BeneficiaryPeer returns the peer for a beneficiary.
package swap
import (
	"errors"
	"fmt"
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethsana/sana/pkg/storage"
	"github.com/ethsana/sana/pkg/swarm"
)
var (
	peerPrefix            = "swap_chequebook_peer_"
	peerChequebookPrefix  = "swap_peer_chequebook_"
	beneficiaryPeerPrefix = "swap_beneficiary_peer_"
	peerBeneficiaryPrefix = "swap_peer_beneficiary_"
	deductedForPeerPrefix = "swap_deducted_for_peer_"
	deductedByPeerPrefix  = "swap_deducted_by_peer_"
)
type Addressbook interface {
	Beneficiary(peer swarm.Address) (beneficiary common.Address, known bool, err error)
	Chequebook(peer swarm.Address) (chequebookAddress common.Address, known bool, err error)
	BeneficiaryPeer(beneficiary common.Address) (peer swarm.Address, known bool, err error)
	ChequebookPeer(chequebook common.Address) (peer swarm.Address, known bool, err error)
	PutBeneficiary(peer swarm.Address, beneficiary common.Address) error
	PutChequebook(peer swarm.Address, chequebook common.Address) error
	AddDeductionFor(peer swarm.Address) error
	AddDeductionBy(peer swarm.Address) error
	GetDeductionFor(peer swarm.Address) (bool, error)
	GetDeductionBy(peer swarm.Address) (bool, error)
	MigratePeer(oldPeer, newPeer swarm.Address) error
}
type addressbook struct {
	store storage.StateStorer
}
func NewAddressbook(store storage.StateStorer) Addressbook {
	return &addressbook{
		store: store,
	}
}
func (a *addressbook) MigratePeer(oldPeer, newPeer swarm.Address) error {
	ba, known, err := a.Beneficiary(oldPeer)
	if err != nil {
		return err
	}
	if !known {
		return errors.New("old beneficiary not known")
	}
	cb, known, err := a.Chequebook(oldPeer)
	if err != nil {
		return err
	}
	if err := a.PutBeneficiary(newPeer, ba); err != nil {
		return err
	}
	if err := a.store.Delete(peerBeneficiaryKey(oldPeer)); err != nil {
		return err
	}
	if known {
		if err := a.PutChequebook(newPeer, cb); err != nil {
			return err
		}
		if err := a.store.Delete(peerKey(oldPeer)); err != nil {
			return err
		}
	}
	return nil
}
func (a *addressbook) Beneficiary(peer swarm.Address) (beneficiary common.Address, known bool, err error) {
	err = a.store.Get(peerBeneficiaryKey(peer), &beneficiary)
	if err != nil {
		if err != storage.ErrNotFound {
			return common.Address{}, false, err
		}
		return common.Address{}, false, nil
	}
	return beneficiary, true, nil
}