Refactor contract interaction in its own module #42
@@ -3,7 +3,6 @@ import RSVP from 'rsvp';
|
||||
|
||||
import Kredits from '../kredits';
|
||||
import ContributorSerializer from '../serializers/contributor';
|
||||
import { toBytes32 } from '../utils/multihash';
|
||||
|
||||
import Base from './base';
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import ethers from 'npm:ethers';
|
||||
|
|
||||
import RSVP from 'rsvp';
|
||||
import multihashes from 'npm:multihashes';
|
||||
|
||||
import Kredits from '../kredits';
|
||||
import ContributionSerializer from '../serializers/contribution';
|
||||
import { toBytes32 } from '../utils/multihash';
|
||||
|
||||
import Base from './base';
|
||||
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
import bs58 from 'npm:bs58';
|
||||
import NpmBuffer from 'npm:buffer';
|
||||
const Buffer = NpmBuffer.Buffer;
|
||||
|
||||
function fromBytes32({ digest, hashFunction, hashSize }) {
|
||||
if (hashSize === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hashBytes = Buffer.from(digest.slice(2), 'hex');
|
||||
const multiHashBytes = new (hashBytes.constructor)(2 + hashBytes.length);
|
||||
|
||||
multiHashBytes[0] = hashFunction;
|
||||
multiHashBytes[1] = hashSize;
|
||||
multiHashBytes.set(hashBytes, 2);
|
||||
|
||||
return bs58.encode(multiHashBytes);
|
||||
}
|
||||
|
||||
function toBytes32(string) {
|
||||
const decoded = bs58.decode(string);
|
||||
|
||||
return {
|
||||
digest: `0x${decoded.slice(2).toString('hex')}`,
|
||||
hashFunction: decoded[0],
|
||||
hashSize: decoded[1],
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
fromBytes32,
|
||||
toBytes32
|
||||
};
|
||||
Reference in New Issue
Block a user
We can use
this.functionsWe can use
this.functionsWe can use
this.functions