Charge per byte of object get

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
Jakub Sztandera 2019-08-30 18:05:54 +02:00
parent 1bfa0483fa
commit e6b83d9428

View File

@ -30,6 +30,7 @@ const (
gasInvoke = 5
gasGetObj = 10
gasGetPerByte = 1
gasPutObj = 20
gasPutPerByte = 2
gasCommit = 50
@ -230,7 +231,15 @@ func (bs *gasChargingBlocks) GetBlock(ctx context.Context, c cid.Cid) (block.Blo
if err := bs.chargeGas(gasGetObj); err != nil {
return nil, err
}
return bs.under.GetBlock(ctx, c)
blk, err := bs.under.GetBlock(ctx, c)
if err != nil {
return nil, err
}
if err := bs.chargeGas(uint64(len(blk.RawData())) * gasGetPerByte); err != nil {
return nil, err
}
return blk, nil
}
func (bs *gasChargingBlocks) AddBlock(blk block.Block) error {