Generalize erc20transfers to tokentransfers in api
parent
81e105dd4f
commit
7da714bec4
12
api/types.go
12
api/types.go
|
@ -115,15 +115,16 @@ type Erc20Token struct {
|
|||
ContractIndex string `json:"-"`
|
||||
}
|
||||
|
||||
// Erc20Transfer contains info about ERC20 transfer done in a transaction
|
||||
type Erc20Transfer struct {
|
||||
// TokenTransfer contains info about a token transfer done in a transaction
|
||||
type TokenTransfer struct {
|
||||
Type string `json:"type"`
|
||||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
Contract string `json:"contract"`
|
||||
Token string `json:"token"`
|
||||
Name string `json:"name"`
|
||||
Symbol string `json:"symbol"`
|
||||
Decimals int `json:"decimals"`
|
||||
Tokens *Amount `json:"tokens"`
|
||||
Value *Amount `json:"value"`
|
||||
}
|
||||
|
||||
// EthereumSpecific contains ethereum specific transaction data
|
||||
|
@ -154,7 +155,7 @@ type Tx struct {
|
|||
Hex string `json:"hex,omitempty"`
|
||||
CoinSpecificData interface{} `json:"-"`
|
||||
CoinSpecificJSON json.RawMessage `json:"-"`
|
||||
Erc20Transfers []Erc20Transfer `json:"erc20transfers,omitempty"`
|
||||
TokenTransfers []TokenTransfer `json:"tokentransfers,omitempty"`
|
||||
EthereumSpecific *EthereumSpecific `json:"ethereumspecific,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -174,6 +175,7 @@ const (
|
|||
AddressFilterVoutOutputs = -3
|
||||
)
|
||||
|
||||
// AddressFilter is used to filter data returned from GetAddress api method
|
||||
type AddressFilter struct {
|
||||
Vout int
|
||||
Contract string
|
||||
|
|
|
@ -112,7 +112,7 @@ func (w *Worker) GetTransaction(txid string, spendingTxs bool, specificJSON bool
|
|||
func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32, spendingTxs bool, specificJSON bool) (*Tx, error) {
|
||||
var err error
|
||||
var ta *db.TxAddresses
|
||||
var erc20t []Erc20Transfer
|
||||
var tokens []TokenTransfer
|
||||
var ethSpecific *EthereumSpecific
|
||||
var blockhash string
|
||||
if bchainTx.Confirmations > 0 {
|
||||
|
@ -222,7 +222,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
|
|||
if err != nil {
|
||||
glog.Errorf("GetErc20FromTx error %v, %v", err, bchainTx)
|
||||
}
|
||||
erc20t = make([]Erc20Transfer, len(ets))
|
||||
tokens = make([]TokenTransfer, len(ets))
|
||||
for i := range ets {
|
||||
e := &ets[i]
|
||||
cd, err := w.chainParser.GetAddrDescFromAddress(e.Contract)
|
||||
|
@ -237,12 +237,13 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
|
|||
if erc20c == nil {
|
||||
erc20c = &bchain.Erc20Contract{Name: e.Contract}
|
||||
}
|
||||
erc20t[i] = Erc20Transfer{
|
||||
Contract: e.Contract,
|
||||
tokens[i] = TokenTransfer{
|
||||
Type: "ERC20",
|
||||
Token: e.Contract,
|
||||
From: e.From,
|
||||
To: e.To,
|
||||
Decimals: erc20c.Decimals,
|
||||
Tokens: (*Amount)(&e.Tokens),
|
||||
Value: (*Amount)(&e.Tokens),
|
||||
Name: erc20c.Name,
|
||||
Symbol: erc20c.Symbol,
|
||||
}
|
||||
|
@ -289,7 +290,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
|
|||
Vout: vouts,
|
||||
CoinSpecificData: bchainTx.CoinSpecificData,
|
||||
CoinSpecificJSON: sj,
|
||||
Erc20Transfers: erc20t,
|
||||
TokenTransfers: tokens,
|
||||
EthereumSpecific: ethSpecific,
|
||||
}
|
||||
return r, nil
|
||||
|
|
|
@ -69,11 +69,11 @@
|
|||
{{formatAmount $tx.ValueOutSat}} {{$cs}}
|
||||
</div>
|
||||
</div>
|
||||
{{- if $tx.Erc20Transfers -}}
|
||||
{{- if $tx.TokenTransfers -}}
|
||||
<div class="row line-top" style="padding: 15px 0 6px 15px;font-weight: bold;">
|
||||
ERC20 Token Transfers
|
||||
</div>
|
||||
{{- range $erc20 := $tx.Erc20Transfers -}}
|
||||
{{- range $erc20 := $tx.TokenTransfers -}}
|
||||
<div class="row" style="padding: 2px 15px;">
|
||||
<div class="col-md-4">
|
||||
<div class="row">
|
||||
|
@ -106,7 +106,7 @@
|
|||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3 text-right" style="padding: .4rem 0;">{{formatAmountWithDecimals $erc20.Tokens $erc20.Decimals}} {{$erc20.Symbol}}</div>
|
||||
<div class="col-md-3 text-right" style="padding: .4rem 0;">{{formatAmountWithDecimals $erc20.Value $erc20.Decimals}} {{$erc20.Symbol}}</div>
|
||||
</div>
|
||||
{{- end -}}
|
||||
<div class="row" style="padding: 6px 15px;"></div>
|
||||
|
|
Loading…
Reference in New Issue