// NewAccountResource creates a new AccountResource from a provided db.CoreAccountRecord and // a provided db.AccountRecord. // // panics if the two records are not for the same logical account. func NewAccountResource(ac db.AccountRecord) AccountResource { address := ac.Address self := fmt.Sprintf("/accounts/%s", address) balances := make([]BalanceResource, len(ac.Trustlines)+1) for i, tl := range ac.Trustlines { balances[i] = BalanceResource{ Type: "alphanum", Balance: tl.Balance, Code: tl.Alphanumcurrency, Issuer: tl.Issuer, Limit: tl.Tlimit, } } // add native balance balances[len(ac.Trustlines)] = BalanceResource{Type: "native", Balance: ac.Balance} return AccountResource{ Links: halgo.Links{}. Self(self). Link("transactions", "%s/transactions/%s", self, hal.StandardPagingOptions). Link("operations", "%s/operations/%s", self, hal.StandardPagingOptions). Link("effects", "%s/effects/%s", self, hal.StandardPagingOptions). Link("offers", "%s/offers/%s", self, hal.StandardPagingOptions), ID: address, PagingToken: ac.PagingToken(), Address: address, Sequence: ac.Seqnum, Balances: balances, } }
// NewAccountResource creates a new AccountResource from a provided db.CoreAccountRecord and // a provided db.AccountRecord. // // panics if the two records are not for the same logical account. func NewAccountResource(ac db.AccountRecord) AccountResource { address := ac.Address self := fmt.Sprintf("/accounts/%s", address) balances := make([]BalanceResource, len(ac.Trustlines)+1) for i, tl := range ac.Trustlines { balance := BalanceResource{ Balance: tl.Balance, Limit: tl.Tlimit, Issuer: tl.Issuer, Code: tl.Assetcode, } switch tl.Assettype { case int32(xdr.AssetTypeAssetTypeCreditAlphanum4): balance.Type = "credit_alphanum4" case int32(xdr.AssetTypeAssetTypeCreditAlphanum12): balance.Type = "credit_alphanum12" } balances[i] = balance } // add native balance balances[len(ac.Trustlines)] = BalanceResource{Type: "native", Balance: ac.Balance} return AccountResource{ Links: halgo.Links{}. Self(self). Link("transactions", "%s/transactions/%s", self, hal.StandardPagingOptions). Link("operations", "%s/operations/%s", self, hal.StandardPagingOptions). Link("effects", "%s/effects/%s", self, hal.StandardPagingOptions). Link("offers", "%s/offers/%s", self, hal.StandardPagingOptions), ID: address, PagingToken: ac.PagingToken(), Address: address, Sequence: ac.Seqnum, Balances: balances, } }