return account.Alias
}
+// CreateAddressForChange generate an address for the UTXO change
+func (m *Manager) CreateCtrlProgramForChange(ctx context.Context, accountID string) (cp *CtrlProgram, err error) {
+ return m.CreateAddress(ctx, accountID, true)
+}
+
// CreateAddress generate an address for the select account
func (m *Manager) CreateAddress(ctx context.Context, accountID string, change bool) (cp *CtrlProgram, err error) {
account, err := m.findByID(ctx, accountID)
Address string
KeyIndex uint64
ControlProgram []byte
- Change bool
+ Change bool // Mark whether this control program is for UTXO change
}
func (m *Manager) insertAccountControlProgram(ctx context.Context, progs ...*CtrlProgram) error {
}
if res.Change > 0 {
- acp, err := a.accounts.CreateAddress(ctx, a.AccountID, true)
+ acp, err := a.accounts.CreateCtrlProgramForChange(ctx, a.AccountID)
if err != nil {
return errors.Wrap(err, "creating control program")
}
Address string
ControlProgramIndex uint64
ValidHeight uint64
+ Change bool
}
func (u *UTXO) source() source {
AccountAlias string `json:"account_alias"`
AccountID string `json:"account_id"`
Address string `json:"address"`
+ Change bool `json:"change"`
}
func (a *API) listAddresses(ctx context.Context, ins struct {
}
accountAlias := a.wallet.AccountMgr.GetAliasByID(cp.AccountID)
- addresses = append(addresses, &addressResp{AccountAlias: accountAlias, AccountID: cp.AccountID, Address: cp.Address})
+ addresses = append(addresses, &addressResp{
+ AccountAlias: accountAlias,
+ AccountID: cp.AccountID,
+ Address: cp.Address,
+ Change: cp.Change,
+ })
}
return NewSuccessResponse(addresses)
}
var UTXOs []query.AnnotatedUTXO
for _, utxo := range accountUTXOs {
- UTXOs = append(UTXOs, query.AnnotatedUTXO{
+ UTXOs = append([]query.AnnotatedUTXO{{
AccountID: utxo.AccountID,
OutputID: utxo.OutputID.String(),
SourceID: utxo.SourceID.String(),
ValidHeight: utxo.ValidHeight,
Alias: a.wallet.AccountMgr.GetAliasByID(utxo.AccountID),
AssetAlias: a.wallet.AssetReg.GetAliasByID(utxo.AssetID.String()),
- })
+ Change: utxo.Change,
+ }}, UTXOs...)
}
return NewSuccessResponse(UTXOs)
SourceID string `json:"source_id"`
SourcePos uint64 `json:"source_pos"`
ValidHeight uint64 `json:"valid_height"`
+ Change bool `json:"change"`
}
)
type rawOutput struct {
- OutputID bc.Hash
+ OutputID bc.Hash
bc.AssetAmount
ControlProgram []byte
txHash bc.Hash
AccountID: out.AccountID,
Address: out.Address,
ValidHeight: out.ValidHeight,
+ Change: out.change,
}
data, err := json.Marshal(u)