Commit 560a2364b7318ac4511c7e50913ac0bcc9bbe7b6
move actor id generation to its own method
Norton Wang committed on 4/16/2018, 9:02:33 PMParent: d0a5ea25b9d19aad6f2be59441be57da023c9c70
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -76,11 +76,9 @@ | ||
76 | 76 | * @param {Object} id - the id for the actor |
77 | 77 | */ |
78 | 78 | createActor (type, code, id = {nonce: this.nonce++, parent: null}) { |
79 | 79 | const Container = this._containerTypes[type] |
80 | - const encoded = encodedID(id) | |
81 | - id = this._hash(encoded) | |
82 | - id = new ID(id) | |
80 | + id = this.generateId(id) | |
83 | 81 | const module = Container.onCreation(code, id) |
84 | 82 | const metaData = [type, 0] |
85 | 83 | |
86 | 84 | // save the container in the state |
@@ -100,8 +98,14 @@ | ||
100 | 98 | module |
101 | 99 | } |
102 | 100 | } |
103 | 101 | |
102 | + generateId (id) { | |
103 | + const encoded = encodedID(id) | |
104 | + const hashed = this._hash(encoded) | |
105 | + return new ID(hashed) | |
106 | + } | |
107 | + | |
104 | 108 | _hash (buf) { |
105 | 109 | const hash = crypto.createHash('sha256') |
106 | 110 | hash.update(buf) |
107 | 111 | return hash.digest().slice(0, 20) |
Built with git-ssb-web